Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.DS_Store
.DS_Store
.code-workspace
20 changes: 17 additions & 3 deletions firmware/include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@
#define OLED_HEIGHT 64
#define OLED_ADDR 0x3C

// --- Device Configuration ---
#define DEVICE_ORIENTATION 0 // 0 = Default, 1 = Rotated 180°

// Configure settings based on orientation
#if DEVICE_ORIENTATION == 1
#define OLED_ROTATION 2 // 180° rotation
#define ENCODER_A_PIN 25 // Swapped encoder pins
#define ENCODER_B_PIN 27
#define ENCODER_REVERSE_VALUE true // Reverse encoder for timer adjustment
#else
#define OLED_ROTATION 0 // Normal orientation
#define ENCODER_A_PIN 27 // Normal encoder pins
#define ENCODER_B_PIN 25
#define ENCODER_REVERSE_VALUE false // Normal encoder direction
#endif

#define LED_PIN 15
#define NUM_LEDS 16
#define LED_BRIGHTNESS 100

#define ENCODER_A_PIN 27
#define ENCODER_B_PIN 25
#define BUTTON_PIN 26
#define BUTTON_PIN 26 // A0 on QT Py ESP32

// --- LED Colors ---
#define BLUE 0x0000FF
Expand Down
13 changes: 7 additions & 6 deletions firmware/src/controllers/DisplayController.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "controllers/DisplayController.h"
#include "Config.h"

#include "fonts/Picopixel.h"
#include "fonts/Org_01.h"
Expand All @@ -8,17 +9,17 @@ DisplayController::DisplayController(uint8_t oledWidth, uint8_t oledHeight, uint
: oled(oledWidth, oledHeight, &Wire, -1), animation(&oled) {}

void DisplayController::begin() {
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("Initializing display...");
if (!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Loop forever if initialization fails
}

// oled.ssd1306_command(SSD1306_SETCONTRAST);
// oled.ssd1306_command(128);

Serial.println("Display initialized successfully");
Serial.printf("Setting rotation to %d\n", OLED_ROTATION);
oled.setRotation(OLED_ROTATION);
oled.clearDisplay();
oled.display();
Serial.println("DisplayController initialized.");
Serial.println("Display setup complete");
}

void DisplayController::drawSplashScreen() {
Expand Down
24 changes: 17 additions & 7 deletions firmware/src/controllers/InputController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ void InputController::handleButtonInterrupt()
{
if (instancePtr)
{
bool buttonState = digitalRead(instancePtr->buttonPin);
Serial.printf("Button state: %d\n", buttonState);
instancePtr->button.tick();
}
}
Expand All @@ -41,6 +43,7 @@ InputController::InputController(uint8_t buttonPin, uint8_t encoderPinA, uint8_t

void InputController::begin()
{
Serial.printf("Initializing button on pin %d\n", buttonPin);
button.setDebounceMs(20);
button.setClickMs(150);
button.setPressMs(400);
Expand All @@ -50,27 +53,31 @@ void InputController::begin()
pinMode(encoderPinA, INPUT_PULLUP);
pinMode(encoderPinB, INPUT_PULLUP);

Serial.printf("Initial button state: %d\n", digitalRead(buttonPin));

// Set up interrupts for encoder handling
attachInterrupt(digitalPinToInterrupt(encoderPinA), handleEncoderInterrupt, CHANGE);
attachInterrupt(digitalPinToInterrupt(encoderPinB), handleEncoderInterrupt, CHANGE);

// Set up interrupt for button
attachInterrupt(digitalPinToInterrupt(buttonPin), handleButtonInterrupt, CHANGE);

// Set up interrupt for button handling
attachInterrupt(digitalPinToInterrupt(buttonPin), handleButtonInterrupt, CHANGE); // Interrupt on button state change
}

void InputController::update()
{
// Check button state
button.tick();
encoder.tick();

// Check encoder position and calculate delta
int currentPosition = encoder.getPosition();
int delta = currentPosition - lastPosition;

if (delta != 0)
// Check encoder position
long newPosition = encoder.getPosition();
if (newPosition != lastPosition)
{
int delta = newPosition - lastPosition;
lastPosition = newPosition;
onEncoderRotate(delta);
lastPosition = currentPosition;
}
}

Expand Down Expand Up @@ -110,6 +117,7 @@ void InputController::releaseHandlers()
// Internal event handlers that call the registered state handlers
void InputController::onButtonClick()
{
Serial.println("Button clicked!");
if (pressHandler != nullptr)
{
pressHandler();
Expand All @@ -118,6 +126,7 @@ void InputController::onButtonClick()

void InputController::onButtonDoubleClick()
{
Serial.println("Button double clicked!");
if (doublePressHandler != nullptr)
{
doublePressHandler();
Expand All @@ -126,6 +135,7 @@ void InputController::onButtonDoubleClick()

void InputController::onButtonLongPress()
{
Serial.println("Button long pressed!");
if (longPressHandler != nullptr)
{
longPressHandler();
Expand Down
4 changes: 4 additions & 0 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Arduino.h>
#include <Wire.h>
#include "Config.h"
#include "StateMachine.h"
#include "Controllers.h"
Expand All @@ -13,6 +14,9 @@ Preferences preferences;
void setup() {
Serial.begin(115200);

// Initialize I2C
Wire.begin();

// Initialize controllers
inputController.begin();
displayController.begin();
Expand Down
9 changes: 7 additions & 2 deletions firmware/src/states/AdjustState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ void AdjustState::enter()
Serial.println("Adjust State: Encoder turned");
Serial.println(delta);

// Update duration with delta and enforce bounds
this->adjustDuration += (delta * 5);
// Update duration based on orientation configuration
#if ENCODER_REVERSE_VALUE
this->adjustDuration -= (delta * 5); // Reversed
#else
this->adjustDuration += (delta * 5); // Normal
#endif

if (this->adjustDuration < MIN_TIMER) {
this->adjustDuration = MIN_TIMER;
} else if (this->adjustDuration > MAX_TIMER) {
Expand Down
21 changes: 16 additions & 5 deletions firmware/src/states/ResetState.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "StateMachine.h"
#include "Controllers.h"
#include "Config.h"

bool resetSelected = false; // button selection

Expand All @@ -12,11 +13,21 @@ void ResetState::enter()
// Register state-specific handlers
inputController.onEncoderRotateHandler([this](int delta)
{
if (delta > 0) {
resetSelected = true; // Select "RESET"
} else if (delta < 0) {
resetSelected = false; // Select "CANCEL"
} });
Serial.print("Reset State: Encoder delta = ");
Serial.println(delta);

// Update selection based on encoder value
// Note: When pins are swapped, clockwise = -1, counterclockwise = +1
if (delta != 0) {
#if DEVICE_ORIENTATION == 1
resetSelected = (delta > 0); // When rotated, counterclockwise (+1) selects RESET
#else
resetSelected = (delta < 0); // When normal, clockwise (-1) selects RESET
#endif
Serial.print("Reset Selected = ");
Serial.println(resetSelected);
}
});

inputController.onPressHandler([this]()
{
Expand Down