implemented button - #708

This commit is contained in:
proddy
2021-03-01 22:19:28 +01:00
parent 7521ce6ad3
commit 3eb8ac9194
9 changed files with 560 additions and 216 deletions

View File

@@ -36,6 +36,7 @@
#endif
#include <uuid/log.h>
#include <PButton.h>
using uuid::console::Shell;
@@ -47,92 +48,103 @@ class System {
void loop();
// commands
static void restart();
static void format(uuid::console::Shell & shell);
static void console_commands(Shell & shell, unsigned int context);
static bool command_pin(const char * value, const int8_t id);
static bool command_send(const char * value, const int8_t id);
static bool command_publish(const char * value, const int8_t id);
static bool command_fetch(const char * value, const int8_t id);
static bool command_info(const char * value, const int8_t id, JsonObject & json);
static bool command_settings(const char * value, const int8_t id, JsonObject & json);
#if defined(EMSESP_TEST)
static bool command_test(const char * value, const int8_t id);
#endif
static void upload_status(bool in_progress);
static bool upload_status();
static void show_mem(const char * note);
void init_network();
static void init();
static void led_init();
static void syslog_init();
static void other_init();
void restart();
void format(uuid::console::Shell & shell);
void upload_status(bool in_progress);
bool upload_status();
void show_mem(const char * note);
void get_settings();
void led_init(bool refresh);
void syslog_init(bool refresh);
void adc_init(bool refresh);
void network_init();
void commands_init();
void button_init(bool refresh);
bool check_upgrade();
void send_heartbeat();
static std::string hostname() {
std::string hostname() {
return hostname_;
}
static void hostname(std::string hostname) {
void hostname(std::string hostname) {
hostname_ = hostname;
}
static bool ethernet_connected() {
bool ethernet_connected() {
return ethernet_connected_;
}
static void ethernet_connected(bool b) {
void ethernet_connected(bool b) {
ethernet_connected_ = b;
}
private:
static uuid::log::Logger logger_;
static uint32_t heap_start_;
#ifndef EMSESP_STANDALONE
static uuid::syslog::SyslogService syslog_;
#endif
// button
static PButton myPButton_; // PButton instance
static void button_OnClick(PButton & b);
static void button_OnDblClick(PButton & b);
static void button_OnLongPress(PButton & b);
static void button_OnVLongPress(PButton & b);
static constexpr uint32_t BUTTON_Debounce = 40; // Debounce period to prevent flickering when pressing or releasing the button (in ms)
static constexpr uint32_t BUTTON_DblClickDelay = 250; // Max period between clicks for a double click event (in ms)
static constexpr uint32_t BUTTON_LongPressDelay = 750; // Hold period for a long press event (in ms)
static constexpr uint32_t BUTTON_VLongPressDelay = 9000; // Hold period for a very long press event (in ms)
static constexpr uint32_t SYSTEM_CHECK_FREQUENCY = 5000; // check every 5 seconds
static constexpr uint32_t LED_WARNING_BLINK = 1000; // pulse to show no connection, 1 sec
static constexpr uint32_t LED_WARNING_BLINK_FAST = 100; // flash quickly for boot up sequence
static constexpr uint32_t SYSTEM_HEARTBEAT_INTERVAL = 60000; // in milliseconds, how often the MQTT heartbeat is sent (1 min)
static constexpr uint32_t SYSTEM_MEASURE_ANALOG_INTERVAL = 500;
static constexpr uint8_t LED_ON = LOW; // internal LED
// internal LED
static constexpr uint8_t LED_ON = LOW;
#ifndef EMSESP_STANDALONE
static uuid::syslog::SyslogService syslog_;
#endif
void led_monitor();
void set_led_speed(uint32_t speed);
void system_check();
void measure_analog();
static void show_system(uuid::console::Shell & shell);
static void show_users(uuid::console::Shell & shell);
static void wifi_reconnect();
static int8_t wifi_quality();
void show_system(uuid::console::Shell & shell);
void show_users(uuid::console::Shell & shell);
void wifi_reconnect();
int8_t wifi_quality();
bool system_healthy_ = false;
uint32_t led_flash_speed_ = LED_WARNING_BLINK_FAST; // default boot flashes quickly
uint32_t last_heartbeat_ = 0;
uint32_t last_system_check_ = 0;
static bool upload_status_; // true if we're in the middle of a OTA firmware upload
static uint32_t heap_start_;
static uint16_t analog_;
static bool ethernet_connected_;
bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload
bool ethernet_connected_;
uint16_t analog_;
// settings
static std::string hostname_;
static bool hide_led_;
static uint8_t led_gpio_;
static bool syslog_enabled_;
static bool analog_enabled_;
std::string hostname_;
bool hide_led_;
uint8_t led_gpio_;
bool syslog_enabled_;
bool analog_enabled_;
uint8_t ethernet_profile_;
uint8_t pbutton_gpio_;
int8_t syslog_level_;
uint32_t syslog_mark_interval_;
String syslog_host_;
};
} // namespace emsesp