From 73e3c1b5cf6a83f519e853e437dd9060135904e5 Mon Sep 17 00:00:00 2001 From: Jackson Chen Date: Thu, 22 Dec 2016 11:16:52 -0800 Subject: [PATCH] Lights off override (#723) * add proto * promote to static * impl * unsigned * pass arg * fix overflow comparison --- kitsune/commands.c | 6 ++---- kitsune/protobuf/sync_response.pb.c | 5 +++-- kitsune/protobuf/sync_response.pb.h | 11 +++++++---- kitsune/wifi_cmd.c | 5 +++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/kitsune/commands.c b/kitsune/commands.c index 72bd4ecc..d9fbc20c 100644 --- a/kitsune/commands.c +++ b/kitsune/commands.c @@ -770,14 +770,12 @@ uint8_t get_alpha_from_light() LOGI("ALS %d ALPHA %d\r\n", als, alpha); return alpha; } - - +uint32_t light_off_threshold = 100; static int _is_light_off() { static int last_light = -1; static int now_light; static unsigned int last_light_time = 0; - const int light_off_threshold = 100; int ret = 0; xSemaphoreTakeRecursive(_light_data.light_smphr, portMAX_DELAY); @@ -786,7 +784,7 @@ static int _is_light_off() { int delta = last_light - now_light; if(xTaskGetTickCount() - last_light_time > 2000 - && delta >= light_off_threshold + && abs(delta) >= light_off_threshold && now_light < 100) { LOGI("light delta: %d, current %d, last %d\n", delta, now_light, last_light); diff --git a/kitsune/protobuf/sync_response.pb.c b/kitsune/protobuf/sync_response.pb.c index c6fb9392..aaad95cb 100644 --- a/kitsune/protobuf/sync_response.pb.c +++ b/kitsune/protobuf/sync_response.pb.c @@ -1,5 +1,5 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.3.1 at Wed Nov 2 15:28:45 2016. */ +/* Generated by nanopb-0.3.1 at Tue Dec 20 17:34:23 2016. */ #include "sync_response.pb.h" @@ -10,7 +10,7 @@ const int32_t SyncResponse_Alarm_ringtone_id_default = 1; -const pb_field_t SyncResponse_fields[17] = { +const pb_field_t SyncResponse_fields[18] = { PB_FIELD( 6, MESSAGE , OPTIONAL, STATIC , FIRST, SyncResponse, alarm, alarm, &SyncResponse_Alarm_fields), PB_FIELD( 8, MESSAGE , OPTIONAL, STATIC , OTHER, SyncResponse, white_noise, alarm, &SyncResponse_WhiteNoise_fields), PB_FIELD( 10, BOOL , OPTIONAL, STATIC , OTHER, SyncResponse, reset_device, white_noise, 0), @@ -27,6 +27,7 @@ const pb_field_t SyncResponse_fields[17] = { PB_FIELD( 24, STRING , OPTIONAL, STATIC , OTHER, SyncResponse, ring_time_ack, pill_batch_size, 0), PB_FIELD( 25, ENUM , OPTIONAL, STATIC , OTHER, SyncResponse, room_conditions_lights_off, ring_time_ack, 0), PB_FIELD( 26, MESSAGE , OPTIONAL, STATIC , OTHER, SyncResponse, audio_features_control, room_conditions_lights_off, &AudioFeaturesControl_fields), + PB_FIELD( 27, UINT32 , OPTIONAL, STATIC , OTHER, SyncResponse, lights_off_threshold, audio_features_control, 0), PB_LAST_FIELD }; diff --git a/kitsune/protobuf/sync_response.pb.h b/kitsune/protobuf/sync_response.pb.h index a28f2376..061563e4 100644 --- a/kitsune/protobuf/sync_response.pb.h +++ b/kitsune/protobuf/sync_response.pb.h @@ -1,5 +1,5 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.3.1 at Wed Nov 2 15:28:45 2016. */ +/* Generated by nanopb-0.3.1 at Tue Dec 20 17:34:23 2016. */ #ifndef PB_SYNC_RESPONSE_PB_H_INCLUDED #define PB_SYNC_RESPONSE_PB_H_INCLUDED @@ -170,13 +170,15 @@ typedef struct _SyncResponse { SyncResponse_RoomConditions room_conditions_lights_off; bool has_audio_features_control; AudioFeaturesControl audio_features_control; + bool has_lights_off_threshold; + uint32_t lights_off_threshold; } SyncResponse; /* Default values for struct fields */ extern const int32_t SyncResponse_Alarm_ringtone_id_default; /* Initializer values for message structs */ -#define SyncResponse_init_default {false, SyncResponse_Alarm_init_default, false, SyncResponse_WhiteNoise_init_default, false, 0, false, (SyncResponse_RoomConditions)0, {{NULL}, NULL}, false, 0, false, AudioControl_init_default, false, {0, {0}}, false, 0, {{NULL}, NULL}, false, 0, false, 0, false, 0, false, "", false, (SyncResponse_RoomConditions)0, false, AudioFeaturesControl_init_default} +#define SyncResponse_init_default {false, SyncResponse_Alarm_init_default, false, SyncResponse_WhiteNoise_init_default, false, 0, false, (SyncResponse_RoomConditions)0, {{NULL}, NULL}, false, 0, false, AudioControl_init_default, false, {0, {0}}, false, 0, {{NULL}, NULL}, false, 0, false, 0, false, 0, false, "", false, (SyncResponse_RoomConditions)0, false, AudioFeaturesControl_init_default, false, 0} #define SyncResponse_FileDownload_init_default {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0} #define SyncResponse_Alarm_init_default {false, 0, false, 0, false, 1, false, 0, false, 0, false, ""} #define SyncResponse_PairingAction_init_default {{{NULL}, NULL}, false, (SyncResponse_PairingAction_ActionType)0} @@ -185,7 +187,7 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; #define SyncResponse_LEDAction_init_default {false, (SyncResponse_LEDAction_LEDActionType)0, {{NULL}, NULL}, false, 0, false, 0, false, 0} #define SyncResponse_PillSettings_init_default {false, "", false, 0} #define BatchedPillSettings_init_default {0, {SyncResponse_PillSettings_init_default, SyncResponse_PillSettings_init_default}} -#define SyncResponse_init_zero {false, SyncResponse_Alarm_init_zero, false, SyncResponse_WhiteNoise_init_zero, false, 0, false, (SyncResponse_RoomConditions)0, {{NULL}, NULL}, false, 0, false, AudioControl_init_zero, false, {0, {0}}, false, 0, {{NULL}, NULL}, false, 0, false, 0, false, 0, false, "", false, (SyncResponse_RoomConditions)0, false, AudioFeaturesControl_init_zero} +#define SyncResponse_init_zero {false, SyncResponse_Alarm_init_zero, false, SyncResponse_WhiteNoise_init_zero, false, 0, false, (SyncResponse_RoomConditions)0, {{NULL}, NULL}, false, 0, false, AudioControl_init_zero, false, {0, {0}}, false, 0, {{NULL}, NULL}, false, 0, false, 0, false, 0, false, "", false, (SyncResponse_RoomConditions)0, false, AudioFeaturesControl_init_zero, false, 0} #define SyncResponse_FileDownload_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0} #define SyncResponse_Alarm_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, ""} #define SyncResponse_PairingAction_init_zero {{{NULL}, NULL}, false, (SyncResponse_PairingAction_ActionType)0} @@ -250,9 +252,10 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; #define SyncResponse_ring_time_ack_tag 24 #define SyncResponse_room_conditions_lights_off_tag 25 #define SyncResponse_audio_features_control_tag 26 +#define SyncResponse_lights_off_threshold_tag 27 /* Struct field encoding specification for nanopb */ -extern const pb_field_t SyncResponse_fields[17]; +extern const pb_field_t SyncResponse_fields[18]; extern const pb_field_t SyncResponse_FileDownload_fields[12]; extern const pb_field_t SyncResponse_Alarm_fields[7]; extern const pb_field_t SyncResponse_PairingAction_fields[3]; diff --git a/kitsune/wifi_cmd.c b/kitsune/wifi_cmd.c index 2f93a519..c886fdb3 100644 --- a/kitsune/wifi_cmd.c +++ b/kitsune/wifi_cmd.c @@ -1984,6 +1984,7 @@ void reset_to_factory_fw(); extern int data_queue_batch_size; extern int pill_queue_batch_size; +extern uint32_t light_off_threshold; static void _on_response_protobuf( SyncResponse* response_protobuf) { if (response_protobuf->has_alarm) @@ -2041,6 +2042,10 @@ static void _on_response_protobuf( SyncResponse* response_protobuf) mcu_reset(); } } + if(response_protobuf->has_lights_off_threshold) { + light_off_threshold = response_protobuf->lights_off_threshold; + LOGI("loffthr %u\r\n",light_off_threshold); + } _set_led_color_based_on_room_conditions(response_protobuf); }