|
|
@ -3,7 +3,7 @@ |
|
|
|
|
|
|
|
#include "aproject_config/config.h" |
|
|
|
// #include "ify_hrs_protocol/heart_rate_sensor_protocol.h" |
|
|
|
#include "protocol/protocol.h" |
|
|
|
#include "app_protocols/app_protocols.h" |
|
|
|
#include "zdatachannel_service.h" |
|
|
|
// |
|
|
|
#include "app_basic_service/device_version_info_mgr.h" |
|
|
@ -21,11 +21,11 @@ |
|
|
|
* GLOBAL * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
|
|
static hand_acid_mode_t g_hand_acid_mode; |
|
|
|
static hand_pump_working_state_t g_hand_pump_working_state; |
|
|
|
static bool g_connected; |
|
|
|
static int32_t m_longpress_trigger_time = 500; |
|
|
|
static int32_t m_last_usr_operation_time = 0; |
|
|
|
static hand_acid_mode_t g_hand_acid_mode; |
|
|
|
static bool g_hand_pump_working_state; |
|
|
|
static bool g_connected; |
|
|
|
static int32_t m_longpress_trigger_time = 500; |
|
|
|
static int32_t m_last_usr_operation_time = 0; |
|
|
|
|
|
|
|
// static void testlight_state(int val) { |
|
|
|
// int effect = val % 3; |
|
|
@ -66,69 +66,69 @@ void on_zble_event(zble_event_t* event) { |
|
|
|
* À¶ÑÀÏûÏ¢´¦Àí * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
void one_conduction_process_rx_packet(uint8_t* rx, int len) { |
|
|
|
hand_acid_ble_proto_t* rxheader = (hand_acid_ble_proto_t*)rx; |
|
|
|
hand_acid_ble_proto_t* txheader = bletxbuf_get(); |
|
|
|
hand_acid_ble_proto_cmd_t cmd = (hand_acid_ble_proto_cmd_t)rxheader->cmd; |
|
|
|
|
|
|
|
if (len < HAND_ACID_BLE_BASE_SIZE) { |
|
|
|
ZLOGI("rx len error:%d", len); |
|
|
|
return; |
|
|
|
} |
|
|
|
// hand_acid_ble_proto_t* rxheader = (hand_acid_ble_proto_t*)rx; |
|
|
|
// hand_acid_ble_proto_t* txheader = bletxbuf_get(); |
|
|
|
// hand_acid_ble_proto_cmd_t cmd = (hand_acid_ble_proto_cmd_t)rxheader->cmd; |
|
|
|
|
|
|
|
// if (len < HAND_ACID_BLE_BASE_SIZE) { |
|
|
|
// ZLOGI("rx len error:%d", len); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
bletxbuf_clear(); |
|
|
|
|
|
|
|
txheader->cmd = rxheader->cmd; |
|
|
|
txheader->frame_index = rxheader->frame_index; |
|
|
|
txheader->frame_type = kproto_cmd_receipt; |
|
|
|
|
|
|
|
ZLOGI("rx cmd:%d index:%d paralen:%d", cmd, rxheader->frame_index, len - HAND_ACID_BLE_BASE_SIZE); |
|
|
|
NRF_LOG_HEXDUMP_INFO(rx, len); |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief |
|
|
|
* process cmd here |
|
|
|
*/ |
|
|
|
|
|
|
|
if (kproto_cmd_set_state == cmd) { |
|
|
|
uint8_t hand_acid_mode = rxheader->data.set_state.hand_acid_mode; |
|
|
|
uint8_t hand_pump_working_state = rxheader->data.set_state.hand_pump_working_state; |
|
|
|
ZLOGI("update state mode:%d state:%d", hand_acid_mode, hand_pump_working_state); |
|
|
|
|
|
|
|
// push state_change_event event |
|
|
|
{ |
|
|
|
static app_event_t event; |
|
|
|
memset(&event, 0, sizeof(app_event_t)); |
|
|
|
event.eventType = kappevent_device_state_change_event; |
|
|
|
event.val.state_change_event.mode = hand_acid_mode; |
|
|
|
event.val.state_change_event.state = hand_pump_working_state; |
|
|
|
zapp_ebus_push_event(&event); |
|
|
|
} |
|
|
|
|
|
|
|
send_success_receipt(txheader); |
|
|
|
} else if (kproto_cmd_setlong_key_delayms == cmd) { |
|
|
|
uint32_t longkeydelay = rxheader->data.setlong_key_delayms.longkeydelay; |
|
|
|
if (longkeydelay < 500) { |
|
|
|
longkeydelay = 500; |
|
|
|
} |
|
|
|
m_longpress_trigger_time = longkeydelay; |
|
|
|
ZLOGI("set long key delay:%d", m_longpress_trigger_time); |
|
|
|
} |
|
|
|
|
|
|
|
else if (kproto_cmd_reset == cmd) { |
|
|
|
NVIC_SystemReset(); |
|
|
|
} |
|
|
|
|
|
|
|
else if (kproto_cmd_read_power == cmd) { |
|
|
|
txheader->data.read_power.power = 100; |
|
|
|
send_success_receipt(txheader); |
|
|
|
} |
|
|
|
|
|
|
|
else if (kproto_cmd_read_version == cmd) { |
|
|
|
txheader->data.read_version.firmware_version = FIRMWARE_VERSION; |
|
|
|
txheader->data.read_version.blestack_version = BLESTACK_VERSION; |
|
|
|
txheader->data.read_version.bootloader_version = BOOTLOADER_VERSION; |
|
|
|
txheader->data.read_version.hardware_version = HARDWARE_VERSION; |
|
|
|
send_success_receipt(txheader); |
|
|
|
} |
|
|
|
// txheader->cmd = rxheader->cmd; |
|
|
|
// txheader->frame_index = rxheader->frame_index; |
|
|
|
// txheader->frame_type = kproto_cmd_receipt; |
|
|
|
|
|
|
|
// ZLOGI("rx cmd:%d index:%d paralen:%d", cmd, rxheader->frame_index, len - HAND_ACID_BLE_BASE_SIZE); |
|
|
|
// NRF_LOG_HEXDUMP_INFO(rx, len); |
|
|
|
|
|
|
|
// /** |
|
|
|
// * @brief |
|
|
|
// * process cmd here |
|
|
|
// */ |
|
|
|
|
|
|
|
// if (kproto_cmd_set_state == cmd) { |
|
|
|
// uint8_t hand_acid_mode = rxheader->data.set_state.hand_acid_mode; |
|
|
|
// uint8_t hand_pump_working_state = rxheader->data.set_state.hand_pump_working_state; |
|
|
|
// ZLOGI("update state mode:%d state:%d", hand_acid_mode, hand_pump_working_state); |
|
|
|
|
|
|
|
// // push state_change_event event |
|
|
|
// { |
|
|
|
// static app_event_t event; |
|
|
|
// memset(&event, 0, sizeof(app_event_t)); |
|
|
|
// event.eventType = kappevent_device_state_change_event; |
|
|
|
// event.val.state_change_event.mode = hand_acid_mode; |
|
|
|
// event.val.state_change_event.state = hand_pump_working_state; |
|
|
|
// zapp_ebus_push_event(&event); |
|
|
|
// } |
|
|
|
|
|
|
|
// send_success_receipt(txheader); |
|
|
|
// } else if (kproto_cmd_setlong_key_delayms == cmd) { |
|
|
|
// uint32_t longkeydelay = rxheader->data.setlong_key_delayms.longkeydelay; |
|
|
|
// if (longkeydelay < 500) { |
|
|
|
// longkeydelay = 500; |
|
|
|
// } |
|
|
|
// m_longpress_trigger_time = longkeydelay; |
|
|
|
// ZLOGI("set long key delay:%d", m_longpress_trigger_time); |
|
|
|
// } |
|
|
|
|
|
|
|
// else if (kproto_cmd_reset == cmd) { |
|
|
|
// NVIC_SystemReset(); |
|
|
|
// } |
|
|
|
|
|
|
|
// else if (kproto_cmd_read_power == cmd) { |
|
|
|
// txheader->data.read_power.power = 100; |
|
|
|
// send_success_receipt(txheader); |
|
|
|
// } |
|
|
|
|
|
|
|
// else if (kproto_cmd_read_version == cmd) { |
|
|
|
// txheader->data.read_version.firmware_version = FIRMWARE_VERSION; |
|
|
|
// txheader->data.read_version.blestack_version = BLESTACK_VERSION; |
|
|
|
// txheader->data.read_version.bootloader_version = BOOTLOADER_VERSION; |
|
|
|
// txheader->data.read_version.hardware_version = HARDWARE_VERSION; |
|
|
|
// send_success_receipt(txheader); |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
/*********************************************************************************************************************** |
|
|
@ -198,17 +198,17 @@ void on_zapp_ebus_event(void* p_event_data, uint16_t event_size) { |
|
|
|
break; |
|
|
|
case kappevent_device_state_change_event: |
|
|
|
g_hand_acid_mode = (hand_acid_mode_t)p_event->val.state_change_event.mode; |
|
|
|
g_hand_pump_working_state = (hand_pump_working_state_t)p_event->val.state_change_event.state; |
|
|
|
// g_hand_pump_working_state = (hand_pump_working_state_t)p_event->val.state_change_event.state; |
|
|
|
update_light_state(); |
|
|
|
break; |
|
|
|
case kappevent_key_pressed: |
|
|
|
ZLOGI("key pressed:%d", p_event->val.keyid); |
|
|
|
send_key_event(p_event->val.keyid, kkey_short_press_event); |
|
|
|
// send_key_event(p_event->val.keyid, 1); |
|
|
|
zapp_state_machine_change_state(kstate_working_state); |
|
|
|
break; |
|
|
|
case kappevent_key_long_pressed: |
|
|
|
ZLOGI("key long pressed:%d", p_event->val.keyid); |
|
|
|
send_key_event(p_event->val.keyid, kkey_long_press_event); |
|
|
|
// send_key_event(p_event->val.keyid, 2); |
|
|
|
zapp_state_machine_change_state(kstate_working_state); |
|
|
|
break; |
|
|
|
} |
|
|
@ -229,38 +229,38 @@ void on_zapp_ebus_event(void* p_event_data, uint16_t event_size) { |
|
|
|
case kappevent_ble_disconnected: |
|
|
|
ZLOGI("ble disconnected"); |
|
|
|
g_connected = false; |
|
|
|
g_hand_pump_working_state = khand_acid_pump_is_idle; |
|
|
|
// g_hand_pump_working_state = khand_acid_pump_is_idle; |
|
|
|
update_light_state(); |
|
|
|
break; |
|
|
|
|
|
|
|
case kappevent_device_state_change_event: |
|
|
|
g_hand_acid_mode = (hand_acid_mode_t)p_event->val.state_change_event.mode; |
|
|
|
g_hand_pump_working_state = (hand_pump_working_state_t)p_event->val.state_change_event.state; |
|
|
|
// g_hand_acid_mode = (hand_acid_mode_t)p_event->val.state_change_event.mode; |
|
|
|
// g_hand_pump_working_state = (hand_pump_working_state_t)p_event->val.state_change_event.state; |
|
|
|
update_light_state(); |
|
|
|
break; |
|
|
|
case kappevent_key_pressed: |
|
|
|
ZLOGI("key pressed:%d", p_event->val.keyid); |
|
|
|
send_key_event(p_event->val.keyid, kkey_short_press_event); |
|
|
|
// send_key_event(p_event->val.keyid, kkey_short_press_event); |
|
|
|
break; |
|
|
|
case kappevent_key_long_pressed: |
|
|
|
ZLOGI("key long pressed:%d", p_event->val.keyid); |
|
|
|
send_key_event(p_event->val.keyid, kkey_long_press_event); |
|
|
|
// send_key_event(p_event->val.keyid, kkey_long_press_event); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (g_hand_pump_working_state != khand_acid_pump_is_working) { |
|
|
|
if (g_connected) { |
|
|
|
if (znordic_haspassed_ms(m_last_usr_operation_time) > (5 * 60 * 1000)) { |
|
|
|
ZLOGI("no operation over 5min, enter standby"); |
|
|
|
zapp_state_machine_change_state(kstate_standby); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (znordic_haspassed_ms(m_last_usr_operation_time) > (5 * 1000)) { |
|
|
|
ZLOGI("no operation over 5s, enter standby"); |
|
|
|
zapp_state_machine_change_state(kstate_standby); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// if (g_hand_pump_working_state != khand_acid_pump_is_working) { |
|
|
|
// if (g_connected) { |
|
|
|
// if (znordic_haspassed_ms(m_last_usr_operation_time) > (5 * 60 * 1000)) { |
|
|
|
// ZLOGI("no operation over 5min, enter standby"); |
|
|
|
// zapp_state_machine_change_state(kstate_standby); |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// if (znordic_haspassed_ms(m_last_usr_operation_time) > (5 * 1000)) { |
|
|
|
// ZLOGI("no operation over 5s, enter standby"); |
|
|
|
// zapp_state_machine_change_state(kstate_standby); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -333,11 +333,11 @@ static void process_key(key_t* key) { |
|
|
|
|
|
|
|
static void state_machine_driver_tmr_cb(void* p_context) { // |
|
|
|
static key_t mode_and_action_butt = { |
|
|
|
.keid = kkey_id_mode_and_action_butt, |
|
|
|
.keid = 1, |
|
|
|
.read_key_state = key_read_acid_state, |
|
|
|
}; |
|
|
|
static key_t liquid_reflux_butt = { |
|
|
|
.keid = kkey_id_liquid_reflux_butt, |
|
|
|
.keid = 2, |
|
|
|
.read_key_state = key_liquid_reflux_butt_read_state, |
|
|
|
}; |
|
|
|
|
|
|
|