improvement display state
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
#define COMMAND "FDFCFBFA0800120000000200000004030203" //Normal mode command, see documentation waveshare sensor
|
||||
#define PRESENCE_DISTANCE 200 // in cm
|
||||
#define DELAY_STATUS_CHECK 1000 // delay (in ms) between two checks of the presence
|
||||
#define SLEEP_DELAY 10000 // delay (in ms) until sleep mode
|
||||
#define POWER_DELAY 30000 // delay (in ms) until turning off the screen
|
||||
#define SLEEP_DELAY 30000 // delay (in ms) until sleep mode
|
||||
#define POWER_DELAY 100000 // delay (in ms) until turning off the screen
|
||||
|
||||
byte configCommand[] = {
|
||||
0xFD, 0xFC, 0xFB, 0xFA, 0x08, 0x00, 0x12, 0x00,
|
||||
@@ -85,6 +85,7 @@ void loop() {
|
||||
flag_bl = 1;
|
||||
lv_delay_ms(500);
|
||||
ui_begin();
|
||||
lv_msg_send(MSG_NEW_VOLT, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,6 +113,8 @@ void initSerial() {
|
||||
// Start Serial2 for the HMMD Sensor
|
||||
Serial2.begin(BAUD, SERIAL_8N1, RX2_PIN, TX2_PIN);
|
||||
Serial.println("Serial2 Initialized on RX:" + String(RX2_PIN) + ", TX:" + String(TX2_PIN));
|
||||
Serial.println("Sending configuration to the sensor");
|
||||
delay(2000);
|
||||
Serial2.write(configCommand, sizeof(configCommand));
|
||||
}
|
||||
|
||||
@@ -228,17 +231,17 @@ void readAndProcessSensorLines() {
|
||||
if (currentStatus && state != 0) {
|
||||
state = 0;
|
||||
Serial.println("Motion detected, turning screen on.");
|
||||
update_display_state(state);
|
||||
lv_msg_send(MSG_NEW_VOLT, "0");
|
||||
//restApiAction(0);
|
||||
} else if (!currentStatus && state == 1 && (millis() - lastMotionDetected >= POWER_DELAY)) {
|
||||
state = 2;
|
||||
Serial.printf("No motion detected for %d seconds, turning screen off.\n", POWER_DELAY);
|
||||
update_display_state(state);
|
||||
Serial.printf("No motion detected for %d ms, turning screen off.\n", POWER_DELAY);
|
||||
lv_msg_send(MSG_NEW_VOLT, "2");
|
||||
//restApiAction(2);
|
||||
} else if (!currentStatus && state == 0 && (millis() - lastMotionDetected >= SLEEP_DELAY)) {
|
||||
state = 1;
|
||||
Serial.printf("No motion detected for %d seconds, turning screen screensaver on.\n", SLEEP_DELAY);
|
||||
update_display_state(state);
|
||||
Serial.printf("No motion detected for %d ms, turning screen screensaver on.\n", SLEEP_DELAY);
|
||||
lv_msg_send(MSG_NEW_VOLT, "1");
|
||||
//restApiAction(1);
|
||||
}
|
||||
}
|
||||
|
||||
31
ui-util.cpp
31
ui-util.cpp
@@ -39,6 +39,8 @@ static lv_obj_t *img5;
|
||||
static lv_obj_t *img6;
|
||||
static lv_obj_t *img7;
|
||||
|
||||
lv_obj_t *state_symbol;
|
||||
|
||||
// Transition animation
|
||||
static const void *trans_ainm_buf[] = {
|
||||
&gif_01, &gif_12, &gif_23, &gif_34, &gif_45,
|
||||
@@ -46,6 +48,7 @@ static const void *trans_ainm_buf[] = {
|
||||
};
|
||||
|
||||
static void update_text_subscriber_cb_demo1(void *s, lv_msg_t *msg);
|
||||
static void update_display_state(void *s, lv_msg_t *msg);
|
||||
void set_flip_time_anim(int hour, int minute, int second);
|
||||
|
||||
void ui_begin() {
|
||||
@@ -56,6 +59,12 @@ void ui_begin() {
|
||||
|
||||
lv_obj_t *tv1 = lv_tileview_add_tile(dis, 0, 0, LV_DIR_VER);
|
||||
|
||||
state_symbol = lv_label_create(lv_scr_act());
|
||||
lv_obj_align(state_symbol, LV_ALIGN_TOP_LEFT, 20, 5);
|
||||
lv_obj_set_width(state_symbol, LV_PCT(80));
|
||||
lv_label_set_long_mode(state_symbol, LV_LABEL_LONG_SCROLL);
|
||||
lv_label_set_recolor(state_symbol, true);
|
||||
|
||||
img1 = lv_gif_create(tv1);
|
||||
img2 = lv_gif_create(tv1);
|
||||
img3 = lv_gif_create(tv1);
|
||||
@@ -80,26 +89,24 @@ void ui_begin() {
|
||||
lv_msg_subsribe(MSG_NEW_HOUR, update_text_subscriber_cb_demo1, NULL);
|
||||
lv_msg_subsribe(MSG_NEW_MIN, update_text_subscriber_cb_demo1, NULL);
|
||||
lv_msg_subsribe(MSG_NEW_SEC, update_text_subscriber_cb_demo1, NULL);
|
||||
lv_msg_subsribe(MSG_NEW_VOLT, update_display_state, NULL);
|
||||
}
|
||||
|
||||
void update_display_state(uint16_t state) {
|
||||
lv_obj_t *state_symbol = lv_label_create(lv_scr_act());
|
||||
lv_obj_align(state_symbol, LV_ALIGN_TOP_LEFT, 20, 5);
|
||||
lv_obj_set_width(state_symbol, LV_PCT(80));
|
||||
lv_label_set_long_mode(state_symbol, LV_LABEL_LONG_SCROLL);
|
||||
lv_label_set_recolor(state_symbol, true);
|
||||
static void update_display_state(void *s, lv_msg_t *msg) {
|
||||
const char * payload = (const char *)lv_msg_get_payload(msg);
|
||||
|
||||
if (state == 0) {
|
||||
if (lv_msg_get_id(msg) == MSG_NEW_VOLT) {
|
||||
if (payload == "0") {
|
||||
lv_label_set_text(state_symbol, "#00FF00 " LV_SYMBOL_OK " ON #");
|
||||
} else if (state == 1) {
|
||||
} else if (payload == "1") {
|
||||
lv_label_set_text(state_symbol, "#FFA500 " LV_SYMBOL_PAUSE " IDLE #");
|
||||
} else if (payload == "2") {
|
||||
lv_label_set_text(state_symbol, "#FF0000 " LV_SYMBOL_POWER" OFF #");
|
||||
} else {
|
||||
lv_label_set_text(state_symbol, "#FFA500 " LV_SYMBOL_PAUSE " OFF #");
|
||||
}
|
||||
|
||||
lv_delay_ms(5000);
|
||||
lv_label_set_text(state_symbol, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void update_text_subscriber_cb_demo1(void *s, lv_msg_t *msg) {
|
||||
static int hour = 0;
|
||||
|
||||
Reference in New Issue
Block a user