Skip to content

Commit

Permalink
Merge pull request #8 from Zhaosn/master
Browse files Browse the repository at this point in the history
Fixing Compilation Issues, Adapted to nodemcu, Reset wifi settings using flash button
  • Loading branch information
rvt authored Jan 28, 2024
2 parents d9ac1e0 + c9e825c commit 8e5a6e3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
13 changes: 13 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ build_flags =
lib_deps =
${common_env_data.lib_deps_embedded_external}
upload_speed = 921600

[env:nodemcuv2]
platform = [email protected]
framework = arduino
board = nodemcuv2
board_build.flash_mode = dio
board_build.f_flash = 20000000L
build_flags =
-DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
lib_deps =
${common_env_data.lib_deps_embedded_external}
upload_speed = 921600
monitor_speed = 115200
30 changes: 25 additions & 5 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 @@ -109,7 +110,7 @@ void saveParamCallback() {
bool loadAddressInfoFromConfig() {
if (json.containsKey("tracker_server")) {
trackerPort = json["tracker_port"].as<int>();
const char* tmp = json["tracker_server"].as<char*>();
const char* tmp = json["tracker_server"].as<const char*>();
return trackerIpAddress.fromString(tmp);
}

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 8e5a6e3

Please sign in to comment.