Skip to content

Commit

Permalink
Improve config + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
quadule committed Jun 20, 2024
1 parent 7191515 commit 87f96e5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
4 changes: 1 addition & 3 deletions data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
"buttonPin": 15,
"rotaryAPin": 12,
"rotaryBPin": 13,
"pulseCount": 4,
"wifiSSID": "",
"wifiPassword": ""
"pulseCount": 4
}
21 changes: 15 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
23 changes: 13 additions & 10 deletions src/knobby.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Knobby {
int pulseCount();
void setPulseCount(int count);

void printHeader();
void printHeader(bool wifiProvisioned = false);
void resetSettings();

uint8_t batteryPercentage();
Expand Down Expand Up @@ -159,21 +159,25 @@ const String& Knobby::password() {
}

void Knobby::setPassword(const char *password) {
if (_password == password) return;

_password = password;
_preferences.putString("password", _password);
}

bool Knobby::flippedDisplay() { return _flippedDisplay; }

void Knobby::setFlippedDisplay(bool flip) {
if (_flippedDisplay == flip) return;

_flippedDisplay = flip;
_preferences.putBool("flipDisplay", _flippedDisplay);
}

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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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");
Expand All @@ -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");
}
Expand Down
6 changes: 1 addition & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");

Expand Down
2 changes: 0 additions & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 87f96e5

Please sign in to comment.