Skip to content

Commit

Permalink
Make encoder pulse count configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
quadule committed Jun 26, 2022
1 parent bb4ab9a commit 188c6cb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"configPassword": "",
"firmwareURL": "",
"pulseCount": null,
"wifiSSID": "",
"wifiPassword": ""
}
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ Streaming services feed you new releases and top hits through algorithmic recomm
* [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

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.

### Wire it up

<img src="images/wiring-diagram.png?raw=true" width="439px" height="439px" alt="wiring diagram of rotary encoder with t-display board">
Expand Down
19 changes: 9 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ void knobRotated() {
int newCount = knob.getCount();
int knobDelta = newCount - lastKnobCount;
int reversingMultiplier = flipDisplay ? -1 : 1;
int positionDelta = knobDelta / ROTARY_ENCODER_PULSE_COUNT * reversingMultiplier;
int positionDelta = knobDelta / pulseCount * reversingMultiplier;
if (positionDelta == 0) return;
lastKnobCount = newCount;

Expand Down Expand Up @@ -1798,8 +1798,11 @@ bool readDataJson() {
}

configPassword = doc["configPassword"] | "";
firmwareURL = doc["firmwareURL"] | "";
firmwareURL = doc["firmwareURL"] | KNOBBY_FIRMWARE_URL;
if (firmwareURL.isEmpty()) firmwareURL = KNOBBY_FIRMWARE_URL;
flipDisplay = doc["flipDisplay"];
pulseCount = doc["pulseCount"];
if (pulseCount <= 0 || pulseCount > 8) pulseCount = ROTARY_ENCODER_PULSE_COUNT;
wifiSSID = doc["wifiSSID"] | WiFi.SSID();
wifiPassword = doc["wifiPassword"] | WiFi.psk();

Expand Down Expand Up @@ -1829,8 +1832,9 @@ bool writeDataJson() {
DynamicJsonDocument doc(5000);

doc["configPassword"] = configPassword;
doc["firmwareURL"] = firmwareURL;
if (!firmwareURL.equals(KNOBBY_FIRMWARE_URL)) doc["firmwareURL"] = firmwareURL;
if (flipDisplay) doc["flipDisplay"] = true;
if (pulseCount != ROTARY_ENCODER_PULSE_COUNT) doc["pulseCount"] = pulseCount;
doc["wifiSSID"] = wifiSSID;
doc["wifiPassword"] = wifiPassword;

Expand Down Expand Up @@ -2669,13 +2673,8 @@ void updateFirmware() {
http.setConnectTimeout(4000);
http.setTimeout(4000);
http.setReuse(false);
if (firmwareURL.isEmpty()) {
log_i("GET %s", KNOBBY_FIRMWARE_URL);
http.begin(client, KNOBBY_FIRMWARE_URL);
} else {
log_i("GET %s", firmwareURL);
http.begin(client, firmwareURL);
}
log_i("GET %s", firmwareURL);
http.begin(client, firmwareURL);
const char * headerKeys[] = { "x-amz-meta-git-version" };
http.collectHeaders(headerKeys, (sizeof(headerKeys) / sizeof(headerKeys[0])));
int code = http.GET();
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ ESPAsync_WiFiManager *wifiManager;
bool displayInvalidated = true;
bool displayInvalidatedPartial = false;
bool flipDisplay = false;
int pulseCount = ROTARY_ENCODER_PULSE_COUNT;
int lastKnobCount = 0;
bool knobHeldForRandom = false;
bool knobRotatedWhileLongPressed = false;
Expand Down

0 comments on commit 188c6cb

Please sign in to comment.