Improved readability... I hope.
Arduino sketch file now only contains #includes and setup/loop functions. Everything else moved to separate included files.
This commit is contained in:
parent
288c7dfc80
commit
50bee2daa0
@ -14,89 +14,11 @@
|
|||||||
// My Includes
|
// My Includes
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "button.h"
|
#include "src/button.h"
|
||||||
#include "slowPWM.h"
|
#include "src/slowPWM.h"
|
||||||
#include "thermoControl.h"
|
#include "src/thermoControl.h"
|
||||||
|
#include "src/mqtt.h"
|
||||||
/* Defined in config.h for now */
|
#include "src/functions.h"
|
||||||
// uint8_t ThreshPWR = 5;
|
|
||||||
// double Hysteresis = 1;
|
|
||||||
|
|
||||||
// User I/O objects.
|
|
||||||
Button Enter;
|
|
||||||
MD_REncoder rotary = MD_REncoder(I_DT, I_CLK);
|
|
||||||
LiquidCrystal_I2C lcd(0x27,20,4);
|
|
||||||
|
|
||||||
// Internal I/O objects.
|
|
||||||
slowPWM boilPWM;
|
|
||||||
thermoControl KettleController;
|
|
||||||
|
|
||||||
// Network objects.
|
|
||||||
EthernetClient net;
|
|
||||||
PubSubClient mqtt_client;
|
|
||||||
|
|
||||||
// Return a character array to represent the
|
|
||||||
// state of the kettle.
|
|
||||||
char* ShowKettleState() {
|
|
||||||
if (KettleController.Mode() == MANUAL) {
|
|
||||||
return (char*)F("Kettle: Manual");
|
|
||||||
} else if (KettleController.Mode() == AUTOMATIC) {
|
|
||||||
return (char*)F("Kettle: Auto");
|
|
||||||
} else {
|
|
||||||
return (char*)F("Kettle: Off");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char* ShowKettleSetting() {
|
|
||||||
static char LCD_Line[21];
|
|
||||||
char setting[4];
|
|
||||||
if (KettleController.Mode() == MANUAL) {
|
|
||||||
strcpy(LCD_Line, (char*)F("Kettle Power: "));
|
|
||||||
itoa(KettleController.Power(), setting, 10);
|
|
||||||
strcat(LCD_Line, setting);
|
|
||||||
strcat(LCD_Line, (char*)F("%"));
|
|
||||||
|
|
||||||
return LCD_Line;
|
|
||||||
} else if (KettleController.Mode() == AUTOMATIC) {
|
|
||||||
strcpy(LCD_Line, (char*)F("Kettle Temp: "));
|
|
||||||
itoa(KettleController.Setpoint(), setting, 10);
|
|
||||||
strcat(LCD_Line, setting);
|
|
||||||
strcat(LCD_Line, (char*)F("F"));
|
|
||||||
return LCD_Line;
|
|
||||||
} else {
|
|
||||||
return (char*)"";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interrupt function to run when encoder is turned.
|
|
||||||
//
|
|
||||||
// Increases/decreases the kettle output to a max
|
|
||||||
// of 100% and minimum of 0%.
|
|
||||||
void doEncoder()
|
|
||||||
{
|
|
||||||
uint8_t result = rotary.read();
|
|
||||||
uint8_t inc;
|
|
||||||
uint8_t KettleDuty = (uint8_t)KettleController.Power();
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
uint8_t speed = rotary.speed();
|
|
||||||
speed >= 10 ? inc = 5 : inc = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == DIR_CW && KettleDuty < 100) {
|
|
||||||
KettleDuty = (KettleDuty / inc) * inc + inc;
|
|
||||||
} else if (result == DIR_CCW && KettleDuty > 0) {
|
|
||||||
KettleDuty = (KettleDuty / inc) * inc - inc;
|
|
||||||
}
|
|
||||||
KettleController.Power((double)KettleDuty);
|
|
||||||
SettingChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// LCD menu setup.
|
|
||||||
LiquidLine kettle_state_line(0, 0, ShowKettleState);
|
|
||||||
LiquidLine kettle_power_line(0, 1, ShowKettleSetting);
|
|
||||||
LiquidScreen home_screen(kettle_state_line, kettle_power_line);
|
|
||||||
LiquidMenu menu(lcd);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
ConfigData config;
|
ConfigData config;
|
||||||
@ -137,27 +59,6 @@ void setup() {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void UpdateBoilKettle(){
|
|
||||||
|
|
||||||
|
|
||||||
if (Enter.pressed()) {
|
|
||||||
KettleController.CycleMode();
|
|
||||||
SettingChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SettingChanged) {
|
|
||||||
menu.update();
|
|
||||||
SettingChanged = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (KettleController.Mode() != OFF) {
|
|
||||||
if (KettleController.Compute()) KettleDuty = KettleController.Power();
|
|
||||||
digitalWrite(O_PWM, boilPWM.compute(KettleDuty));
|
|
||||||
} else {
|
|
||||||
digitalWrite(O_PWM, boilPWM.compute(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
UpdateBoilKettle();
|
UpdateBoilKettle();
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef GLOBALS_h
|
#ifndef GLOBALS_h
|
||||||
#define GLOBALS_h
|
#define GLOBALS_h
|
||||||
|
|
||||||
|
#include "src/button.h"
|
||||||
|
#include "src/slowPWM.h"
|
||||||
|
#include "src/thermoControl.h"
|
||||||
|
|
||||||
const uint8_t CompileTimeP[] PROGMEM = __DATE__ " " __TIME__;
|
const uint8_t CompileTimeP[] PROGMEM = __DATE__ " " __TIME__;
|
||||||
const size_t ConfAddress = sizeof(CompileTimeP);
|
const size_t ConfAddress = sizeof(CompileTimeP);
|
||||||
|
|
||||||
@ -49,6 +53,25 @@ bool SettingChanged = false;
|
|||||||
const int UpdateInterval = 5000;
|
const int UpdateInterval = 5000;
|
||||||
unsigned long lastRun = 0;
|
unsigned long lastRun = 0;
|
||||||
|
|
||||||
|
// User I/O objects.
|
||||||
|
Button Enter;
|
||||||
|
MD_REncoder rotary = MD_REncoder(I_DT, I_CLK);
|
||||||
|
LiquidCrystal_I2C lcd(0x27,20,4);
|
||||||
|
|
||||||
|
// Internal I/O objects.
|
||||||
|
slowPWM boilPWM;
|
||||||
|
thermoControl KettleController;
|
||||||
|
|
||||||
|
// Network objects.
|
||||||
|
EthernetClient net;
|
||||||
|
PubSubClient mqtt_client;
|
||||||
|
|
||||||
|
// LCD menu setup.
|
||||||
|
LiquidLine kettle_state_line(0, 0, ShowKettleState);
|
||||||
|
LiquidLine kettle_power_line(0, 1, ShowKettleSetting);
|
||||||
|
LiquidScreen home_screen(kettle_state_line, kettle_power_line);
|
||||||
|
LiquidMenu menu(lcd);
|
||||||
|
|
||||||
// Pin Definitions
|
// Pin Definitions
|
||||||
#ifndef I_CLK
|
#ifndef I_CLK
|
||||||
#define I_CLK 2
|
#define I_CLK 2
|
||||||
@ -69,5 +92,4 @@ unsigned long lastRun = 0;
|
|||||||
#define I_CS2 48
|
#define I_CS2 48
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
79
boil_kettle/src/functions.h
Normal file
79
boil_kettle/src/functions.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "../globals.h"
|
||||||
|
|
||||||
|
// Interrupt function to run when encoder is turned.
|
||||||
|
//
|
||||||
|
// Increases/decreases the kettle output to a max
|
||||||
|
// of 100% and minimum of 0%.
|
||||||
|
void doEncoder()
|
||||||
|
{
|
||||||
|
uint8_t result = rotary.read();
|
||||||
|
uint8_t inc;
|
||||||
|
uint8_t KettleDuty = (uint8_t)KettleController.Power();
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
uint8_t speed = rotary.speed();
|
||||||
|
speed >= 10 ? inc = 5 : inc = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == DIR_CW && KettleDuty < 100) {
|
||||||
|
KettleDuty = (KettleDuty / inc) * inc + inc;
|
||||||
|
} else if (result == DIR_CCW && KettleDuty > 0) {
|
||||||
|
KettleDuty = (KettleDuty / inc) * inc - inc;
|
||||||
|
}
|
||||||
|
KettleController.Power((double)KettleDuty);
|
||||||
|
SettingChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a character array to represent the
|
||||||
|
// state of the kettle.
|
||||||
|
char* ShowKettleState() {
|
||||||
|
if (KettleController.Mode() == MANUAL) {
|
||||||
|
return (char*)F("Kettle: Manual");
|
||||||
|
} else if (KettleController.Mode() == AUTOMATIC) {
|
||||||
|
return (char*)F("Kettle: Auto");
|
||||||
|
} else {
|
||||||
|
return (char*)F("Kettle: Off");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* ShowKettleSetting() {
|
||||||
|
static char LCD_Line[21];
|
||||||
|
char setting[4];
|
||||||
|
if (KettleController.Mode() == MANUAL) {
|
||||||
|
strcpy(LCD_Line, (char*)F("Kettle Power: "));
|
||||||
|
itoa(KettleController.Power(), setting, 10);
|
||||||
|
strcat(LCD_Line, setting);
|
||||||
|
strcat(LCD_Line, (char*)F("%"));
|
||||||
|
|
||||||
|
return LCD_Line;
|
||||||
|
} else if (KettleController.Mode() == AUTOMATIC) {
|
||||||
|
strcpy(LCD_Line, (char*)F("Kettle Temp: "));
|
||||||
|
itoa(KettleController.Setpoint(), setting, 10);
|
||||||
|
strcat(LCD_Line, setting);
|
||||||
|
strcat(LCD_Line, (char*)F("F"));
|
||||||
|
return LCD_Line;
|
||||||
|
} else {
|
||||||
|
return (char*)"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateBoilKettle(){
|
||||||
|
|
||||||
|
|
||||||
|
if (Enter.pressed()) {
|
||||||
|
KettleController.CycleMode();
|
||||||
|
SettingChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SettingChanged) {
|
||||||
|
menu.update();
|
||||||
|
SettingChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (KettleController.Mode() != OFF) {
|
||||||
|
if (KettleController.Compute()) KettleDuty = KettleController.Power();
|
||||||
|
digitalWrite(O_PWM, boilPWM.compute(KettleDuty));
|
||||||
|
} else {
|
||||||
|
digitalWrite(O_PWM, boilPWM.compute(0));
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
#include "../config.h"
|
||||||
|
#include "../globals.h"
|
||||||
|
|
||||||
void ConnectMQTT() {
|
void ConnectMQTT() {
|
||||||
ConfigData config;
|
ConfigData config;
|
Loading…
Reference in New Issue
Block a user