Skip to content

Commit

Permalink
Use flash button as wifi resetSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaosn committed Jan 28, 2024
1 parent 42e4f93 commit c9e825c
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define RAD_TO_DEG (180.f / M_PI)
#endif

#define TRIGGER_PIN 0 // Flash button in nodemcu
#define UPDATES_PER_SECOND 200
#define EFFECT_PERIOD_CALLBACK (1000 / UPDATES_PER_SECOND)
#define TRACKER_CONFIG_FILENAME "/tracker.json"
Expand Down Expand Up @@ -302,7 +303,24 @@ bool saveConfigSPIFFS() {
return false;
}


void checkButton(){
// check for button press
if ( digitalRead(TRIGGER_PIN) == LOW ) {
// poor mans debounce/press-hold, code not ideal for production
delay(50);
if( digitalRead(TRIGGER_PIN) == 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(TRIGGER_PIN) == LOW ){
Serial.println("Button Held");
Serial.println("Erasing Config, restarting");
wm.resetSettings();
ESP.restart();
}
}
}
}

void setup() {

Expand All @@ -313,6 +331,8 @@ void setup() {
Serial.println("\n Starting");
WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability

pinMode(TRIGGER_PIN, INPUT);

wm.setClass("invert");

// custom_html.setValue("test",4);
Expand Down Expand Up @@ -379,15 +399,15 @@ void setup() {
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
//hwTrack.reset(new HWHeadTrackmpu6050());
hwTrack.reset(new HWHeadTrackmpu9250());
hwTrack.reset(new HWHeadTrackmpu6050());
// hwTrack.reset(new HWHeadTrackmpu9250());

effectPeriodStartMillis = millis();
}

#define NUMBER_OF_SLOTS 10
void loop() {

checkButton();
const uint32_t currentMillis = millis();

if (currentMillis - effectPeriodStartMillis >= EFFECT_PERIOD_CALLBACK) {
Expand Down

0 comments on commit c9e825c

Please sign in to comment.