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