Skip to content

Commit

Permalink
Añadido inputs desde serial
Browse files Browse the repository at this point in the history
Revisado timer_control
Mejoras en logs
  • Loading branch information
surfzone-org committed Aug 20, 2022
1 parent e02539c commit 1e352bf
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 20 deletions.
3 changes: 2 additions & 1 deletion include/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ float c3 = 0.00006146459005e-7; // COEFFICIENT C NTC 25/50 Beta3950 100KOhms
//===========================================

// #define BOARD_TEST // IF ACTIVATED, BOARD IN TEST MODE (DESACTIVATE DEFAULT)
// #define DEBUG_LOG // IF ACTIVATED, SERIAL.PRINT FOR DEBUGING
// #define DEBUG_LOG // IF ACTIVATED, SERIAL.PRINT FOR DEBUGING
// #define DEBUG_LOG_HW // IF ACTIVATED, SERIAL.PRINT FOR DEBUGING
2 changes: 1 addition & 1 deletion include/global_vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bool pin_res[] = { // Si queremos activo con high (true) o low (false)
};

byte current_inputs = 0;
bool input_change = false;

bool is_input_active(byte inputs, byte sensor){
return ((inputs & (1 << sensor)) != 0);
Expand All @@ -39,7 +40,6 @@ bool is_input_active(byte inputs, byte sensor){
bool temp_change = false;
bool temp_change_primary = false;
bool temp_change_secondary = false;
bool input_change = false;

volatile bool zero_crossing_detected = false;
bool zero_crossing_active = false;
Expand Down
2 changes: 1 addition & 1 deletion include/hardware/fan_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void set_fan(unsigned int vel) {
Serial.print("/");
Serial.print((int)PWM_RATE-1);
Serial.print(" - ");
Serial.print((int)((vel*100)/(PWM_RATE-1));
Serial.print((int)((vel*100)/(PWM_RATE-1)));
Serial.println("%");
#endif
}
Expand Down
5 changes: 5 additions & 0 deletions include/hardware/lcdserial_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ void screen_info(String msg){
}

void screen_resistances(byte resist){
Serial.print("Monitor ");
Serial.print("Resist");
Serial.print(": ");
Serial.println(resist);
}

void screen_current_temp(int temp){
Serial.print("Monitor ");
Serial.print(RESSTR_CURR_TEMP);
Serial.print(": ");
Serial.println(temp);
}

void screen_prog_temp(int temp){
Serial.print("Monitor ");
Serial.print(RESSTR_PROG_TEMP);
Serial.print(": ");
Serial.println(temp);
Expand Down
2 changes: 1 addition & 1 deletion include/hardware/light_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ void set_lights(bool active) {
digitalWrite(PIN_LIGHT_CHAMBER, active == true ? HIGH : LOW);
#ifdef DEBUG_LOG
Serial.print("Light: ");
Serial.println((String)(active ? "ON" : "OFF");
Serial.println((String)(active ? "ON" : "OFF"));
#endif
}
4 changes: 2 additions & 2 deletions include/hardware/temperature_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void read_temperature_primary(){
// TODO: Buscar según tabla
int temp_primary_sensor = read_temperature_map(raw_primary_sensor, &prog_eeprom_actual); // read_temperature(raw_primary_sensor, RESISTANCE_PRIMARY_SENSOR);

#ifdef DEBUG_LOG
#ifdef DEBUG_LOG_HW
Serial.print("Sensor A1: ");
Serial.print(temp_primary_sensor);
Serial.print(" Raw: ");
Expand All @@ -30,7 +30,7 @@ void read_temperature_secondary(){
//int temp_secondary_sensor = read_temperature(raw_secondary_sensor, RESISTANCE_SECONDARY_SENSOR, c1, c2, c3, PULLUP_SECONDARY == 1);
int temp_secondary_sensor = read_temperature_beta(raw_secondary_sensor, RESISTANCE_SECONDARY_SENSOR, THERMISTOR_SECONDARY_RESIST,
THERMISTOR_SECONDARY_TEMP, THERMISTOR_SECONDARY_BETA, PULLUP_SECONDARY == 1);
#ifdef DEBUG_LOG
#ifdef DEBUG_LOG_HW
Serial.print("Sensor A2: ");
Serial.print(temp_secondary_sensor);
Serial.print(" Raw: ");
Expand Down
14 changes: 14 additions & 0 deletions include/hardware/usb_serial_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ void serial_print(String msg){

void serial_println(String msg){
Serial.println(msg);
}

void serial_input(){
if (Serial.available()) {
byte c = Serial.read();
if(c >= '0' && c < '6'){
if (c == '0') current_inputs = 0;
else {
c -= '1';
current_inputs = 1 << c;
}
input_change = true;
}
}
}
13 changes: 11 additions & 2 deletions include/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#endif

#if defined SCREEN_CONTROL
#ifdef SCREEN_SERIAL
#include <hardware/lcdserial_control.h>
#endif
#if defined LCD_1602_I2C
#include <hardware/lcd1602_control.h>
#endif
Expand All @@ -60,11 +63,17 @@
// HARDWARE INCLUDES: =
//======================================

#include <hardware/inputs_control.h>
#if defined DUMMY_SENSORS
#include <test/inputs_control.h>
#include <test/temperature_control.h>
#else
#include <hardware/inputs_control.h>
#include <hardware/temperature_control.h>
#endif

#include <hardware/resistance_control.h>
#include <hardware/zero_crossing_control.h>
#include <hardware/dimmer_control.h>
#include <hardware/temperature_control.h>
#include <hardware/fan_control.h>
#include <hardware/light_control.h>
#include <oven_control.h>
Expand Down
70 changes: 68 additions & 2 deletions include/statemachines/cooking.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,61 @@ bool beep_on_temp = true;
byte reset_resistance_counter = 0;
byte calibrate_mode_counter = 0;

#ifdef DEBUG_LOG
void print_cooking_state_event(byte state, byte event){
Serial.print("state_machine_cooking: ");

switch(state) {
case COOKING_STATE_OFF:
Serial.print("COOKING_STATE_OFF");
break;
case COOKING_STATE_SET_TEMP:
Serial.print("COOKING_STATE_SET_TEMP");
break;
case COOKING_STATE_UNDER_TEMP:
Serial.print("COOKING_STATE_UNDER_TEMP");
break;
case COOKING_STATE_ON_TEMP:
Serial.print("COOKING_STATE_ON_TEMP");
break;
default:
Serial.print(state);
}

Serial.print(" ");

switch(event) {
case COOKING_EVENT_KEY_ENTER:
Serial.println("COOKING_EVENT_KEY_ENTER");
break;
case COOKING_EVENT_KEY_MINUS:
Serial.println("COOKING_EVENT_KEY_MINUS");
break;
case COOKING_EVENT_KEY_PLUS:
Serial.println("COOKING_EVENT_KEY_PLUS");
break;
case COOKING_EVENT_KEY_CANCEL:
Serial.println("COOKING_EVENT_KEY_CANCEL");
break;
case COOKING_EVENT_TEMP_CHANGE:
Serial.println("COOKING_EVENT_TEMP_CHANGE");
break;
case COOKING_EVENT_OPEN_DOOR:
Serial.println("COOKING_EVENT_OPEN_DOOR");
break;
case COOKING_EVENT_INACTIVE:
Serial.println("COOKING_EVENT_INACTIVE");
break;
case COOKING_EVENT_TIMER:
Serial.println("COOKING_EVENT_TIMER");
break;
default:
Serial.println(event);
}
}
#endif


void programed_temp_change(){
screen_prog_temp(programed_temp);
Serial.print(RESSTR_PROG_TEMP);
Expand Down Expand Up @@ -117,6 +172,8 @@ void state_machine_cooking_set_state(byte state){
break;

case COOKING_STATE_SET_TEMP:
screen_backlight(true);
screen_text(RESSTR_SEL_TEMP);
break;

case COOKING_STATE_UNDER_TEMP:
Expand All @@ -129,15 +186,17 @@ void state_machine_cooking_set_state(byte state){
}

void state_machine_cooking(byte event){
#ifdef DEBUG_LOG
print_cooking_state_event(cooking_state, event);
#endif

switch(cooking_state) {
case COOKING_STATE_OFF:
switch(event) {
case COOKING_EVENT_KEY_ENTER:
case COOKING_EVENT_KEY_MINUS:
case COOKING_EVENT_KEY_PLUS:
case COOKING_EVENT_KEY_CANCEL:
screen_backlight(true);
screen_text(RESSTR_SEL_TEMP);
start_timer_inactive(TIMER_INACTIVE);
state_machine_cooking_set_state(COOKING_STATE_SET_TEMP);
break;
Expand Down Expand Up @@ -291,6 +350,13 @@ void state_machine_cooking(byte event){
}

void inputs_change_cooking(byte inputs){
#ifdef DEBUG_LOG
Serial.print("Cooking input: ");
Serial.print(inputs);
Serial.print(" ");
Serial.println(last_input_cooking);
#endif

if (is_input_active(inputs, KEY_ENTER) && !is_input_active(last_input_cooking, KEY_ENTER))
state_machine_cooking(COOKING_EVENT_KEY_ENTER);

Expand Down
17 changes: 17 additions & 0 deletions include/test/inputs_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/***************************************************************
openELECTRO
Home appliance control, based on arduino and other MPU
https://github.com/carlymx/openELECTRO
[email protected], [email protected]
2022
***************************************************************/

void read_inputs() {
byte new_inputs = current_inputs;

if (new_inputs != current_inputs) {
current_inputs = new_inputs;
input_change = true;
}
}
16 changes: 9 additions & 7 deletions include/test/temperature_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

// DUMMY MODE

void read_temperature_primary() {
void read_temperature_primary() {
int temp_primary_sensor = current_temp_primary;
if (resistance_active == true) temp_primary_sensor += 5;
else temp_primary_sensor -= 4;

Expand All @@ -18,7 +19,7 @@ void read_temperature_primary() {
// TODO: Usar el raw tambien (o usar solo el raw y obtener de tabla)
// raw_primary_sensor = xxxxx;

#ifdef DEBUG_LOG
#ifdef DEBUG_LOG_HW
Serial.print("Sensor A1 DUMMY: ");
Serial.print(temp_primary_sensor);
Serial.print(" Raw: ");
Expand All @@ -31,7 +32,8 @@ void read_temperature_primary() {
}
}

void read_temperature_secundary(){
void read_temperature_secondary(){
int temp_secondary_sensor = current_temp_secondary;
// TODO: Usar el raw tambien
if (resistance_active == true) temp_secondary_sensor += 5;
else temp_secondary_sensor -= 4;
Expand All @@ -41,15 +43,15 @@ void read_temperature_secundary(){
// TODO: Usar el raw tambien (o usar solo el raw y obtener de tabla)
// raw_secondary_sensor = xxxxx;

#ifdef DEBUG_LOG
#ifdef DEBUG_LOG_HW
Serial.print("Sensor A2 DUMMY: ");
Serial.print(temp_secondary_sensor);
Serial.print(" Raw: ");
Serial.println(raw_secondary_sensor);
#endif

if (temp_secondary_sensor != temp_secondary_sensor){
temp_secondary_sensor = temp_secondary_sensor;
temp_secondary_sensor = true;
if (current_temp_secondary != temp_secondary_sensor){
current_temp_secondary = temp_secondary_sensor;
temp_change_secondary = true;
}
}
20 changes: 17 additions & 3 deletions include/timer_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@
2022
***************************************************************/

unsigned int timer_inactive = 0;
unsigned long timer_inactive = 0;
bool timer_inactive_timeout = false;

void timers_verify(){
timer_inactive_timeout = (timer_inactive > 0) && (timer_inactive < millis());

if(timer_inactive_timeout == true) timer_inactive = 0;
if(timer_inactive_timeout == true) {
#ifdef DEBUG_LOG
Serial.print("Timeout! ");
Serial.print(timer_inactive);
Serial.print(" ");
Serial.println(millis());
#endif
timer_inactive = 0;
}
}

void start_timer_inactive(unsigned int ms){
void start_timer_inactive(unsigned long ms){
timer_inactive = ms == 0 ? 0 : ms + millis();
#ifdef DEBUG_LOG
Serial.print("Timer: ");
Serial.print(timer_inactive);
Serial.print(" ");
Serial.println(millis());
#endif
}
7 changes: 7 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ framework = arduino
build_flags = -D LGT8F328P -D ARDUINO_BOARDS
lib_deps = marcoschwartz/LiquidCrystal_I2C @ ^1.1.4

[env:LGT8F328P Test]
platform = lgt8f
board = LGT8F328P
board_build.f_cpu = 32000000L
framework = arduino
build_flags = -D LGT8F328P -D ARDUINO_BOARDS -D DEBUG_LOG -D DUMMY_SENSORS -D SERIAL_SCREEN
lib_deps = marcoschwartz/LiquidCrystal_I2C @ ^1.1.4

[env:Micro-Atmega32u4]
platform = atmelavr
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void loop() {
// ULTRAFAST TIMER ACTIONS:
if (ufast_click == true){
read_inputs();
serial_input();
}
// FAST TIMER ACTIONS:
if (fast_click == true){
Expand Down
Loading

0 comments on commit 1e352bf

Please sign in to comment.