implement display timeout
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -20,3 +20,6 @@
|
||||
|
||||
void lv_begin();
|
||||
void lv_handler();
|
||||
|
||||
void check_display_off();
|
||||
void set_screen_timer(unsigned long time);
|
||||
|
@@ -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();
|
||||
}
|
||||
|
19
src/services/ble_service.cpp
Normal file
19
src/services/ble_service.cpp
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#include "ble_service.h"
|
19
src/services/ble_service.h
Normal file
19
src/services/ble_service.h
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#pragma once
|
@@ -17,3 +17,78 @@
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#include "esp_now_service.h"
|
||||
|
||||
#include <esp32-hal-log.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -17,3 +17,14 @@
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <esp_now.h>
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user