From f70042287862ecda937320843e5a105ecd277f2f Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Mon, 19 Sep 2016 00:02:16 +1000 Subject: [PATCH] Filling out more of the mode change logic --- workspace/ts100/inc/Modes.h | 28 +++++++---- workspace/ts100/src/Main.c | 2 +- workspace/ts100/src/Modes.c | 96 +++++++++++++++++++++++++++++++++++-- 3 files changed, 112 insertions(+), 14 deletions(-) diff --git a/workspace/ts100/inc/Modes.h b/workspace/ts100/inc/Modes.h index 43495650..e167d954 100644 --- a/workspace/ts100/inc/Modes.h +++ b/workspace/ts100/inc/Modes.h @@ -9,18 +9,26 @@ #define MODES_H_ #include "CTRL.h" #include "Hardware.h" -enum -{ -STARTUP,//we are sitting on the prompt to push a button -SOLDERING, -TEMP_ADJ, -SETTINGS, +#include "Interrupt.h" +#include "Oled.h" +uint32_t LastButtonPushTime; +uint32_t LastMovementTime; +enum { + STARTUP, //we are sitting on the prompt to push a button + SOLDERING, + TEMP_ADJ, + SETTINGS, + SLEEP, } operatingMode; enum { - UVLO, - SLEEP_TEMP, - SLEEP_TIME, + UVLO = 0, SLEEP_TEMP, SLEEP_TIME, -}settingsPage; +} settingsPage; +struct { + uint32_t SolderingTemp; //current setpoint for the iron + uint8_t SleepTime; //minutes to sleep + uint32_t SleepTemp; //temp to drop to in sleep + uint8_t cutoutVoltage; //X10 the voltage we cutout at for undervoltage +} systemSettings; #endif /* MODES_H_ */ diff --git a/workspace/ts100/src/Main.c b/workspace/ts100/src/Main.c index cff767f5..57ad2455 100644 --- a/workspace/ts100/src/Main.c +++ b/workspace/ts100/src/Main.c @@ -46,7 +46,7 @@ int main(void) { for (;;) { - OLED_DrawTwoNumber((millis() / 100) % 100, 0); + OLED_DrawTwoNumber((millis() / 100) % 100, (millis()/100)%80); } Start_Watchdog(3000); //start the system watchdog as 3 seconds diff --git a/workspace/ts100/src/Modes.c b/workspace/ts100/src/Modes.c index 21d07161..0302bb59 100644 --- a/workspace/ts100/src/Modes.c +++ b/workspace/ts100/src/Modes.c @@ -2,12 +2,16 @@ * Modes.c * * Created on: 17 Sep 2016 - * Author: Ralim + * Author: Ralim */ #include "Modes.h" //This does the required processing and state changes void ProcessUI() { uint8_t Buttons = Get_gKey(); //read the buttons status + + if (millis() - LastButtonPushTime < 50) //rough prevention for debouncing + Buttons = 0; + switch (operatingMode) { case STARTUP: if (Buttons & KEY_A) { @@ -16,17 +20,83 @@ void ProcessUI() { } else if (Buttons & KEY_B) { //B Button was pressed so we are moving to the Settings menu operatingMode = SETTINGS; - } else { - //no buttons pressed so we sit tight } + //Nothing else to check here break; case SOLDERING: //We need to check the buttons if we need to jump out + if (Buttons & KEY_A) { + //A key pressed so we are moving to temp set + operatingMode = TEMP_ADJ; + } else if (Buttons & KEY_B) { + //B Button was pressed so we are moving back to idle + operatingMode = STARTUP; + } else { + //We need to check the timer for movement in case we need to goto idle + if (millis() - LastMovementTime > (systemSettings.SleepTime * 60000) + && millis() - LastMovementTime + > (systemSettings.SleepTime * 60000)) { + operatingMode = SLEEP; //Goto Sleep Mode + return; + } + //If no buttons pushed we need to read the current temperatures + // and then setup the drive signal time for the iron + } break; case TEMP_ADJ: + if (Buttons & KEY_A) { + //A key pressed so we are moving down in temp + } else if (Buttons & KEY_B) { + //B key pressed so we are moving up in temp + + } else { + //we check the timeout for how long the buttons have not been pushed + //if idle for > 3 seconds then we return to soldering + if (millis() - LastButtonPushTime > 3000) + operatingMode = SOLDERING; + } break; case SETTINGS: + //Settings is the mode with the most logic + //Here we are in the menu so we need to increment through the sub menus / increase the value + if (Buttons & KEY_A) { + //A key iterates through the menu + if (settingsPage == 2) { + //Roll off the end + settingsPage = 0; //reset + operatingMode = STARTUP; + //TODO Save settings + } else + ++settingsPage; //move to the next option + } else if (Buttons & KEY_B) { + //B changes the value selected + switch (settingsPage) { + case UVLO: + //we are incrementing the cutout voltage + systemSettings.cutoutVoltage += 5; //Go up 0.5V at a jump + if (systemSettings.cutoutVoltage < 90) + systemSettings.cutoutVoltage = 90; //cant set UVLO below 9V + break; + case SLEEP_TEMP: + systemSettings.SleepTemp += 10; //Go up 10c at a time + if (systemSettings.SleepTemp > 300) + systemSettings.SleepTemp = 100; //cant sleep higher than 300 + break; + case SLEEP_TIME: + ++systemSettings.SleepTime; //Go up 1 minute at a time + if (systemSettings.SleepTime > 60) + systemSettings.SleepTime = 2; //cant set time over an hour + //Remember that ^ is the time of no movement + break; + default: + break; + } + } + break; + case SLEEP: + //The iron is sleeping at a lower temperature due to lack of movement + break; default: break; @@ -36,12 +106,32 @@ void ProcessUI() { void DrawUI() { switch (operatingMode) { case STARTUP: + //We are chilling in the idle mode + //Check if movement in the last 5 minutes , if not sleep OLED + if (millis() - LastMovementTime > (5 * 60 * 1000)) { + //OLED off + Oled_DisplayOff(); + } else { + Oled_DisplayOn(); + OLED_DrawString("IDLE ", 0); //write the word IDLE + } break; case SOLDERING: + //The user is soldering + //We draw in the current system temp and an indicator if the iron is heating or not + break; case TEMP_ADJ: + //We are prompting the user to change the temp so we draw the current setpoint temp + //With the nifty arrows break; case SETTINGS: + //We are prompting the user the setting name + break; + case SLEEP: + //The iron is in sleep temp mode + //Draw in temp and sleep + break; default: break;