- Refactoring of the "configuration reset" button
- Adding the possibility to rotate and turn the screen on and off
This commit is contained in:
parent
8b97101e23
commit
af8934643b
@ -37,4 +37,5 @@ build_flags =
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/takkaO/OpenFontRender
|
https://github.com/takkaO/OpenFontRender
|
||||||
bblanchon/ArduinoJson@^6.21.2
|
bblanchon/ArduinoJson@^6.21.2
|
||||||
https://github.com/tzapu/WiFiManager.git
|
https://github.com/tzapu/WiFiManager.git
|
||||||
|
mathertel/OneButton @ ^2.0.3
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
|
//Botón configuración
|
||||||
|
#define PIN_BUTTON_1 0
|
||||||
|
#define PIN_BUTTON_2 14
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <WebServer.h>
|
#include <WebServer.h>
|
||||||
#include <esp_task_wdt.h>
|
#include <esp_task_wdt.h>
|
||||||
#include <TFT_eSPI.h> // Graphics and font library
|
#include <TFT_eSPI.h> // Graphics and font library
|
||||||
|
#include <OneButton.h>
|
||||||
|
|
||||||
#include "mbedtls/md.h"
|
#include "mbedtls/md.h"
|
||||||
#include "media/images.h"
|
#include "media/images.h"
|
||||||
@ -13,6 +18,9 @@
|
|||||||
|
|
||||||
//3 seconds WDT
|
//3 seconds WDT
|
||||||
#define WDT_TIMEOUT 3
|
#define WDT_TIMEOUT 3
|
||||||
|
OneButton button1(PIN_BUTTON_1);
|
||||||
|
OneButton button2(PIN_BUTTON_2);
|
||||||
|
|
||||||
|
|
||||||
OpenFontRender render;
|
OpenFontRender render;
|
||||||
|
|
||||||
@ -31,6 +39,20 @@ unsigned long start = millis();
|
|||||||
|
|
||||||
//void runMonitor(void *name);
|
//void runMonitor(void *name);
|
||||||
|
|
||||||
|
void alternate_screen_state() {
|
||||||
|
int screen_state= digitalRead(38);
|
||||||
|
//Serial.printf("Screen state is '%s', switching to '%s'", screen_state, !screen_state);
|
||||||
|
Serial.println("Switching display state");
|
||||||
|
digitalWrite(38, !screen_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void alternate_screen_rotation() {
|
||||||
|
tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/********* INIT *****/
|
/********* INIT *****/
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@ -41,14 +63,29 @@ void setup()
|
|||||||
// Idle task that would reset WDT never runs, because core 0 gets fully utilized
|
// Idle task that would reset WDT never runs, because core 0 gets fully utilized
|
||||||
disableCore0WDT();
|
disableCore0WDT();
|
||||||
disableCore1WDT();
|
disableCore1WDT();
|
||||||
|
|
||||||
|
// Setup the buttons
|
||||||
|
// Button 1 (Boot)
|
||||||
|
button1.setPressTicks(5000);
|
||||||
|
button1.attachClick(alternate_screen_state);
|
||||||
|
button1.attachDoubleClick(alternate_screen_rotation);
|
||||||
|
// button1.attachLongPressStart([]{Serial.println("Button 1 started a long press");});
|
||||||
|
// button1.attachLongPressStop([]{Serial.println("Button 1 stopped a long press");});
|
||||||
|
// button1.attachDuringLongPress([]{Serial.println("Button 1 is being held down");});
|
||||||
|
|
||||||
|
// Button 2 (GPIO14)
|
||||||
|
button2.setPressTicks(5000);
|
||||||
|
// button2.attachClick();
|
||||||
|
// button2.attachDoubleClick([]{Serial.println("Button 2 was double clicked");});
|
||||||
|
button2.attachLongPressStart(reset_configurations);
|
||||||
|
// button2.attachLongPressStop(reset_configurations);
|
||||||
|
// button2.attachDuringLongPress([]{Serial.println("Button 2 is being held down");});
|
||||||
|
|
||||||
|
|
||||||
/******** INIT NERDMINER ************/
|
/******** INIT NERDMINER ************/
|
||||||
Serial.println("NerdMiner v2 starting......");
|
Serial.println("NerdMiner v2 starting......");
|
||||||
|
|
||||||
// Setup the button
|
|
||||||
pinMode(PIN_BUTTON_1, INPUT);
|
|
||||||
attachInterrupt(PIN_BUTTON_1, checkResetConfigButton, FALLING);
|
|
||||||
|
|
||||||
/******** INIT DISPLAY ************/
|
/******** INIT DISPLAY ************/
|
||||||
tft.init();
|
tft.init();
|
||||||
tft.setRotation(1);
|
tft.setRotation(1);
|
||||||
@ -73,7 +110,7 @@ void setup()
|
|||||||
|
|
||||||
/******** INIT WIFI ************/
|
/******** INIT WIFI ************/
|
||||||
init_WifiManager();
|
init_WifiManager();
|
||||||
|
|
||||||
/******** CREATE TASK TO PRINT SCREEN *****/
|
/******** CREATE TASK TO PRINT SCREEN *****/
|
||||||
//tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
|
//tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
|
||||||
// Higher prio monitor task
|
// Higher prio monitor task
|
||||||
@ -104,7 +141,10 @@ void app_error_fault_handler(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// keep watching the push buttons:
|
||||||
|
button1.tick();
|
||||||
|
button2.tick();
|
||||||
|
|
||||||
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
|
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
|
||||||
|
|
||||||
int newStatus = WiFi.status();
|
int newStatus = WiFi.status();
|
||||||
@ -118,9 +158,7 @@ void loop() {
|
|||||||
oldStatus = newStatus;
|
oldStatus = newStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkResetConfigButton();
|
//Run miner on main core when there is time --Currently on test
|
||||||
|
|
||||||
//Run miner on main core when there is time --Currently on test
|
|
||||||
// runMiner();
|
// runMiner();
|
||||||
|
|
||||||
}
|
}
|
@ -27,10 +27,6 @@ char btcString[80] = "yourBtcAddress";
|
|||||||
// Define WiFiManager Object
|
// Define WiFiManager Object
|
||||||
WiFiManager wm;
|
WiFiManager wm;
|
||||||
|
|
||||||
static int buttonReset = 1;
|
|
||||||
static unsigned long lastButtonPress = 0; // Última vez que se pulsó el botón
|
|
||||||
|
|
||||||
volatile bool buttonPressed = false;
|
|
||||||
|
|
||||||
extern TFT_eSPI tft; // tft variable declared on main
|
extern TFT_eSPI tft; // tft variable declared on main
|
||||||
|
|
||||||
@ -140,8 +136,6 @@ void init_WifiManager()
|
|||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
//Serial.setTxTimeoutMs(10);
|
//Serial.setTxTimeoutMs(10);
|
||||||
//Init config pin
|
|
||||||
pinMode(PIN_BUTTON_2, INPUT);
|
|
||||||
|
|
||||||
//Init pin 15 to eneble 5V external power (LilyGo bug)
|
//Init pin 15 to eneble 5V external power (LilyGo bug)
|
||||||
pinMode(PIN_ENABLE5V, OUTPUT);
|
pinMode(PIN_ENABLE5V, OUTPUT);
|
||||||
@ -271,45 +265,11 @@ void init_WifiManager()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void checkResetConfigButton(){
|
void reset_configurations() {
|
||||||
|
Serial.println("Erasing Config, restarting");
|
||||||
// Leer el estado del botón
|
wm.resetSettings();
|
||||||
int buttonState = digitalRead(PIN_BUTTON_0);
|
SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero
|
||||||
unsigned int last_time = (millis() - lastButtonPress);
|
ESP.restart();
|
||||||
Serial.printf("button pressed %i - %u\n", buttonReset, last_time);
|
|
||||||
|
|
||||||
buttonReset++;
|
|
||||||
lastButtonPress = millis();
|
|
||||||
|
|
||||||
if ( last_time > 1000) {
|
|
||||||
buttonReset = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si el botón está pulsado y ha pasado suficiente tiempo desde la última pulsación
|
|
||||||
if (last_time < 1000 && buttonReset == 4) {
|
|
||||||
buttonPressed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void checkResetConfigButton() {
|
|
||||||
// check for button press
|
|
||||||
if ( digitalRead(PIN_BUTTON_2) == LOW ) {
|
|
||||||
// poor mans debounce/press-hold, code not ideal for production
|
|
||||||
delay(50);
|
|
||||||
if( digitalRead(PIN_BUTTON_2) == LOW ){
|
|
||||||
Serial.println("Button Pressed");
|
|
||||||
// still holding button for 3000 ms, reset settings, code not ideaa for production
|
|
||||||
delay(3000); // reset delay hold
|
|
||||||
if( digitalRead(PIN_BUTTON_2) == LOW ){
|
|
||||||
Serial.println("Button Held");
|
|
||||||
Serial.println("Erasing Config, restarting");
|
|
||||||
wm.resetSettings();
|
|
||||||
SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero
|
|
||||||
ESP.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
//Botón configuración
|
|
||||||
#define PIN_BUTTON_1 0
|
|
||||||
#define PIN_BUTTON_2 14
|
|
||||||
#define PIN_ENABLE5V 15
|
#define PIN_ENABLE5V 15
|
||||||
|
|
||||||
void init_WifiManager();
|
void init_WifiManager();
|
||||||
void wifiManagerProcess();
|
void wifiManagerProcess();
|
||||||
void checkResetConfigButton();
|
void reset_configurations();
|
||||||
void checkRemoveConfiguration();
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user