diff --git a/src/gfx/lv_setup.cpp b/src/gfx/lv_setup.cpp
index 2bbfed6..e7d0f61 100644
--- a/src/gfx/lv_setup.cpp
+++ b/src/gfx/lv_setup.cpp
@@ -27,6 +27,15 @@
LGFX tft;
+struct Timer
+{
+ unsigned long time;
+ long duration = 5000;
+ bool active;
+};
+
+Timer screenTimer;
+
void lv_handler()
{
static uint32_t previousUpdate = 0;
@@ -39,6 +48,22 @@ void lv_handler()
}
}
+void check_display_off()
+{
+ if (screenTimer.active && millis() - screenTimer.time > screenTimer.duration)
+ {
+ tft.setBrightness(0);
+ screenTimer.active = false;
+ }
+}
+
+void set_screen_timer(unsigned long time)
+{
+ tft.setBrightness(255);
+ screenTimer.time = time;
+ screenTimer.active = true;
+}
+
void flush_cb(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
uint32_t w = (area->x2 - area->x1 + 1);
@@ -52,7 +77,7 @@ void flush_cb(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
lv_disp_flush_ready(disp);
}
-void read_cb(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
+void touch_cb(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
uint16_t touchX, touchY;
bool touched = tft.getTouch(&touchX, &touchY);
@@ -61,6 +86,7 @@ void read_cb(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
data->state = LV_INDEV_STATE_PR;
data->point.x = touchX;
data->point.y = touchY;
+ set_screen_timer(millis());
}
else
{
@@ -103,6 +129,6 @@ void lv_begin()
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
- indev_drv.read_cb = read_cb;
+ indev_drv.read_cb = touch_cb;
lv_indev_drv_register(&indev_drv);
}
diff --git a/src/gfx/lv_setup.h b/src/gfx/lv_setup.h
index 04ca1a9..031c35c 100644
--- a/src/gfx/lv_setup.h
+++ b/src/gfx/lv_setup.h
@@ -20,3 +20,6 @@
void lv_begin();
void lv_handler();
+
+void check_display_off();
+void set_screen_timer(unsigned long time);
diff --git a/src/main.cpp b/src/main.cpp
index 74c9ee9..17370cc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -44,9 +44,13 @@ void setup()
lv_disp_set_theme(display, theme);
LaunchScreen::show();
+
+ set_screen_timer(millis());
}
void loop()
{
lv_handler();
+
+ check_display_off();
}
diff --git a/src/services/ble_service.cpp b/src/services/ble_service.cpp
new file mode 100644
index 0000000..019b2f4
--- /dev/null
+++ b/src/services/ble_service.cpp
@@ -0,0 +1,19 @@
+//----------------------------------------------------------------------------
+// OS-Railway - Remote Control
+// Copyright (C) 2023 Peter Siegmund (https://mars3142.dev)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+//
+//----------------------------------------------------------------------------
+#include "ble_service.h"
diff --git a/src/services/ble_service.h b/src/services/ble_service.h
new file mode 100644
index 0000000..0cb5d9d
--- /dev/null
+++ b/src/services/ble_service.h
@@ -0,0 +1,19 @@
+//----------------------------------------------------------------------------
+// OS-Railway - Remote Control
+// Copyright (C) 2023 Peter Siegmund (https://mars3142.dev)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+//
+//----------------------------------------------------------------------------
+#pragma once
diff --git a/src/services/esp_now_service.cpp b/src/services/esp_now_service.cpp
index 06d9e1c..8691991 100644
--- a/src/services/esp_now_service.cpp
+++ b/src/services/esp_now_service.cpp
@@ -17,3 +17,78 @@
//
//----------------------------------------------------------------------------
#include "esp_now_service.h"
+
+#include
+#include
+
+namespace ESPNow
+{
+ enum MessageType
+ {
+ PAIRING,
+ META,
+ FEATURES,
+ COMMAND,
+ };
+ MessageType messageType;
+
+ typedef struct struct_pairing
+ {
+ uint8_t msgType;
+ uint8_t id;
+ uint8_t macAddr[6];
+ uint8_t channel;
+ } struct_pairing;
+
+ typedef struct struct_meta
+ {
+ uint8_t msgType;
+ uint8_t id;
+ /// data?
+ } struct_meta;
+
+ typedef struct struct_features
+ {
+ uint8_t msgType;
+ uint8_t id;
+ /// data?
+ } struct_features;
+
+ typedef struct struct_command
+ {
+ uint8_t msgType;
+ uint8_t id;
+ /// data?
+ } struct_command;
+
+ void init()
+ {
+ WiFi.mode(WIFI_STA);
+
+ if (esp_now_init() != ESP_OK)
+ {
+ Serial.println("Error initializing ESP-NOW");
+ ESP.restart();
+ }
+ esp_now_register_send_cb(onDataSent);
+ esp_now_register_recv_cb(onDataRecv);
+ }
+
+ void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
+ {
+ char macStr[18];
+ snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
+ mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
+ ESP_LOGD("espnow", "Last Packet Sent to: %s", macStr);
+ ESP_LOGD("espnow", "Last Packet Send Status: %s", status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
+ }
+
+ void onDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len)
+ {
+ char macStr[18];
+ snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
+ mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
+ ESP_LOGD("espnow", "Last Packet Recv from: %s", macStr);
+ ESP_LOGD("espnow", "Last Packet Recv Data: %s", *data);
+ }
+}
diff --git a/src/services/esp_now_service.h b/src/services/esp_now_service.h
index 0cb5d9d..efb5d4f 100644
--- a/src/services/esp_now_service.h
+++ b/src/services/esp_now_service.h
@@ -17,3 +17,14 @@
//
//----------------------------------------------------------------------------
#pragma once
+
+#include
+#include
+
+namespace ESPNow
+{
+ void init();
+ void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);
+ void onDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len);
+
+}