Changeset - 169432b428c7
[Not reviewed]
default
0 1 0
Ethan Zonca - 10 years ago 2014-09-14 19:32:39
ez@ethanzonca.com
Added slowdown for value incrementing
1 file changed with 44 insertions and 48 deletions:
main.c
44
48
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -29,6 +29,16 @@ uint16_t k_p = 1;
 
uint16_t k_i = 1;
 
uint16_t k_d = 1;
 
 
// ISR ticks var TODO: Double check functionality after volatilazation... needed on ARM?
 
volatile uint32_t ticks = 0;
 
 
// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow...
 
uint32_t change_time_reset = 0;
 
#define CHANGE_PERIOD_MS 100
 
#define CHANGE_ELAPSED (ticks - change_time_reset) > CHANGE_PERIOD_MS
 
#define CHANGE_RESET change_time_reset = ticks
 
 
 
int16_t setpoint_brew = 0;
 
int16_t setpoint_steam = 0;
 
 
@@ -215,7 +225,6 @@ int16_t update_pid(uint16_t k_p, uint16_
 
 
 
 
uint32_t ticks = 0;
 
uint32_t last_ssr_on = 0;
 
uint32_t last_led = 0;
 
int32_t setpoint = 0;
 
@@ -365,6 +374,24 @@ void restore_settings()
 
    DATA_EEPROM_Lock();
 
}
 
 
void user_input(uint16_t* to_modify)
 
{
 
    if(CHANGE_ELAPSED) {
 
 
        // TODO: Make function that takes reference to a var and increase/decreases it based on buttonpress
 
        if(!GPIO_ReadInputDataBit(SW_UP) ) {
 
            CHANGE_RESET;
 
            (*to_modify)++;
 
        }
 
        else if(!GPIO_ReadInputDataBit(SW_DOWN) && (*to_modify) > 0) {
 
            CHANGE_RESET;
 
            (*to_modify)--;
 
        }
 
 
    }
 
 
}
 
 
void machine()
 
{
 
    uint8_t last_state = state;
 
@@ -459,11 +486,8 @@ void machine()
 
            if(SW_BTN_PRESSED) {
 
                state = STATE_SETI;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
                k_p++;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_p > 0) {
 
                k_p--;
 
            else {
 
                user_input(&k_p);
 
            }
 
 
            // Event Handler
 
@@ -491,13 +515,9 @@ void machine()
 
            if(SW_BTN_PRESSED) {
 
                state = STATE_SETD;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
                k_i++;
 
            else {
 
                user_input(&k_i);
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_i > 0) {
 
                k_i--;
 
            }
 
 
 
            // Event Handler
 
            // N/A
 
@@ -524,11 +544,8 @@ void machine()
 
            if(SW_BTN_PRESSED) {
 
                state = STATE_SETWINDUP;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
                k_d++;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && k_d > 0) {
 
                k_d--;
 
            else {
 
                user_input(&k_d);
 
            }
 
 
            // Event Handler
 
@@ -556,11 +573,8 @@ void machine()
 
            if(SW_BTN_PRESSED) {
 
                state = STATE_SETBOOTTOBREW;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
                windup_guard++;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && windup_guard > 0) {
 
                windup_guard--;
 
            else {
 
                user_input(&windup_guard);
 
            }
 
 
            // Event Handler
 
@@ -602,9 +616,6 @@ void machine()
 
 
 
        } break;
 
 
 
 
 
        case STATE_PREHEAT_BREW:
 
        {
 
            // Write text to OLED
 
@@ -621,13 +632,9 @@ void machine()
 
		save_setpoints(); // TODO: Check for mod
 
                state = STATE_IDLE;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
               setpoint_brew++; 
 
            else {
 
                user_input(&setpoint_brew);
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint_brew > 0) {
 
                setpoint_brew--;
 
            }
 
 
 
            // Event Handler
 
            if(temp >= setpoint) {
 
@@ -652,13 +659,9 @@ void machine()
 
		save_setpoints(); // TODO: Check for mod
 
                state = STATE_IDLE;
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
               setpoint_brew++; 
 
            else {
 
                user_input(&setpoint_brew);
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint_brew > 0) {
 
                setpoint_brew--;
 
            }
 
 
 
            // Event Handler
 
            // N/A
 
@@ -681,11 +684,8 @@ void machine()
 
                state = STATE_IDLE;
 
		save_setpoints(); // TODO: Check for mod
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
               setpoint_steam++; 
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint_steam > 0) {
 
                setpoint_steam--;
 
            else {
 
                user_input(&setpoint_steam);
 
            }
 
 
            // Event Handler
 
@@ -711,13 +711,9 @@ void machine()
 
                state = STATE_IDLE;
 
		save_setpoints(); // TODO: Check for mod
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_UP)) {
 
               setpoint_steam++; 
 
            else {
 
                user_input(&setpoint_steam);
 
            }
 
            else if(!GPIO_ReadInputDataBit(SW_DOWN) && setpoint_steam > 0) {
 
                setpoint_steam--;
 
            }
 
 
 
            // Event Handler
 
            // N/A
0 comments (0 inline, 0 general)