mirror of
https://github.com/arwidcool/Solder-Plate.git
synced 2024-11-30 17:24:29 +01:00
stuff
This commit is contained in:
parent
0aac756d7e
commit
b91e4cee1f
@ -12,13 +12,14 @@ void EEPROMDataManager::setup()
|
||||
saveToEEPROM();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
uint16_t resUint;
|
||||
EEPROM.get(2 * i + EEPROM_START_TERMISTORS, resUint);
|
||||
float res = resUint / 1000.0;
|
||||
thermistors[i].setPotentiometerResistance(res);
|
||||
}
|
||||
// THermistors part. for now we let the user set the thermistor values in code.
|
||||
|
||||
// for (int i = 0; i < 6; i++)
|
||||
// {
|
||||
// uint16_t resUint;
|
||||
// EEPROM.get(2 * i + EEPROM_START_TERMISTORS, resUint);
|
||||
// thermistors[i].setPotentiometerResistance(resUint);
|
||||
// }
|
||||
|
||||
EEPROM.get(EEPROM_START_PLATERES, plateResistanceOhm);
|
||||
}
|
||||
@ -26,14 +27,15 @@ void EEPROMDataManager::saveToEEPROM()
|
||||
{
|
||||
EEPROM.begin();
|
||||
uint16_t tmp = 0x1234;
|
||||
EEPROM.put(0, &tmp); // initialize the EEPROM
|
||||
EEPROM.put(0, tmp); // initialize the EEPROM
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
float res = thermistors[i].getResistance();
|
||||
uint16_t resUint = res * 1000;
|
||||
EEPROM.put(2 * i + EEPROM_START_TERMISTORS, &resUint);
|
||||
}
|
||||
// THermistors part. for now we dont save the thermistor values in code.
|
||||
|
||||
EEPROM.put(EEPROM_START_PLATERES, &plateResistanceOhm);
|
||||
// for (int i = 0; i < 6; i++)
|
||||
// {
|
||||
// uint16_t res = thermistors[i].getPotentiometerResistance();
|
||||
// EEPROM.put(2 * i + EEPROM_START_TERMISTORS, res);
|
||||
// }
|
||||
|
||||
EEPROM.put(EEPROM_START_PLATERES, plateResistanceOhm);
|
||||
}
|
@ -4,44 +4,47 @@
|
||||
#include "../common.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
class OledMenuItem {
|
||||
public:
|
||||
class OledMenuItem
|
||||
{
|
||||
public:
|
||||
OledMenuItem(){};
|
||||
OledMenuItem(char *title): title(title), identifier(0) {};
|
||||
OledMenuItem(char *title, uint8_t identifier): title(title), identifier(identifier) {};
|
||||
OledMenuItem(char *title) : title(title), identifier(0){};
|
||||
OledMenuItem(char *title, uint8_t identifier) : title(title), identifier(identifier){};
|
||||
|
||||
char const * title;
|
||||
char const *title;
|
||||
// Identifier c
|
||||
uint8_t identifier;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
class OledMenu {
|
||||
public:
|
||||
class OledMenu
|
||||
{
|
||||
public:
|
||||
OledMenu(){};
|
||||
OledMenu(uint8_t identifier): identifier(identifier), elementsLength(0), childrenLength(0) {};
|
||||
~OledMenu() {
|
||||
OledMenu(uint8_t identifier) : identifier(identifier), elementsLength(0), childrenLength(0){};
|
||||
~OledMenu()
|
||||
{
|
||||
delete elements;
|
||||
delete children;
|
||||
delete childrenMatrix;
|
||||
};
|
||||
uint8_t identifier;
|
||||
|
||||
void setChildren(OledMenu **children, int length) {
|
||||
void setChildren(OledMenu **children, int length)
|
||||
{
|
||||
this->children = children;
|
||||
this->childrenLength = length;
|
||||
for (int i=0; i<length; i++) {
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
children[i]->parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
void setElements(OledMenuItem *elements, int length) {
|
||||
void setElements(OledMenuItem *elements, int length)
|
||||
{
|
||||
this->elements = new OledMenuItem[length];
|
||||
|
||||
for (int i=0; i<length; i++) {
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
this->elements[i].title = malloc(strlen(elements[i].title) + 1);
|
||||
memcpy(this->elements[i].title, elements[i].title, strlen(elements[i].title) + 1);
|
||||
this->elements[i].identifier = elements[i].identifier;
|
||||
@ -51,16 +54,20 @@ class OledMenu {
|
||||
this->elementsLength = length;
|
||||
}
|
||||
|
||||
void setChildrenMatrix(int length, uint8_t (*matrix)[2]) {
|
||||
void setChildrenMatrix(int length, uint8_t (*matrix)[2])
|
||||
{
|
||||
this->childrenMatrix = matrix;
|
||||
this->childrenMatrixLength = length;
|
||||
}
|
||||
|
||||
// To be invoked when the user presses the SELECT btn
|
||||
// If null is returned then the menu should not be changed
|
||||
OledMenu *getNextMenu() {
|
||||
for (int i=0; i<childrenMatrixLength; i++) {
|
||||
if (childrenMatrix[i][0] == curItem) {
|
||||
OledMenu *getNextMenu()
|
||||
{
|
||||
for (int i = 0; i < childrenMatrixLength; i++)
|
||||
{
|
||||
if (childrenMatrix[i][0] == curItem)
|
||||
{
|
||||
return children[childrenMatrix[i][1]];
|
||||
}
|
||||
}
|
||||
@ -68,7 +75,8 @@ class OledMenu {
|
||||
}
|
||||
|
||||
// To be invoked when the user presses the UP btn
|
||||
OledMenuItem goNextItem() {
|
||||
OledMenuItem goNextItem()
|
||||
{
|
||||
curItem++;
|
||||
curItem = curItem % elementsLength;
|
||||
Serial.println(String(elements[curItem].title) + " - " + String(curItem));
|
||||
@ -76,9 +84,11 @@ class OledMenu {
|
||||
}
|
||||
|
||||
// To be invoked when the user presses the DOWN btn
|
||||
OledMenuItem goPrevItem() {
|
||||
OledMenuItem goPrevItem()
|
||||
{
|
||||
curItem--;
|
||||
if (curItem < 0) {
|
||||
if (curItem < 0)
|
||||
{
|
||||
curItem = elementsLength - 1;
|
||||
}
|
||||
Serial.println(String(elements[curItem].title) + " - " + String(curItem));
|
||||
@ -86,15 +96,19 @@ class OledMenu {
|
||||
return elements[curItem];
|
||||
}
|
||||
|
||||
OledMenuItem getCurItem() {
|
||||
OledMenuItem itemAt(uint8_t index)
|
||||
{
|
||||
return elements[index];
|
||||
}
|
||||
|
||||
OledMenuItem getCurItem()
|
||||
{
|
||||
return elements[curItem];
|
||||
}
|
||||
|
||||
OledMenu *parent;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
int curItem = 0;
|
||||
OledMenuItem *elements;
|
||||
int elementsLength;
|
||||
@ -108,11 +122,13 @@ class OledMenu {
|
||||
*/
|
||||
uint8_t (*childrenMatrix)[2]; // First is element index, second is children index,
|
||||
int childrenMatrixLength;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#define SETMATRIX(menuItem, CODE) { Pair<ButtonKind,int> matrix[] = { CODE }; menuItem.setMatrix( sizeof(matrix)/sizeof(matrix[0]), matrix); }
|
||||
#define SETMATRIX(menuItem, CODE) \
|
||||
{ \
|
||||
Pair<ButtonKind, int> matrix[] = {CODE}; \
|
||||
menuItem.setMatrix(sizeof(matrix) / sizeof(matrix[0]), matrix); \
|
||||
}
|
||||
#define UPBUTTON(index) Pair<ButtonKind, int>(ButtonKind::UP, index),
|
||||
#define DOWNBUTTON(index) Pair<ButtonKind, int>(ButtonKind::DOWN, index),
|
||||
#define SELECTBUTTON(index) Pair<ButtonKind, int>(ButtonKind::SELECT, index),
|
||||
|
@ -5,7 +5,7 @@
|
||||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 64
|
||||
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||
#define MENUID_PLATERES 2
|
||||
#define MENUID_DEBUG 2
|
||||
#define MENUITEM_THERMISTOR_START 150
|
||||
|
||||
unsigned long lastProcessedReflowState = 0;
|
||||
@ -17,6 +17,9 @@ OledDisplay::OledDisplay()
|
||||
|
||||
void OledDisplay::handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<ButtonState>> change)
|
||||
{
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
if (state == USER_INPUT)
|
||||
{
|
||||
if (change.second.to == ButtonState::PRESSED)
|
||||
{
|
||||
if (change.first == ButtonKind::SELECT)
|
||||
@ -37,21 +40,59 @@ void OledDisplay::handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<Butt
|
||||
}
|
||||
else if (change.first == ButtonKind::UP)
|
||||
{
|
||||
curMenu->goNextItem();
|
||||
curMenu->goPrevItem();
|
||||
}
|
||||
else if (change.first == ButtonKind::DOWN)
|
||||
{
|
||||
curMenu->goPrevItem();
|
||||
curMenu->goNextItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OledDisplay::handleDrawThermistorMenu(OledMenuItem menuItem)
|
||||
{
|
||||
int thermistorIndex = menuItem.identifier - MENUITEM_THERMISTOR_START;
|
||||
if (thermistorIndex == 6)
|
||||
{
|
||||
// Showing all thermistors values in a row
|
||||
display.setTextSize(1, 2);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
int thermistorTemp = thermistors[i].getTemperature();
|
||||
display.setCursor(i < 3 ? 0 : (SCREEN_WIDTH / 2 + 20), 20 * (i % 3));
|
||||
display.println(String(i + 1) + " " + String(thermistorTemp));
|
||||
}
|
||||
centerText(menuItem.title);
|
||||
displayIndicators();
|
||||
}
|
||||
else if (thermistorIndex == 7)
|
||||
{
|
||||
display.setTextSize(1, 2);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
float thermR = thermistors[i].getResistance();
|
||||
display.setCursor(i < 3 ? 0 : (SCREEN_WIDTH / 2 + 20), 20 * (i % 3));
|
||||
display.println(String(i + 1) + " " + String((int)(thermR)));
|
||||
}
|
||||
centerText(menuItem.title);
|
||||
displayIndicators();
|
||||
}
|
||||
else
|
||||
{
|
||||
int thermistorTemp = thermistors[thermistorIndex].getTemperature();
|
||||
centerText((String(menuItem.title) + ": " + String(thermistorTemp)).c_str());
|
||||
displayIndicators();
|
||||
}
|
||||
}
|
||||
|
||||
void OledDisplay::setup()
|
||||
{
|
||||
curMenu = new OledMenu();
|
||||
curMenu->setElements(new OledMenuItem[3]{
|
||||
OledMenuItem("Reflow\0"),
|
||||
OledMenuItem("PlateR\0"),
|
||||
OledMenuItem("Temps\0"),
|
||||
OledMenuItem("Debug\0"),
|
||||
},
|
||||
3);
|
||||
|
||||
@ -63,10 +104,11 @@ void OledDisplay::setup()
|
||||
}
|
||||
pickProfilesMenu->setElements(pickProfilesMenuItems, nReflowProfiles);
|
||||
|
||||
OledMenu *plateRMenu = new OledMenu(MENUID_PLATERES);
|
||||
OledMenu *debugMenu = new OledMenu(MENUID_DEBUG);
|
||||
OledMenu *tempsMenu = new OledMenu(3);
|
||||
tempsMenu->setElements(new OledMenuItem[7]{
|
||||
OledMenuItem("ALL\0", MENUITEM_THERMISTOR_START + 6),
|
||||
tempsMenu->setElements(new OledMenuItem[8]{
|
||||
OledMenuItem("C\0", MENUITEM_THERMISTOR_START + 6),
|
||||
OledMenuItem("R\0", MENUITEM_THERMISTOR_START + 7),
|
||||
OledMenuItem("T1\0", MENUITEM_THERMISTOR_START + 0),
|
||||
OledMenuItem("T2\0", MENUITEM_THERMISTOR_START + 1),
|
||||
OledMenuItem("T3\0", MENUITEM_THERMISTOR_START + 2),
|
||||
@ -74,14 +116,14 @@ void OledDisplay::setup()
|
||||
OledMenuItem("T5\0", MENUITEM_THERMISTOR_START + 4),
|
||||
OledMenuItem("T6\0", MENUITEM_THERMISTOR_START + 5),
|
||||
},
|
||||
6);
|
||||
8);
|
||||
|
||||
curMenu->setChildren(
|
||||
new OledMenu *[3]
|
||||
{
|
||||
pickProfilesMenu,
|
||||
plateRMenu,
|
||||
tempsMenu,
|
||||
debugMenu,
|
||||
},
|
||||
3);
|
||||
curMenu->setChildrenMatrix(3, new uint8_t[3][2]{
|
||||
@ -112,38 +154,11 @@ void OledDisplay::loop()
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
if (state == USER_INPUT)
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setRotation(0);
|
||||
display.setTextSize(2);
|
||||
|
||||
OledMenuItem menuItem = curMenu->getCurItem();
|
||||
display.setTextSize(2);
|
||||
if (menuItem.identifier >= MENUITEM_THERMISTOR_START && menuItem.identifier < MENUITEM_THERMISTOR_START + 7)
|
||||
handleUserInputState();
|
||||
}
|
||||
else if (state >= REFLOW && state <= DONE)
|
||||
{
|
||||
int thermistorIndex = menuItem.identifier - MENUITEM_THERMISTOR_START;
|
||||
if (thermistorIndex == 6) {
|
||||
// Showing all
|
||||
} else {
|
||||
int thermistorTemp = thermistors[thermistorIndex].getTemperature();
|
||||
centerText((String(menuItem.title) + ": " + String(thermistorTemp)).c_str());
|
||||
displayIndicators();
|
||||
}
|
||||
|
||||
}
|
||||
else if (curMenu->identifier == MENUID_PLATERES)
|
||||
{
|
||||
// TODO: Logic for plate resistance
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// draw menu item with selectors.
|
||||
|
||||
centerText(menuItem.title);
|
||||
displayIndicators();
|
||||
}
|
||||
|
||||
display.display();
|
||||
handleReflowState();
|
||||
}
|
||||
// Loop implementation
|
||||
}
|
||||
@ -171,6 +186,7 @@ void OledDisplay::drawDebug()
|
||||
}
|
||||
void OledDisplay::displayIndicators()
|
||||
{
|
||||
display.setTextSize(2);
|
||||
display.setRotation(1);
|
||||
display.setCursor(0, SCREEN_WIDTH / 2 - 5);
|
||||
display.print("<");
|
||||
@ -190,16 +206,33 @@ void OledDisplay::centerText(const char *txt)
|
||||
void OledDisplay::handleUserInputState()
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, SCREEN_HEIGHT / 2 + 10);
|
||||
display.setRotation(0);
|
||||
display.setTextSize(2);
|
||||
|
||||
OledMenuItem menuItem = curMenu->getCurItem();
|
||||
display.setTextSize(2);
|
||||
// THERMISTORS
|
||||
if (menuItem.identifier >= MENUITEM_THERMISTOR_START && menuItem.identifier < MENUITEM_THERMISTOR_START + 8)
|
||||
{
|
||||
handleDrawThermistorMenu(menuItem);
|
||||
}
|
||||
else if (curMenu->identifier == MENUID_DEBUG)
|
||||
{
|
||||
drawDebug();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default menu handling. Just display the title and the indicators to go back and forth
|
||||
centerText(menuItem.title);
|
||||
displayIndicators();
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
void OledDisplay::handleReflowState()
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
|
||||
display.println("REFLOW");
|
||||
ReflowProcessState state = reflowProcessState.get();
|
||||
centerText(STATE_STR(state));
|
||||
display.display();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ class OledDisplay {
|
||||
|
||||
void centerText(const char * text);
|
||||
void displayIndicators();
|
||||
void handleDrawThermistorMenu(OledMenuItem item);
|
||||
};
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@ AnalogRef analogRef(5.0);
|
||||
TempCalibration calibration_100K_3950 = {25, 100000, 86, 10000, 170, 1000};
|
||||
// Initalize the 3950 100K thermistors with ACTUAL reference resistor measurnment(Measured between Left pin and GND when the board is powered off) using the default calibration data for 100K thermistor
|
||||
Thermistor thermistor1(THERMISTOR1_PIN, 2500);
|
||||
Thermistor thermistor2(THERMISTOR2_PIN, 2500);
|
||||
Thermistor thermistor2(THERMISTOR2_PIN, 1111);
|
||||
Thermistor thermistor3(THERMISTOR3_PIN, 2500);
|
||||
Thermistor thermistor4(THERMISTOR4_PIN, 2500);
|
||||
Thermistor thermistor5(THERMISTOR5_PIN, 2500);
|
||||
|
@ -1,12 +1,6 @@
|
||||
#include "Thermistor.h"
|
||||
|
||||
|
||||
void Thermistor::setPotentiometerResistance(float resistance)
|
||||
{
|
||||
setRes = resistance;
|
||||
calculateCoefficents(resistance, calibration);
|
||||
}
|
||||
|
||||
int Thermistor::getTemperature()
|
||||
{
|
||||
|
||||
@ -26,7 +20,7 @@ int Thermistor::getTemperature()
|
||||
return temp;
|
||||
}
|
||||
|
||||
void Thermistor::calculateCoefficents(float resistance, TempCalibration calibration)
|
||||
void Thermistor::calculateCoefficents(TempCalibration calibration)
|
||||
{
|
||||
|
||||
float lowK = calibration.lowC + K;
|
||||
|
@ -41,27 +41,27 @@ public:
|
||||
// Constructor
|
||||
Thermistor();
|
||||
|
||||
Thermistor(uint8_t pin, float resistance, TempCalibration calibration): thermistorPin(pin), setRes(resistance), calibration(calibration) {
|
||||
calculateCoefficents(resistance, calibration);
|
||||
Thermistor(uint8_t pin, uint16_t resistance, TempCalibration calibration): thermistorPin(pin), setRes(resistance), calibration(calibration) {
|
||||
calculateCoefficents(calibration);
|
||||
}
|
||||
|
||||
Thermistor(uint8_t pin, float resistance): thermistorPin(pin), setRes(resistance), calibration(calibration_100K_3950) {
|
||||
calculateCoefficents(resistance, calibration);
|
||||
Thermistor(uint8_t pin, uint16_t resistance): thermistorPin(pin), setRes(resistance), calibration(calibration_100K_3950) {
|
||||
calculateCoefficents(calibration);
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
int getTemperature();
|
||||
float getResistance();
|
||||
void setPotentiometerResistance(float resistance);
|
||||
|
||||
void setPotentiometerResistance(uint16_t resistance) { setRes = resistance; };
|
||||
uint16_t getPotentiometerResistance() { return setRes; };
|
||||
// Public Variables
|
||||
void calculateCoefficents(float resistance, TempCalibration calibration);
|
||||
void calculateCoefficents(TempCalibration calibration);
|
||||
|
||||
private:
|
||||
const double K = 273.15;
|
||||
float sensorResistance;
|
||||
uint8_t thermistorPin;
|
||||
float setRes;
|
||||
uint16_t setRes;
|
||||
Coefficents coefficents;
|
||||
float referenceResistance;
|
||||
TempCalibration calibration;
|
||||
|
Loading…
Reference in New Issue
Block a user