Skip to content

Commit

Permalink
Lights off override (#723)
Browse files Browse the repository at this point in the history
* add proto

* promote to static

* impl

* unsigned

* pass arg

* fix overflow comparison
  • Loading branch information
zer0page authored Dec 22, 2016
1 parent a8056a6 commit 73e3c1b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 2 additions & 4 deletions kitsune/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions kitsune/protobuf/sync_response.pb.c
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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),
Expand All @@ -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
};

Expand Down
11 changes: 7 additions & 4 deletions kitsune/protobuf/sync_response.pb.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions kitsune/wifi_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 73e3c1b

Please sign in to comment.