Improved OrangeClock board defintion, add button handler
This commit is contained in:
parent
88e82797a6
commit
730cc4338f
6 changed files with 99 additions and 28 deletions
|
@ -11,7 +11,7 @@
|
|||
"-DARDUINO_ORANGECLOCK",
|
||||
"-DARDUINO_ESP32S3_DEV",
|
||||
"-DIS_ORANGECLOCK",
|
||||
"-DARDUINO_USB_MODE=1",
|
||||
"-DARDUINO_USB_MODE=0",
|
||||
"-DARDUINO_RUNNING_CORE=1",
|
||||
"-DARDUINO_EVENT_RUNNING_CORE=1",
|
||||
"-DARDUINO_USB_CDC_ON_BOOT=1"
|
||||
|
|
|
@ -6,6 +6,9 @@ const char *ntpServer = "pool.ntp.org";
|
|||
// const long gmtOffset_sec = 0;
|
||||
const int daylightOffset_sec = 3600;
|
||||
TaskHandle_t OTAHandle = NULL;
|
||||
SemaphoreHandle_t xButtonSemaphore = NULL;
|
||||
const TickType_t debounceDelay = pdMS_TO_TICKS(500);
|
||||
TickType_t lastButtonPressTime = 0;
|
||||
|
||||
#define STA_SSID ""
|
||||
#define STA_PASS ""
|
||||
|
@ -92,7 +95,7 @@ void setupWifi()
|
|||
|
||||
WiFiManager wm;
|
||||
|
||||
#ifndef ARDUINO_ORANGECLOCK
|
||||
#ifndef ARDUINO_ORANGECLOCK
|
||||
// Touch pin 14 to reset
|
||||
if (touchRead(14) > 9000)
|
||||
{
|
||||
|
@ -109,7 +112,7 @@ void setupWifi()
|
|||
wm.resetSettings();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
String softAP_SSID =
|
||||
String("OrangeBTClock");
|
||||
|
@ -264,6 +267,42 @@ void OTAUpdateTask(void *pvParameters)
|
|||
}
|
||||
}
|
||||
|
||||
void HandleButtonTask(void *pvParameters)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (xSemaphoreTake(xButtonSemaphore, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
TickType_t currentTime = xTaskGetTickCount();
|
||||
if ((currentTime - lastButtonPressTime) >= debounceDelay)
|
||||
{
|
||||
lastButtonPressTime = currentTime;
|
||||
|
||||
Serial.println("Button Pressed");
|
||||
|
||||
leds[0] = CRGB::SkyBlue;
|
||||
leds[1] = CRGB::Black;
|
||||
|
||||
FastLED.show();
|
||||
|
||||
vTaskDelay(100);
|
||||
|
||||
leds[0] = CRGB::Black;
|
||||
leds[1] = CRGB::DarkOrange;
|
||||
|
||||
FastLED.show();
|
||||
|
||||
vTaskDelay(100);
|
||||
|
||||
leds[0] = CRGB::Black;
|
||||
leds[1] = CRGB::Black;
|
||||
|
||||
FastLED.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char getCurrencyIcon()
|
||||
{
|
||||
char ret;
|
||||
|
@ -287,3 +326,22 @@ char getCurrencyIcon()
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void IRAM_ATTR onButtonPress()
|
||||
{
|
||||
xSemaphoreGiveFromISR(xButtonSemaphore, NULL);
|
||||
}
|
||||
|
||||
void setupButtonISR()
|
||||
{
|
||||
xButtonSemaphore = xSemaphoreCreateBinary();
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
HandleButtonTask, // Task function
|
||||
"Button Task", // Task name
|
||||
2048, // Stack size (bytes)
|
||||
NULL, // Task parameters
|
||||
1, // Priority (1 is default)
|
||||
NULL, // Task handle
|
||||
0); // Core to run the task (0 or 1)
|
||||
}
|
|
@ -22,3 +22,5 @@ void setModemSleep();
|
|||
|
||||
bool inPowerSaveMode();
|
||||
char getCurrencyIcon();
|
||||
void IRAM_ATTR onButtonPress();
|
||||
void setupButtonISR();
|
53
src/main.cpp
53
src/main.cpp
|
@ -8,7 +8,6 @@
|
|||
#include "config.hpp"
|
||||
#include "webserver.hpp"
|
||||
#include <data.hpp>
|
||||
#include <FastLED.h>
|
||||
|
||||
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
|
||||
#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */
|
||||
|
@ -35,25 +34,31 @@ uint currentPrice = 0;
|
|||
String currentBlock = "";
|
||||
String currentFees = "";
|
||||
|
||||
#define NUM_LEDS 2
|
||||
CRGB leds[NUM_LEDS];
|
||||
|
||||
void setup()
|
||||
{
|
||||
// setCpuFrequencyMhz(40);
|
||||
Serial.begin(115200);
|
||||
|
||||
//#ifndef IS_ORANGECLOCK
|
||||
delay(2500);
|
||||
Serial.println("Hello");
|
||||
#ifndef IS_ORANGECLOCK
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
//#else
|
||||
FastLED.addLeds<WS2812B, 12, GRB>(leds, NUM_LEDS);
|
||||
leds[0] = CRGB::DarkOrange;
|
||||
#else
|
||||
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
attachInterrupt(BUTTON_PIN, onButtonPress, FALLING);
|
||||
|
||||
FastLED.addLeds<WS2812B, 48, GRB>(leds, NUM_LEDS);
|
||||
leds[0] = CRGB::GreenYellow;
|
||||
leds[1] = CRGB::OrangeRed;
|
||||
|
||||
FastLED.show();
|
||||
//#endif
|
||||
|
||||
setupButtonISR();
|
||||
#endif
|
||||
|
||||
setupPreferences();
|
||||
setupDisplay();
|
||||
|
@ -102,24 +107,24 @@ void loop()
|
|||
|
||||
//
|
||||
|
||||
IPAddress res;
|
||||
uint result = WiFi.hostByName("mempool.space", res);
|
||||
// IPAddress res;
|
||||
// uint result = WiFi.hostByName("mempool.space", res);
|
||||
|
||||
if (result >= 0)
|
||||
{
|
||||
Serial.print("SUCCESS!");
|
||||
Serial.println(res.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
WiFi.reconnect();
|
||||
// if (result >= 0)
|
||||
// {
|
||||
// Serial.print("SUCCESS!");
|
||||
// Serial.println(res.toString());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// WiFi.reconnect();
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
Serial.print('.');
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
// while (WiFi.status() != WL_CONNECTED)
|
||||
// {
|
||||
// Serial.print('.');
|
||||
// delay(1000);
|
||||
// }
|
||||
// }
|
||||
|
||||
for (uint i = 1; i <= 3; i++)
|
||||
{
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
#include "shared.hpp"
|
||||
|
||||
volatile bool buttonPressed = false;
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include <GxEPD2_BW.h>
|
||||
#include "utils.hpp"
|
||||
#include "fonts/fonts.hpp"
|
||||
#include <FastLED.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#ifdef VERSION_EPD_2_13
|
||||
#define EPD_CLASS GxEPD2_213_B74
|
||||
|
@ -101,3 +104,5 @@ extern char currentIcon1;
|
|||
extern char currentIcon2;
|
||||
extern char currentIcon3;
|
||||
|
||||
extern CRGB leds[NUM_LEDS];
|
||||
extern volatile bool buttonPressed;
|
Loading…
Reference in a new issue