Browse Source

赵老师修改部分(后续我修改完成)

master
zwsd 3 years ago
parent
commit
2e57ee3258
  1. 0
      doc/README.md
  2. 119
      main/main.c
  3. 3
      main/port.h

0
doc/README.md

119
main/main.c

@ -17,35 +17,29 @@
#define MAIN_LOG_TAG "MAIN"
#define SUPPORT_KEY_INT 0
#define SUPPORT_ELECTRIC_RELAY 0
/**
* @brief
*/
#define SUPPORT_KEY_INT 1 //是否支持按键
#define KEY_INT1 27
#define KEY_INT2 14
// #define GPIO_KEY_INPUT_PIN_SEL ((1ULL << KEY_INT1) | (1ULL << KEY_INT2))
#define SUPPORT_ELECTRIC_RELAY 1
#define SUPPORT_DEBUG_LIGHT 1
#define SUPPORT_TEMPER_LINE 0
#define SUPPORT_FAN 0
#define SUPPORT_TEMPER_LINE 1
#define SUPPORT_FAN 1
#define ble_uart_tx_size 128
#define ble_uart_rx_size 128
#if SUPPORT_KEY_INT
#define KEY_INT1 27
#define KEY_INT2 14
#define GPIO_KEY_INPUT_PIN_SEL ((1ULL << KEY_INT1) | (1ULL << KEY_INT2))
#endif
#if SUPPORT_ELECTRIC_RELAY
#define ELECTRIC_RELAY1 25
#define ELECTRIC_RELAY2 26
#define ELECTRIC_RELAY1 25 //
#define ELECTRIC_RELAY2 26 //
#define GPIO_ELECTRIC_RELAY_OUTPUT_PIN_SEL ((1ULL << ELECTRIC_RELAY1) | (1ULL << ELECTRIC_RELAY2))
#endif
#if SUPPORT_DEBUG_LIGHT
#define DEBUG_LIGHT 12
#define GPIO_DEBUG_LIGHT_OUTPUT_PIN_SEL ((1ULL << DEBUG_LIGHT))
#endif
#if SUPPORT_TEMPER_LINE
#define TEMPER_LINE 18
#define GPIO_TEMPER_LINE_INPUT_PIN_SEL ((1ULL << TEMPER_LINE))
@ -58,6 +52,11 @@
#endif
typedef struct {
int index;
const char *order;
} RxContext_t;
static uint8_t bluetooth_tx_buffer[ble_uart_tx_size] = {0};
static uint8_t bluetooth_rx_buffer[ble_uart_rx_size] = {0};
@ -86,16 +85,26 @@ void order_receipt_setPosition(int index, uint8_t setPosition_code) {
bleuart_notify_send(buffer, strlen((char *)buffer));
}
}
void order_receipt_getStatus(int index) {
ESP_LOGI(MAIN_LOG_TAG, "Command getStatus execution complete!");
//
// void order_receipt_getStatus(int index) {
// ESP_LOGI(MAIN_LOG_TAG, "Command getStatus execution complete!");
// uint8_t buffer[256] = {0};
// double motor_position = motor_get_position_degree();
// sprintf((char *)buffer,
// "{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"running\", \"deviceException\": 0, \"deviceExceptionInfo\": "
// ", \"position\":%lf }",
// index, motor_position);
// bleuart_notify_send(buffer, strlen((char *)buffer));
// }
void construct_get_status_packet_and_report(int index, double motor_position) {
uint8_t buffer[256] = {0};
double motor_position = motor_get_position_degree();
sprintf((char *)buffer,
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"running\", \"deviceException\": 0, \"deviceExceptionInfo\": "
", \"position\":%lf }",
index, motor_position);
snprintf((char *)buffer, 256,
"{ \"order\": \"receipt\", \"index\": %d, \"deviceState\": \"running\", \"deviceException\": 0, \"deviceExceptionInfo\": "
", \"position\":%lf }",
index, motor_position);
ESP_LOGI(MAIN_LOG_TAG, "report %s", buffer);
bleuart_notify_send(buffer, strlen((char *)buffer));
}
@ -107,7 +116,7 @@ void order_receipt_setMotorCurrentSize(int index) {
bleuart_notify_send(buffer, strlen((char *)buffer));
}
void process_setPosition(cJSON *rxjson) {
void process_setPosition(RxContext_t *context, cJSON *rxjson) {
// { "order": "setPosition", "ble_uart_index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 }
int index = 0;
int speedLevel = 0;
@ -137,7 +146,8 @@ void process_getStatus(cJSON *rxjson) {
if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "index"))) {
index = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "index"));
}
order_receipt_getStatus(index);
double motor_position = motor_get_position_degree();
construct_get_status_packet_and_report(index, motor_position);
}
void process_setMotorCurrentSize(cJSON *rxjson) {
@ -155,14 +165,21 @@ void processrxjson(cJSON *rxjson) {
if (!cJSON_IsString(cJSON_GetObjectItem(rxjson, "order"))) {
return;
}
RxContext_t rxcontext = {0};
const char *order = cJSON_GetStringValue(cJSON_GetObjectItem(rxjson, "order"));
if (cJSON_IsString(cJSON_GetObjectItem(rxjson, "order"))) {
rxcontext.order = cJSON_GetStringValue(cJSON_GetObjectItem(rxjson, "order"));
}
if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "index"))) {
rxcontext.index = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "index"));
}
if (strcmp(order, "setPosition") == 0) {
process_setPosition(rxjson);
} else if (strcmp(order, "getStatus") == 0) {
if (strcmp(rxcontext.order, "setPosition") == 0) {
process_setPosition(&rxcontext, rxjson);
} else if (strcmp(rxcontext.order, "getStatus") == 0) {
process_getStatus(rxjson);
} else if (strcmp(order, "setMotorCurrentSize") == 0) {
} else if (strcmp(rxcontext.order, "setMotorCurrentSize") == 0) {
process_setMotorCurrentSize(rxjson);
}
}
@ -181,29 +198,43 @@ void blerxcb(uint8_t *rxmessage, size_t rxsize) {
void motor_on_event(motor_event_t event) {
//使sprintf
if (event == kRunToPosition) {
ESP_LOGI(MAIN_LOG_TAG, "kRunToPosition ok!");
ESP_LOGI(MAIN_LOG_TAG, "motor_on_event: kRunToPosition");
uint8_t buffer[256] = {0};
double motor_stop_position = motor_get_position_degree();
//{ "order": "deviceStatusReport", "ble_uart_index": 0, "deviceState": "running", "position":13.9, "deviceException": 0, "deviceExceptionInfo": ""}
sprintf((char *)buffer,
"{ \"order\": \"deviceStatusReport\", \"index\": %d, \"deviceState\": \"idel\", \"position\":%.2lf, \"deviceException\": 0, \"deviceExceptionInfo\": \"\" }", //
1, motor_stop_position);
/*index :*/ 1, //
/*position :*/ motor_stop_position //
);
bleuart_notify_send(buffer, strlen((char *)buffer));
}
}
#if SUPPORT_KEY_INT
void gpio_input_key_init() {
gpio_config_t gpio_grb_led_structer;
{ // Key1
gpio_config_t gpio_grb_led_structer;
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
gpio_grb_led_structer.mode = GPIO_MODE_INPUT;
gpio_grb_led_structer.pin_bit_mask = GPIO_KEY_INPUT_PIN_SEL;
gpio_grb_led_structer.pull_down_en = 0;
gpio_grb_led_structer.pull_up_en = 0;
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
gpio_grb_led_structer.mode = GPIO_MODE_INPUT;
gpio_grb_led_structer.pin_bit_mask = 1ULL << KEY_INT1;
gpio_grb_led_structer.pull_down_en = 0;
gpio_grb_led_structer.pull_up_en = 0;
gpio_config(&gpio_grb_led_structer);
gpio_config(&gpio_grb_led_structer);
}
{ // Key2
gpio_config_t gpio_grb_led_structer;
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
gpio_grb_led_structer.mode = GPIO_MODE_INPUT;
gpio_grb_led_structer.pin_bit_mask = 1ULL << KEY_INT2;
gpio_grb_led_structer.pull_down_en = 0;
gpio_grb_led_structer.pull_up_en = 0;
gpio_config(&gpio_grb_led_structer);
}
}
#endif

3
main/port.h

@ -1,5 +1,8 @@
#pragma once
#include <stdint.h>
uint32_t port_get_ticket();
uint32_t port_haspassedms(uint32_t ticket);

Loading…
Cancel
Save