From 87f96e597b0615fe28c77ec0df1ae711d5787359 Mon Sep 17 00:00:00 2001 From: Milo Winningham Date: Wed, 19 Jun 2024 23:07:08 -0700 Subject: [PATCH] Improve config + docs --- data/data.json | 4 +--- readme.md | 21 +++++++++++++++------ src/knobby.h | 23 +++++++++++++---------- src/main.cpp | 6 +----- src/main.h | 2 -- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/data/data.json b/data/data.json index 6c55af8..3be610b 100644 --- a/data/data.json +++ b/data/data.json @@ -5,7 +5,5 @@ "buttonPin": 15, "rotaryAPin": 12, "rotaryBPin": 13, - "pulseCount": 4, - "wifiSSID": "", - "wifiPassword": "" + "pulseCount": 4 } diff --git a/readme.md b/readme.md index 4662b25..fb6a79f 100644 --- a/readme.md +++ b/readme.md @@ -67,12 +67,9 @@ https://user-images.githubusercontent.com/15299/221440478-d7a543d5-4e82-4146-b03 * [MakerFocus 1100mAh LiPo battery](https://www.makerfocus.com/products/makerfocus-3-7v-1100mah-lithium-rechargeable-battery-1s-3c-lipo-battery-with-protection-board-pack-of-4) * [3D printed case and knob](https://www.printables.com/model/156363) -#### Other rotary encoders +Or, install the firmware on another supported ESP32 development board: -If you use a different rotary encoder in your build and find that the knob must be turned two clicks to move one item through the menu, you can configure the encoder’s pulse count. - -1. Edit `data/data.json` and replace `null` with `2` for `pulseCount`. -2. Run `pio run --target uploadfs` to upload the configuration file. +* [LilyGO T-Embed](https://www.lilygo.cc/products/t-embed) ### Wire it up @@ -94,9 +91,21 @@ Alternatively, you can download [the latest release](https://github.com/quadule/ - on Linux or Mac: `./flash.sh` - on Windows: `flash.bat` +### Web configuration + +Additional configuration is available at http://knobby.local after knobby is connected to your network. From this page, you can change hardware settings or apply a manual firmware update. + +You'll need the device password for this, which is randomly generated on first boot if not configured in `data.json`. You can see the configured password in the serial console output over USB, or by double-clicking the knob on the settings > about screen. + +#### Custom builds and other rotary encoders + +You may need to adjust the pin assignments or pulse count to work with different hardware. If you find that the knob must be turned two clicks to move one item through the menu, try changing the pulse count from `4` to `2`. The scroll direction can be also reversed by swapping the A and B pins. + +These settings can be changed from the web configuration page, or also by editing `data/data.json` when setting up a device for the first time (see below). + ### Compile from source -1. Edit `data/data.json` and enter your wifi network information (if you want; it can also be configured later) +1. Edit `data/data.json` and update the configuration if necessary. 2. Build and upload with [PlatformIO](https://platformio.org/): `pio run && pio run --target upload && pio run --target uploadfs` If data.json is not configured or there is a problem connecting to your network, knobby will enter configuration mode. Join the temporary wifi network displayed on screen and wait for the configuration portal to appear or visit http://192.168.4.1. Enter your wifi network information, then switch back to your normal wifi network and visit http://knobby.local to continue. diff --git a/src/knobby.h b/src/knobby.h index 0937e46..002b693 100644 --- a/src/knobby.h +++ b/src/knobby.h @@ -49,7 +49,7 @@ class Knobby { int pulseCount(); void setPulseCount(int count); - void printHeader(); + void printHeader(bool wifiProvisioned = false); void resetSettings(); uint8_t batteryPercentage(); @@ -159,6 +159,8 @@ const String& Knobby::password() { } void Knobby::setPassword(const char *password) { + if (_password == password) return; + _password = password; _preferences.putString("password", _password); } @@ -166,6 +168,8 @@ void Knobby::setPassword(const char *password) { bool Knobby::flippedDisplay() { return _flippedDisplay; } void Knobby::setFlippedDisplay(bool flip) { + if (_flippedDisplay == flip) return; + _flippedDisplay = flip; _preferences.putBool("flipDisplay", _flippedDisplay); } @@ -173,7 +177,7 @@ void Knobby::setFlippedDisplay(bool flip) { int Knobby::buttonPin() { return _buttonPin; } void Knobby::setButtonPin(int pin) { - if (pin >= 0 && pin <= 39) { + if (pin >= 0 && pin <= 39 && pin != _buttonPin) { _buttonPin = pin; _preferences.putInt("buttonPin", _buttonPin); } @@ -182,7 +186,7 @@ void Knobby::setButtonPin(int pin) { int Knobby::rotaryAPin() { return _rotaryAPin; } void Knobby::setRotaryAPin(int pin) { - if (pin >= 0 && pin <= 39) { + if (pin >= 0 && pin <= 39 && pin != _rotaryAPin) { _rotaryAPin = pin; _preferences.putInt("rotaryAPin", _rotaryAPin); } @@ -191,7 +195,7 @@ void Knobby::setRotaryAPin(int pin) { int Knobby::rotaryBPin() { return _rotaryBPin; } void Knobby::setRotaryBPin(int pin) { - if (pin >= 0 && pin <= 39) { + if (pin >= 0 && pin <= 39 && pin != _rotaryBPin) { _rotaryBPin = pin; _preferences.putInt("rotaryBPin", _rotaryBPin); } @@ -200,13 +204,13 @@ void Knobby::setRotaryBPin(int pin) { int Knobby::pulseCount() { return _pulseCount; } void Knobby::setPulseCount(int count) { - if (count > 0 && count <= 8) { + if (count > 0 && count <= 8 && count != _pulseCount) { _pulseCount = count; _preferences.putInt("pulseCount", _pulseCount); } } -void Knobby::printHeader() { +void Knobby::printHeader(bool wifiProvisioned) { const esp_app_desc_t *desc = esp_ota_get_app_description(); log_printf("\n _ _ _ |\n"); log_printf(" | | | | | | |\n"); @@ -218,13 +222,12 @@ void Knobby::printHeader() { log_printf(" https://knobby.net |\n"); log_printf("___________________________________________|____________________________________\n"); log_printf("\n"); - if (WiFi.SSID().isEmpty()) { + if (wifiProvisioned) { + log_printf(" for configuration and more: http://knobby.local?pass=%s\n", password()); + } else { log_printf(" setup this device via usb or wifi:\n"); log_printf(" * (re)connect and visit https://setup.knobby.net to configure\n"); log_printf(" * or join the wifi network %s with password %s\n", name(), password()); - } else { - log_printf(" connecting to wifi network: %s\n", WiFi.SSID()); - log_printf(" for configuration and more: http://knobby.local?pass=%s\n", password()); } log_printf("\n"); } diff --git a/src/main.cpp b/src/main.cpp index 8e2bb41..3636f4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -367,7 +367,7 @@ void setup() { xTaskCreatePinnedToCore(jpgDecodeLoop, "jpgDecode", 10000, NULL, 0, &jpgDecodeTask, 0); if (knobby.powerStatus() != PowerStatusPowered) knobby.updateBattery(); - if (knobby.powerStatus() == PowerStatusPowered) knobby.printHeader(); + if (knobby.powerStatus() == PowerStatusPowered) knobby.printHeader(wifiProvisioned); } void setLightSleepEnabled(bool enabled) { @@ -2265,8 +2265,6 @@ bool readDataJson() { if (!doc["rotaryAPin"].isNull()) knobby.setRotaryAPin(doc["rotaryAPin"]); if (!doc["rotaryBPin"].isNull()) knobby.setRotaryBPin(doc["rotaryBPin"]); if (!doc["pulseCount"].isNull()) knobby.setPulseCount(doc["pulseCount"]); - wifiSSID = doc["wifiSSID"] | WiFi.SSID(); - wifiPassword = doc["wifiPassword"] | WiFi.psk(); JsonArray usersArray = doc["users"]; spotifyUsers.clear(); @@ -2298,8 +2296,6 @@ bool writeDataJson() { DynamicJsonDocument doc(5000); if (!firmwareURL.equals(defaultFirmwareURL)) doc["firmwareURL"] = firmwareURL; - if (knobby.flippedDisplay()) doc["flipDisplay"] = true; - if (knobby.pulseCount() != ROTARY_ENCODER_PULSE_COUNT) doc["pulseCount"] = knobby.pulseCount(); JsonArray usersArray = doc.createNestedArray("users"); diff --git a/src/main.h b/src/main.h index 4dcc50c..2806a52 100644 --- a/src/main.h +++ b/src/main.h @@ -322,8 +322,6 @@ unsigned long menuClickedMillis = 0; unsigned long menuTimeoutMillis = 15000; unsigned long wifiConnectTimeoutMillis = 45000; bool wifiConnectWarning = false; -String wifiSSID; -String wifiPassword; size_t updateContentLength = 0; long spotifyApiRequestStartedMillis = -1;