mirror of
https://github.com/arwidcool/Solder-Plate.git
synced 2024-11-14 10:17:40 +01:00
fix leds
This commit is contained in:
parent
153ab39ad1
commit
985aff8618
@ -68,6 +68,7 @@ public:
|
||||
{
|
||||
if (childrenMatrix[i][0] == curItem)
|
||||
{
|
||||
Serial.println(String(childrenMatrix[i][0]) + " " + String(childrenMatrix[i][1]));
|
||||
return children[childrenMatrix[i][1]];
|
||||
}
|
||||
}
|
||||
@ -106,7 +107,7 @@ public:
|
||||
return elements[curItem];
|
||||
}
|
||||
|
||||
OledMenu *parent;
|
||||
OledMenu *parent = nullptr;
|
||||
|
||||
protected:
|
||||
int curItem = 0;
|
||||
|
@ -73,6 +73,7 @@ void OledDisplay::handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<Butt
|
||||
void OledDisplay::handleDrawThermistorMenu(OledMenuItem menuItem)
|
||||
{
|
||||
int thermistorIndex = menuItem.identifier - MENUITEM_THERMISTOR_START;
|
||||
// Serial.println("Thermistor index: " + String(thermistorIndex));
|
||||
if (thermistorIndex == 6)
|
||||
{
|
||||
// Showing all thermistors values in a row
|
||||
@ -104,6 +105,7 @@ void OledDisplay::handleDrawThermistorMenu(OledMenuItem menuItem)
|
||||
centerText((String(menuItem.title) + ": " + String(thermistorTemp)).c_str());
|
||||
displayIndicators();
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
|
||||
void OledDisplay::setup()
|
||||
|
@ -1,56 +0,0 @@
|
||||
#include "Leds.h"
|
||||
#include <Arduino.h>
|
||||
#include "../globals.h"
|
||||
|
||||
bool yellowLEDUPOn = false;
|
||||
bool yellowLEDSeleOn = false;
|
||||
LEDS::LEDS()
|
||||
{
|
||||
// Constructor implementation
|
||||
}
|
||||
|
||||
void LEDS::setup()
|
||||
{
|
||||
pinMode(yellowLED, OUTPUT);
|
||||
pinMode(greenLED, OUTPUT);
|
||||
pinMode(redLED, OUTPUT);
|
||||
}
|
||||
void LEDS::handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<ButtonState>> change)
|
||||
{
|
||||
switch (change.first) {
|
||||
case ButtonKind::UP:
|
||||
Serial.println("MEOW");
|
||||
if (change.second.to == ButtonState::PRESSED) {
|
||||
digitalWrite(yellowLED, HIGH);
|
||||
} else if (!yellowLEDSeleOn) {
|
||||
digitalWrite(yellowLED, LOW);
|
||||
}
|
||||
yellowLEDUPOn = change.second.to == ButtonState::PRESSED;
|
||||
break;
|
||||
case ButtonKind::DOWN:
|
||||
if (change.second.to == ButtonState::PRESSED) {
|
||||
digitalWrite(yellowLED, HIGH);
|
||||
} else if (!yellowLEDUPOn) {
|
||||
digitalWrite(yellowLED, LOW);
|
||||
}
|
||||
break;
|
||||
case ButtonKind::BACK:
|
||||
if (change.second.to == ButtonState::PRESSED) {
|
||||
digitalWrite(redLED, HIGH);
|
||||
} else {
|
||||
digitalWrite(redLED, LOW);
|
||||
}
|
||||
break;
|
||||
case ButtonKind::SELECT:
|
||||
if (change.second.to == ButtonState::PRESSED) {
|
||||
analogWrite(greenLED, 30);
|
||||
} else {
|
||||
digitalWrite(greenLED, LOW);
|
||||
}
|
||||
yellowLEDSeleOn = change.second.to == ButtonState::PRESSED;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
@ -2,18 +2,87 @@
|
||||
#define __leds_h__
|
||||
#include "../buttons/base.h"
|
||||
#include "../common.h"
|
||||
#include "../globals.h"
|
||||
|
||||
// If you didnt solder the LEDS in order, change the order here
|
||||
#define yellowLED 18
|
||||
#define greenLED 19
|
||||
#define redLED 20
|
||||
#define LEFT_LED_PIN 20
|
||||
#define MID_LED_PIN 19
|
||||
#define RIGHT_LED_PIN 18
|
||||
#define GREEN_LED_PIN RIGHT_LED_PIN
|
||||
enum LedDesiredState
|
||||
{
|
||||
LED_ON,
|
||||
LED_OFF,
|
||||
LED_BLINKING
|
||||
};
|
||||
|
||||
class LEDS
|
||||
{
|
||||
public:
|
||||
LEDS();
|
||||
void setup();
|
||||
void handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<ButtonState>> change);
|
||||
LEDS(){};
|
||||
void setup()
|
||||
{
|
||||
pinMode(LEFT_LED_PIN, OUTPUT);
|
||||
pinMode(MID_LED_PIN, OUTPUT);
|
||||
pinMode(RIGHT_LED_PIN, OUTPUT);
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
if (state >= PREHEAT && state < DONE)
|
||||
{
|
||||
leftLED = (state == PREHEAT || state == COOL) ? LED_BLINKING : LED_ON;
|
||||
midLED = (state == SOAK || state == COOL) ? LED_BLINKING : (state == PREHEAT ? LED_OFF : LED_ON);
|
||||
rightLED = (state == REFLOW || state == COOL) ? LED_BLINKING : ((state == PREHEAT || state == SOAK) ? LED_OFF : LED_ON);
|
||||
|
||||
}
|
||||
else if (state == DONE)
|
||||
{
|
||||
leftLED = midLED = rightLED = LED_OFF;
|
||||
}
|
||||
setLED(LEFT_LED_PIN, leftLED);
|
||||
setLED(MID_LED_PIN, midLED);
|
||||
setLED(RIGHT_LED_PIN, rightLED);
|
||||
}
|
||||
|
||||
void setLED(int pin, LedDesiredState state)
|
||||
{
|
||||
bool goingToBeOn = state == LED_ON || (state == LED_BLINKING && millis() % 1000 < 500);
|
||||
if (goingToBeOn && pin == GREEN_LED_PIN)
|
||||
{
|
||||
analogWrite(pin, 30);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(pin, goingToBeOn ? HIGH : LOW);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Handles the state change of a button
|
||||
* CALL only if the global state is USER_INPUT
|
||||
*/
|
||||
void handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<ButtonState>> change)
|
||||
{
|
||||
switch (change.first)
|
||||
{
|
||||
case ButtonKind::UP:
|
||||
case ButtonKind::DOWN:
|
||||
midLED = (change.second.to == ButtonState::PRESSED) ? LED_ON : LED_OFF;
|
||||
break;
|
||||
case ButtonKind::BACK:
|
||||
leftLED = (change.second.to == ButtonState::PRESSED) ? LED_ON : LED_OFF;
|
||||
break;
|
||||
case ButtonKind::SELECT:
|
||||
rightLED = (change.second.to == ButtonState::PRESSED) ? LED_ON : LED_OFF;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
LedDesiredState leftLED = LedDesiredState::LED_OFF;
|
||||
LedDesiredState midLED = LedDesiredState::LED_OFF;
|
||||
LedDesiredState rightLED = LedDesiredState::LED_OFF;
|
||||
};
|
||||
#endif
|
@ -62,9 +62,9 @@ void loop()
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
if (k != NULL)
|
||||
{
|
||||
leds.handleButtonStateChange(*k);
|
||||
if (state == USER_INPUT)
|
||||
{
|
||||
leds.handleButtonStateChange(*k);
|
||||
oled.handleButtonStateChange(*k);
|
||||
}
|
||||
else if (state >= PREHEAT && state <= COOL)
|
||||
@ -88,6 +88,7 @@ void loop()
|
||||
}
|
||||
state = newState;
|
||||
|
||||
leds.loop();
|
||||
oled.loop();
|
||||
|
||||
if (state >= PREHEAT && state <= COOL)
|
||||
|
Loading…
Reference in New Issue
Block a user