clean up
This commit is contained in:
@@ -11,19 +11,25 @@
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
// Serial
|
||||
#define BAUD 115200
|
||||
#define BAUD 921600
|
||||
|
||||
// Sensor pins
|
||||
#define RX2_PIN TOUCH_IICSCL
|
||||
#define TX2_PIN TOUCH_IICSDA
|
||||
|
||||
// Sensor configuration
|
||||
#define COMMAND "FDFCFBFA0800120000006400000004030201" //Normal mode command, see documentation waveshare sensor
|
||||
#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
|
||||
|
||||
byte configCommand[] = {
|
||||
0xFD, 0xFC, 0xFB, 0xFA, 0x08, 0x00, 0x12, 0x00,
|
||||
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x03,
|
||||
0x02, 0x03
|
||||
};
|
||||
|
||||
SemaphoreHandle_t xSemaphore = NULL;
|
||||
PowersSY6970 PMU;
|
||||
|
||||
@@ -47,14 +53,12 @@ static String BASE_URL_HA = "http://192.168.1.2:8123/api/services";
|
||||
static String HA_TOKEN = "abc";
|
||||
|
||||
void setup() {
|
||||
|
||||
xSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(xSemaphore);
|
||||
|
||||
initSerial();
|
||||
initializeWifi();
|
||||
initializeTime();
|
||||
sendCommandAsHex(COMMAND);
|
||||
initializeUI();
|
||||
}
|
||||
|
||||
@@ -108,36 +112,10 @@ 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));
|
||||
}
|
||||
|
||||
void sendCommandAsHex(String hexString) {
|
||||
int hexStringLength = hexString.length();
|
||||
if (hexStringLength % 2 != 0) {
|
||||
Serial.println("Error: Hex string must have an even number of characters.");
|
||||
return;
|
||||
}
|
||||
int byteCount = hexStringLength / 2;
|
||||
byte hexBytes[byteCount];
|
||||
for (int i = 0; i < hexStringLength; i += 2) {
|
||||
String byteString = hexString.substring(i, i + 2);
|
||||
byte hexByte = (byte)strtoul(byteString.c_str(), NULL, 16);
|
||||
hexBytes[i / 2] = hexByte;
|
||||
}
|
||||
// Print confirmation of what's being sent
|
||||
Serial.print("Sending ");
|
||||
Serial.print(byteCount);
|
||||
Serial.print(" bytes: ");
|
||||
for(int i=0; i<byteCount; i++) {
|
||||
if (hexBytes[i] < 16) Serial.print("0");;
|
||||
}
|
||||
Serial.println();
|
||||
// Send the data
|
||||
Serial2.write(hexBytes, byteCount);
|
||||
Serial.println("Initial command sent to Serial2.");
|
||||
Serial2.write(configCommand, sizeof(configCommand));
|
||||
}
|
||||
|
||||
void initializeWifi() {
|
||||
|
||||
WiFi.persistent(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
@@ -164,7 +142,6 @@ void initializeTime() {
|
||||
}
|
||||
|
||||
void initializeUI() {
|
||||
|
||||
Serial.println("Initializing UI....");
|
||||
axs15231_init();
|
||||
lv_init();
|
||||
@@ -223,7 +200,6 @@ void printLocalTime() {
|
||||
}
|
||||
|
||||
void readAndProcessSensorLines() {
|
||||
|
||||
if (millis() - lastMotionCheckTime >= DELAY_STATUS_CHECK) {
|
||||
lastMotionCheckTime = millis();
|
||||
// Check if data is available on Serial2
|
||||
@@ -246,18 +222,24 @@ void readAndProcessSensorLines() {
|
||||
lastMotionDetected = millis();
|
||||
}
|
||||
|
||||
//Serial.print("Radar: ");
|
||||
//Serial.println(distance);
|
||||
|
||||
if (currentStatus && state != 0) {
|
||||
state = 0;
|
||||
Serial.println("Motion detected, turning screen on.");
|
||||
//rest_api_action(0);
|
||||
update_display_state(state);
|
||||
//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);
|
||||
//rest_api_action(2);
|
||||
update_display_state(state);
|
||||
//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);
|
||||
//rest_api_action(1);
|
||||
update_display_state(state);
|
||||
//restApiAction(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -265,7 +247,7 @@ void readAndProcessSensorLines() {
|
||||
}
|
||||
|
||||
// action: 0 => Screen on, => 1 Screen off, => 2 Power off
|
||||
void rest_api_action(int action) {
|
||||
void restApiAction(int action) {
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
int httpResponseCode;
|
||||
|
||||
24
ui-util.cpp
24
ui-util.cpp
@@ -37,6 +37,7 @@ static lv_obj_t *img3;
|
||||
static lv_obj_t *img4;
|
||||
static lv_obj_t *img5;
|
||||
static lv_obj_t *img6;
|
||||
static lv_obj_t *img7;
|
||||
|
||||
// Transition animation
|
||||
static const void *trans_ainm_buf[] = {
|
||||
@@ -51,13 +52,9 @@ void ui_begin() {
|
||||
dis = lv_tileview_create(lv_scr_act());
|
||||
lv_obj_align(dis, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
lv_obj_set_size(dis, LV_PCT(100), LV_PCT(100));
|
||||
// lv_obj_remove_style(dis, 0, LV_PART_SCROLLBAR);
|
||||
lv_obj_set_style_bg_color(dis, lv_color_black(), LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
|
||||
lv_obj_t *tv1 = lv_tileview_add_tile(dis, 0, 0, LV_DIR_VER);
|
||||
lv_obj_t *tv2 = lv_tileview_add_tile(dis, 0, 1, LV_DIR_VER);
|
||||
lv_obj_t *tv3 = lv_tileview_add_tile(dis, 0, 2, LV_DIR_VER);
|
||||
lv_obj_t *tv4 = lv_tileview_add_tile(dis, 0, 3, LV_DIR_VER);
|
||||
|
||||
img1 = lv_gif_create(tv1);
|
||||
img2 = lv_gif_create(tv1);
|
||||
@@ -85,6 +82,25 @@ void ui_begin() {
|
||||
lv_msg_subsribe(MSG_NEW_SEC, update_text_subscriber_cb_demo1, 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);
|
||||
|
||||
if (state == 0) {
|
||||
lv_label_set_text(state_symbol, "#00FF00 " LV_SYMBOL_OK " ON #");
|
||||
} else if (state == 1) {
|
||||
lv_label_set_text(state_symbol, "#FFA500 " LV_SYMBOL_PAUSE " IDLE #");
|
||||
} 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;
|
||||
static int minute = 0;
|
||||
|
||||
Reference in New Issue
Block a user