This commit is contained in:
Andrea Baccega 2024-01-27 15:31:36 +01:00
parent 0aac756d7e
commit b91e4cee1f
7 changed files with 233 additions and 187 deletions

View File

@ -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);
}

View File

@ -4,115 +4,131 @@
#include "../common.h"
#include <Arduino.h>
class OledMenuItem
{
public:
OledMenuItem(){};
OledMenuItem(char *title) : title(title), identifier(0){};
OledMenuItem(char *title, uint8_t identifier) : title(title), identifier(identifier){};
class OledMenuItem {
public:
OledMenuItem(){};
OledMenuItem(char *title): title(title), identifier(0) {};
OledMenuItem(char *title, uint8_t identifier): title(title), identifier(identifier) {};
char const * title;
// Identifier c
uint8_t identifier;
char const *title;
// Identifier c
uint8_t identifier;
};
class OledMenu {
public:
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) {
this->children = children;
this->childrenLength = length;
for (int i=0; i<length; i++) {
children[i]->parent = this;
class OledMenu
{
public:
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)
{
this->children = children;
this->childrenLength = length;
for (int i = 0; i < length; i++)
{
children[i]->parent = this;
}
}
void setElements(OledMenuItem *elements, int length)
{
this->elements = new OledMenuItem[length];
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;
Serial.println(String(this->elements[i].title) + " " + String(elements[i].title));
}
this->elementsLength = length;
}
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)
{
return children[childrenMatrix[i][1]];
}
}
return nullptr;
}
void setElements(OledMenuItem *elements, int length) {
this->elements = new OledMenuItem[length];
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;
// To be invoked when the user presses the UP btn
OledMenuItem goNextItem()
{
curItem++;
curItem = curItem % elementsLength;
Serial.println(String(elements[curItem].title) + " - " + String(curItem));
return elements[curItem];
}
Serial.println(String(this->elements[i].title) + " " + String(elements[i].title));
}
this->elementsLength = length;
// To be invoked when the user presses the DOWN btn
OledMenuItem goPrevItem()
{
curItem--;
if (curItem < 0)
{
curItem = elementsLength - 1;
}
Serial.println(String(elements[curItem].title) + " - " + String(curItem));
void setChildrenMatrix(int length, uint8_t (*matrix)[2]) {
this->childrenMatrix = matrix;
this->childrenMatrixLength = length;
}
return elements[curItem];
}
// 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) {
return children[childrenMatrix[i][1]];
}
}
return nullptr;
}
OledMenuItem itemAt(uint8_t index)
{
return elements[index];
}
// To be invoked when the user presses the UP btn
OledMenuItem goNextItem() {
curItem++;
curItem = curItem % elementsLength;
Serial.println(String(elements[curItem].title) + " - " + String(curItem));
return elements[curItem];
}
OledMenuItem getCurItem()
{
return elements[curItem];
}
// To be invoked when the user presses the DOWN btn
OledMenuItem goPrevItem() {
curItem--;
if (curItem < 0) {
curItem = elementsLength - 1;
}
Serial.println(String(elements[curItem].title) + " - " + String(curItem));
OledMenu *parent;
return elements[curItem];
}
OledMenuItem getCurItem() {
return elements[curItem];
}
OledMenu *parent;
protected:
int curItem = 0;
OledMenuItem *elements;
int elementsLength;
OledMenu **children;
int childrenLength;
/**
* Matrix of pairs of (element index, children index)
* ex if element at index 0 should go to children at index 1 when user hits SELECT
* then the matrix would be:
* { ..., {0, 1}, ...}
*/
uint8_t (*childrenMatrix)[2]; // First is element index, second is children index,
int childrenMatrixLength;
protected:
int curItem = 0;
OledMenuItem *elements;
int elementsLength;
OledMenu **children;
int childrenLength;
/**
* Matrix of pairs of (element index, children index)
* ex if element at index 0 should go to children at index 1 when user hits SELECT
* then the matrix would be:
* { ..., {0, 1}, ...}
*/
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),

View File

@ -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,41 +17,82 @@ OledDisplay::OledDisplay()
void OledDisplay::handleButtonStateChange(Pair<ButtonKind, StateChangeEvent<ButtonState>> change)
{
if (change.second.to == ButtonState::PRESSED)
ReflowProcessState state = reflowProcessState.get();
if (state == USER_INPUT)
{
if (change.first == ButtonKind::SELECT)
if (change.second.to == ButtonState::PRESSED)
{
OledMenu *selectedMenu = curMenu->getNextMenu();
if (selectedMenu != NULL)
if (change.first == ButtonKind::SELECT)
{
curMenu = selectedMenu;
OledMenu *selectedMenu = curMenu->getNextMenu();
if (selectedMenu != NULL)
{
curMenu = selectedMenu;
}
}
}
else if (change.first == ButtonKind::BACK)
{
OledMenu *selectedMenu = curMenu->parent;
if (selectedMenu != NULL)
else if (change.first == ButtonKind::BACK)
{
curMenu = selectedMenu;
OledMenu *selectedMenu = curMenu->parent;
if (selectedMenu != NULL)
{
curMenu = selectedMenu;
}
}
else if (change.first == ButtonKind::UP)
{
curMenu->goPrevItem();
}
else if (change.first == ButtonKind::DOWN)
{
curMenu->goNextItem();
}
}
else if (change.first == ButtonKind::UP)
{
curMenu->goNextItem();
}
else if (change.first == ButtonKind::DOWN)
{
curMenu->goPrevItem();
}
}
}
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)
{
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();
handleUserInputState();
}
else if (state >= REFLOW && state <= DONE)
{
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);
display.display();
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();
}

View File

@ -21,6 +21,7 @@ class OledDisplay {
void centerText(const char * text);
void displayIndicators();
void handleDrawThermistorMenu(OledMenuItem item);
};

View File

@ -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);

View File

@ -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;

View File

@ -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;