Compare commits

..

No commits in common. "master" and "update-encoder-logic" have entirely different histories.

9 changed files with 15 additions and 83 deletions

View file

@ -16,7 +16,6 @@ include_directories(include)
add_executable(clock
src/main.cpp
src/Output.cpp
src/Gate.cpp
src/DisplayHandler.cpp
src/EncoderHandler.cpp

View file

@ -13,7 +13,7 @@ class DisplayHandler {
char buffer[32];
uint8_t currentScreen;
std::string screens[7];
std::array<std::string, 5> out_pages = {"Exit", "Mod", "Width", "Prob", "Mute"};
std::array<std::string, 4> out_pages = {"Exit", "Mod", "Width", "Prob"};
bool onOutScreen = 0;
void renderMainPage();
void renderOutPage();

View file

@ -3,28 +3,29 @@
#define Gate_h
#include <cstdint>
#include "Output.h"
class Gate : public Output {
class Gate {
private:
bool state;
uint32_t dur;
uint32_t len;
uint32_t lastTriggerTick = 0xFFFFFFFF;
public:
Gate(uint8_t pin);
uint8_t pin;
uint8_t editing;
int8_t modifierSelectionIndex;
uint8_t divideMode;
uint16_t modifier;
uint16_t tickInterval;
bool isEnabled;
uint8_t width;
uint8_t p;
void turnOn() override;
void turnOff() override;
void turnOn();
void turnOff();
void setLen(uint32_t currentPeriod);
void setDiv(uint8_t modifier_selection_index);
void setWidth(uint16_t newWidth);

View file

@ -1,23 +0,0 @@
// Output.h
#ifndef Output_h
#define Output_h
#include <cstdint>
class Output {
private:
public:
Output(uint8_t pin);
bool state;
uint8_t pin;
uint8_t editing;
bool isEnabled;
virtual ~Output() {};
virtual void turnOn();
virtual void turnOff();
};
#endif

View file

@ -28,7 +28,6 @@ static constexpr uint8_t ENCODER_DT_PIN = 21;
static constexpr uint8_t ENCODER_SW_PIN = 22;
// TIME BASED
extern volatile bool PLAY;
extern volatile uint8_t BPM;
static constexpr uint32_t MINUTE_US = 60000000;
static constexpr uint8_t PPQN = 96;

View file

@ -21,7 +21,7 @@ DisplayHandler::DisplayHandler(Gate* outputs[]) {
currentOut = -1;
updateScreen = 1;
cursorPosition = 0;
mainMaxCursorPosition = 10;
mainMaxCursorPosition = 8;
outMaxCursorPosition = std::size(out_pages) - 1;
cursorClick = 0;
}
@ -96,7 +96,7 @@ void DisplayHandler::moveCursor(bool dir) {
outputs[currentOut]->setWidth(outputs[currentOut]->width);
} else if (currentScreen == 3) { // PROBABILITY
} else if (currentScreen == 3) {
outputs[currentOut]->editing = 1;
if (dir == 1) {
@ -112,11 +112,6 @@ void DisplayHandler::moveCursor(bool dir) {
if (outputs[currentOut]->p < 0) {
outputs[currentOut]->p = 0;
}
} else if (currentScreen == 4) { // MUTE
outputs[currentOut]->editing = 1;
outputs[currentOut]->isEnabled ^= true;
}
}
@ -172,8 +167,6 @@ void DisplayHandler::handleClick() {
currentScreen = 1;
onOutScreen = 1;
cursorClick = 0;
} else if (cursorPosition == 9) { // PLAY/PAUSE BUTTON
PLAY ^= true;
}
}
@ -233,23 +226,8 @@ void DisplayHandler::renderMainPage() {
}
pico_ssd1306::drawText(display, font_12x16, std::to_string(i).c_str(), cursor_x, cursor_y);
cursor_x += 30;
}
if (cursorPosition == 9) { // PLAY BUTTON
pico_ssd1306::fillRect(display, 120, 8, 130, 18, pico_ssd1306::WriteMode::ADD);
pico_ssd1306::drawText(display, font_8x8, PLAY ? ">" : "#", 120, 10, pico_ssd1306::WriteMode::SUBTRACT);
} else {
pico_ssd1306::drawText(display, font_8x8, PLAY ? ">" : "#", 120, 10);
}
if (cursorPosition == 10) { // OPTIONS BUTTON
pico_ssd1306::fillRect(display, 120, 28, 130, 38, pico_ssd1306::WriteMode::ADD);
pico_ssd1306::drawText(display, font_8x8, "*", 120, 30, pico_ssd1306::WriteMode::SUBTRACT);
} else {
pico_ssd1306::drawText(display, font_8x8, "*", 120, 30);
}
}
@ -272,8 +250,6 @@ void DisplayHandler::renderOutPage() {
} else if (currentScreen == 3) { // Probability screen
param_string = std::to_string(outputs[currentOut]->p) + "%";
} else if (currentScreen == 4) { // Mute Screen
param_string = outputs[currentOut]->isEnabled ? "ON" : "OFF";
}
if (cursorClick) {

View file

@ -4,13 +4,13 @@
#include <cstdlib>
Gate::Gate(uint8_t pin) : Output(pin){
Gate::Gate(uint8_t pin) {
this->pin = pin;
state = 0;
editing = 0;
modifierSelectionIndex = 8;
modifierSelectionIndex = 3;
divideMode = 0; // 1 divison | 0 multiplication
modifier = 0; // divide mode modifier (4x, /32, etc)

View file

@ -1,10 +0,0 @@
#include "Output.h"
Output::Output(uint8_t pin) {
this->pin = pin;
state = 0;
isEnabled = false;
}
void Output::turnOn() {}
void Output::turnOff() {}

View file

@ -15,7 +15,7 @@
// Time based operations
struct repeating_timer bpm_timer = {0};
volatile uint8_t BPM = 60;
volatile bool PLAY = true;
volatile uint8_t PLAY = 1;
volatile uint32_t period_us = 0;
volatile uint32_t MASTER_TICK;
@ -122,18 +122,8 @@ int main() {
update_period();
bool lastPlayState = false;
while (true) {
encoder_handler.update();
if (PLAY) {
handle_outs();
} else {
for (Gate* g: outputs) {
g->turnOff();
}
}
lastPlayState = PLAY;
handle_outs();
}
}