Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/vite
Browse files Browse the repository at this point in the history
  • Loading branch information
Coltin Kifer committed Jun 22, 2023
2 parents 3096ba9 + 0c2ecbe commit b003f01
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 30 deletions.
20 changes: 14 additions & 6 deletions src/gaggiuino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void setup(void) {
LOG_INFO("Setup sequence finished");

// Change LED colour on setup exit.
led.setColor(255, 87, 95); // 64171
led.setColor(9, 0, 9); // 64171

iwdcInit();
}
Expand Down Expand Up @@ -132,7 +132,7 @@ static void sensorsRead(void) {
calculateWeightAndFlow();
updateStartupTimer();
readTankWaterLevel();
crazyLed();
doLed();
}

static void sensorReadSwitches(void) {
Expand Down Expand Up @@ -957,24 +957,32 @@ static void readTankWaterLevel(void) {
currentState.waterLvl = tof.readLvl(currentState);
}

static void crazyLed(void) {
static void doLed(void) {
if (brewActive) {
switch(lcdCurrentPageId) {
case NextionPage::BrewGraph:
case NextionPage::BrewManual:
led.setDisco(15u);
break;
case NextionPage::Flush:
led.setDisco(5u);
led.setDisco(100u);
break;
case NextionPage::Descale:
led.setDisco(500u);
break;
default:
led.setColor(0, 0, 0);
break;
}
} else {
if (lcdCurrentPageId == NextionPage::Led) lcdSetLedColour(runningCfg);
else led.setColor(runningCfg.ledR, runningCfg.ledG, runningCfg.ledB);
switch(lcdCurrentPageId) {
case NextionPage::Led:
lcdSetLedColour(runningCfg);
break;
case NextionPage::Home:
default:
led.setColor(runningCfg.ledR, runningCfg.ledG, runningCfg.ledB);
break;
}
}
}
62 changes: 40 additions & 22 deletions src/peripherals/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,46 @@ void LED::setGreen(uint8_t green) {
}

void LED::setDisco(uint32_t increment) {
if(millis() > LED::timer) {
static uint8_t cstate = 1, val = 0;
static uint8_t r,g,b;
// val<<3 adjusts from 5 bit quantity to 8 bit for the library
if(val % 2 == 0) {
b = (cstate & 4) ? val<<3 : r; // Blue channel enabled on cstate = 4,5,6,7
g = (cstate & 2) ? val<<3 : g; // Green channel enabled on cstate = 2,3,6,7
r = (cstate & 1) ? val<<3 : b; // Red channel enabled on cstate = 1,3,5,7
} else {
r = (cstate & 4) ? val<<3 : b; // Red channel enabled on cstate = 4,5,6,7
g = (cstate & 2) ? val<<3 : g; // Green channel enabled on cstate = 2,3,6,7
b = (cstate & 1) ? val<<3 : r; // Blue channel enabled on cstate = 1,3,5,7
}
setColor(r,g,b);
val++;
if (val>31) { // if val has reached max,
val = 0; // reset val
cstate++; // next state
if (cstate > 7) { // if state has reached max
cstate = 0; // reset state
switch(increment) {
case 15: // brew time disco
case 500: // slow fade during descale
if(millis() > LED::timer) {
static uint8_t cstate = 1, val = 0;
static uint8_t r,g,b;
// val<<3 adjusts from 5 bit quantity to 8 bit for the library
if(val % 2 == 0) {
b = (cstate & 4) ? val<<3 : r; // Blue channel enabled on cstate = 4,5,6,7
g = (cstate & 2) ? val<<3 : g; // Green channel enabled on cstate = 2,3,6,7
r = (cstate & 1) ? val<<3 : b; // Red channel enabled on cstate = 1,3,5,7
} else {
r = (cstate & 4) ? val<<3 : b; // Red channel enabled on cstate = 4,5,6,7
g = (cstate & 2) ? val<<3 : g; // Green channel enabled on cstate = 2,3,6,7
b = (cstate & 1) ? val<<3 : r; // Blue channel enabled on cstate = 1,3,5,7
}
setColor(r,g,b);
val++;
if (val>31) { // if val has reached max,
val = 0; // reset val
cstate++; // next state
if (cstate > 7) { // if state has reached max
cstate = 0; // reset state
}
}
LED::timer = millis() + increment;
}
case 100: // flush strobe
if(millis() > LED::timer) {
static uint8_t val = 0;
// val<<3 adjusts from 5 bit quantity to 8 bit for the library
if(val % 2 == 0) {
setColor(255, 255, 255);
} else {
setColor(0, 0, 0);
}
val++;
if (val>31) val = 0; // reset val
LED::timer = millis() + increment;
}
}
LED::timer = millis() + increment;
}
}

3 changes: 1 addition & 2 deletions src/peripherals/tof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "tof.h"
#include "measurements.h"

Measurements sensorOutput(20);

TOF::TOF() {};

void TOF::init(SensorState& sensor) {
Expand All @@ -18,6 +16,7 @@ void TOF::init(SensorState& sensor) {

uint16_t TOF::readLvl(SensorState& sensor) {
#ifdef TOF_VL53L0X
static Measurements sensorOutput(20);
sensorOutput.add(tof.readRangeResult());
sensor.tofReading = readRangeToPct(sensorOutput.latest().value);
#endif
Expand Down

0 comments on commit b003f01

Please sign in to comment.