Code reformatted
Constants for pump times in main.h (more readable code, easier to adjust) git-svn-id: https://svn.404-net.de/repos/senseoControl/trunk@9 e16d0e86-71da-4a9f-96c8-a2496b660ed8
This commit is contained in:
parent
8bc37cee7d
commit
db8dbb52e0
222
main.c
222
main.c
@ -21,7 +21,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
// variables
|
// variables:
|
||||||
volatile unsigned int time_counter, user_time_counter = 0, sec_counter = 0; // global and universal time counter (ms) and second-counter (for AutoOff)
|
volatile unsigned int time_counter, user_time_counter = 0, sec_counter = 0; // global and universal time counter (ms) and second-counter (for AutoOff)
|
||||||
volatile unsigned int button_1_cup_counter = 0, button_2_cup_counter = 0; // button counter
|
volatile unsigned int button_1_cup_counter = 0, button_2_cup_counter = 0; // button counter
|
||||||
volatile unsigned char button_power_counter = 0;
|
volatile unsigned char button_power_counter = 0;
|
||||||
@ -29,94 +29,103 @@ volatile unsigned char led = 0; // LED status flags
|
|||||||
volatile bool water = false, temperature = false, make_clean = false; // water-, temperature-, clean-flags
|
volatile bool water = false, temperature = false, make_clean = false; // water-, temperature-, clean-flags
|
||||||
volatile unsigned char make_coffee = 0, pump_time = 0; // pump time, clean mode flag
|
volatile unsigned char make_coffee = 0, pump_time = 0; // pump time, clean mode flag
|
||||||
|
|
||||||
int main(void)
|
int main (void)
|
||||||
{
|
{
|
||||||
init(); // initialization
|
init (); // initialization
|
||||||
power_off(); // power off after init sequece
|
power_off (); // power off after init sequece
|
||||||
|
|
||||||
while (1) // main loop
|
while (1) // main loop
|
||||||
{
|
{
|
||||||
if (sec_counter >= AUTO_OFF_THRESHOLD) button_power_counter = BUTTON_THRESHOLD; // check for AutoOff Timer (generate OnOff-button push)
|
if (sec_counter >= AUTO_OFF_THRESHOLD)
|
||||||
|
button_power_counter = BUTTON_THRESHOLD; // check for AutoOff Timer (generate OnOff-button push)
|
||||||
|
|
||||||
water = get_water(); // update water state
|
water = get_water (); // update water state
|
||||||
temperature = get_temperature(); // update temperature
|
temperature = get_temperature (); // update temperature
|
||||||
|
|
||||||
if (button_power_counter >= BUTTON_THRESHOLD) // button "OnOff" pushed:
|
if (button_power_counter >= BUTTON_THRESHOLD) // button "OnOff" pushed:
|
||||||
{
|
{
|
||||||
set_bit(TRIAC_BOILER_w, TRIAC_BOILER_pin); // Boiler off
|
set_bit(TRIAC_BOILER_w, TRIAC_BOILER_pin); // Boiler off
|
||||||
make_coffee = 0; // clear coffee flag
|
make_coffee = 0; // clear coffee flag
|
||||||
|
|
||||||
while (button_power_counter > 0); // wait until button is releasd (debounce)
|
while (button_power_counter > 0)
|
||||||
|
; // wait until button is releasd (debounce)
|
||||||
|
|
||||||
power_off(); // call power off sequence
|
power_off (); // call power off sequence
|
||||||
|
|
||||||
button_power_counter = BUTTON_THRESHOLD; // debounce again after wake up
|
button_power_counter = BUTTON_THRESHOLD; // debounce again after wake up
|
||||||
while (button_power_counter > 0);
|
while (button_power_counter > 0)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (button_1_cup_counter >= BUTTON_CLEAN_THR
|
||||||
if (button_1_cup_counter >= BUTTON_CLEAN_THR && button_2_cup_counter >= BUTTON_CLEAN_THR ) // both coffee buttons pushed: clean mode:
|
&& button_2_cup_counter >= BUTTON_CLEAN_THR) // both coffee buttons pushed: clean mode:
|
||||||
{
|
{
|
||||||
make_clean = true; // clean flag true
|
make_clean = true; // clean flag true
|
||||||
led = 0b00010000; // set blue LED
|
led = 0b00010000; // set blue LED
|
||||||
while (button_1_cup_counter > 0 && button_2_cup_counter > 0); // debounce buttons
|
while (button_1_cup_counter > 0 && button_2_cup_counter > 0)
|
||||||
|
; // debounce buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (button_1_cup_counter >= BUTTON_THRESHOLD && button_2_cup_counter < BUTTON_THRESHOLD) // left coffee button pushed: call espresso
|
else if (button_1_cup_counter >= BUTTON_THRESHOLD
|
||||||
|
&& button_2_cup_counter < BUTTON_THRESHOLD) // left coffee button pushed: call espresso
|
||||||
{
|
{
|
||||||
sec_counter = 0; // reset AutoOff counter
|
sec_counter = 0; // reset AutoOff counter
|
||||||
|
|
||||||
if (water && temperature) // machine ready:
|
if (water && temperature) // machine ready:
|
||||||
{
|
{
|
||||||
while(button_1_cup_counter > 0) // check if button is pushed long time
|
while (button_1_cup_counter > 0) // check if button is pushed long time
|
||||||
{
|
{
|
||||||
if(button_1_cup_counter > BUTTON_LONG_THR) // button pushed for a long time:
|
if (button_1_cup_counter > BUTTON_LONG_THR) // button pushed for a long time:
|
||||||
{
|
{
|
||||||
make_coffee = 1; // set coffee flag to 1 (1 espresso)
|
make_coffee = 1; // set coffee flag to 1 (1 espresso)
|
||||||
button_1_cup_counter = 0; // clear button counter
|
button_1_cup_counter = 0; // clear button counter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(make_coffee != 1) make_coffee = 3; // set coffee flag to 3 (1 coffee) else
|
if (make_coffee != 1)
|
||||||
|
make_coffee = 3; // set coffee flag to 3 (1 coffee) else
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (button_1_cup_counter < BUTTON_THRESHOLD
|
||||||
else if (button_1_cup_counter < BUTTON_THRESHOLD && button_2_cup_counter >= BUTTON_THRESHOLD) // right coffee button pushed: call coffee
|
&& button_2_cup_counter >= BUTTON_THRESHOLD) // right coffee button pushed: call coffee
|
||||||
{
|
{
|
||||||
sec_counter = 0; // reset AutoOff counter
|
sec_counter = 0; // reset AutoOff counter
|
||||||
|
|
||||||
if (water && temperature) // machine ready:
|
if (water && temperature) // machine ready:
|
||||||
{
|
{
|
||||||
while(button_2_cup_counter > 0) // check if button is pushed long time
|
while (button_2_cup_counter > 0) // check if button is pushed long time
|
||||||
{
|
{
|
||||||
if(button_2_cup_counter > BUTTON_LONG_THR) // button pushed for a long time:
|
if (button_2_cup_counter > BUTTON_LONG_THR) // button pushed for a long time:
|
||||||
{
|
{
|
||||||
make_coffee = 2; // set coffee flag to 2 (2 espresso)
|
make_coffee = 2; // set coffee flag to 2 (2 espresso)
|
||||||
button_2_cup_counter = 0; // clear button counter
|
button_2_cup_counter = 0; // clear button counter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(make_coffee != 2) make_coffee = 4; // set coffee flag to 4 (2 coffee) else
|
if (make_coffee != 2)
|
||||||
|
make_coffee = 4; // set coffee flag to 4 (2 coffee) else
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (water) // water OK:
|
if (water) // water OK:
|
||||||
{
|
{
|
||||||
if(make_clean) // if clean-flag is set:
|
if (make_clean) // if clean-flag is set:
|
||||||
{
|
{
|
||||||
set_bit(TRIAC_BOILER_w, TRIAC_BOILER_pin); // boiler off
|
set_bit(TRIAC_BOILER_w, TRIAC_BOILER_pin); // boiler off
|
||||||
bool escape = false; // init escape-flag
|
bool escape = false; // init escape-flag
|
||||||
while (water && !escape) { // pump until water is empty or escape flag is set
|
while (water && !escape)
|
||||||
|
{ // pump until water is empty or escape flag is set
|
||||||
|
|
||||||
unsigned int sense = detect_zero_crossing(); // detect zero crossing
|
unsigned int sense = detect_zero_crossing (); // detect zero crossing
|
||||||
if (sense <= 100) {
|
if (sense <= 100)
|
||||||
|
{
|
||||||
clear_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin); // generate trigger impulse for pump triac
|
clear_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin); // generate trigger impulse for pump triac
|
||||||
_delay_ms(3);
|
_delay_ms (3);
|
||||||
set_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin);
|
set_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin);
|
||||||
}
|
}
|
||||||
water = get_water(); // update water state
|
water = get_water (); // update water state
|
||||||
|
|
||||||
if (button_power_counter > BUTTON_THRESHOLD) escape = true; // check for power button counter and set escape flag
|
if (button_power_counter > BUTTON_THRESHOLD)
|
||||||
|
escape = true; // check for power button counter and set escape flag
|
||||||
}
|
}
|
||||||
make_clean = false; // clear clean flag
|
make_clean = false; // clear clean flag
|
||||||
}
|
}
|
||||||
@ -129,33 +138,42 @@ int main(void)
|
|||||||
|
|
||||||
if (make_coffee > 0) // if coffee flag is set:
|
if (make_coffee > 0) // if coffee flag is set:
|
||||||
{
|
{
|
||||||
if(make_coffee<3) led = 0b00001010; // set orange LED blink
|
if (make_coffee < 3)
|
||||||
else led = 0b00001000; // set green LED blink
|
led = 0b00001010; // set orange LED blink
|
||||||
|
else
|
||||||
|
led = 0b00001000; // set green LED blink
|
||||||
|
|
||||||
if (make_coffee == 1) pump_time = 15; // 1 cup of espresso (2s preinfusion included)
|
if (make_coffee == 1)
|
||||||
else if (make_coffee == 2) pump_time = 28; // 2 cups of espresso (2s preinfusion included)
|
pump_time = TIME_1_ESPRESSO; // 1 cup of espresso (2s preinfusion included)
|
||||||
else if (make_coffee == 3) pump_time = 26; // 1 cup of coffee
|
else if (make_coffee == 2)
|
||||||
else if (make_coffee == 4) pump_time = 52; // 2 cups of coffee
|
pump_time = TIME_2_ESPRESSO; // 2 cups of espresso (2s preinfusion included)
|
||||||
else make_coffee = 0;
|
else if (make_coffee == 3)
|
||||||
|
pump_time = TIME_1_COFFEE; // 1 cup of coffee
|
||||||
|
else if (make_coffee == 4)
|
||||||
|
pump_time = TIME_2_COFFEE; // 2 cups of coffee
|
||||||
|
else
|
||||||
|
make_coffee = 0;
|
||||||
|
|
||||||
user_time_counter = 0; // reset user time counter
|
user_time_counter = 0; // reset user time counter
|
||||||
bool escape = false; // init escape flag
|
bool escape = false; // init escape flag
|
||||||
while (user_time_counter < (pump_time * 1000) && water && !escape) // loop until pump time is reached or water is empty
|
while (user_time_counter < (pump_time * 1000) && water && !escape)
|
||||||
{
|
{ // loop until pump time is reached or water is empty
|
||||||
if(make_coffee > 2 ||
|
if (make_coffee > 2
|
||||||
(user_time_counter < 2000 || user_time_counter > 4000) ) { // check for preinfusion break
|
|| (user_time_counter < 2000 || user_time_counter > 4000))
|
||||||
unsigned int sense = detect_zero_crossing(); // detect zero crossing
|
{ // check for preinfusion break
|
||||||
|
unsigned int sense = detect_zero_crossing (); // detect zero crossing
|
||||||
if (sense <= 100)
|
if (sense <= 100)
|
||||||
{
|
{
|
||||||
clear_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin); // generate trigger impulse for pump triac
|
clear_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin); // generate trigger impulse for pump triac
|
||||||
_delay_ms(3);
|
_delay_ms (3);
|
||||||
set_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin);
|
set_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
water = get_water(); // update water state
|
water = get_water (); // update water state
|
||||||
|
|
||||||
if (button_power_counter > BUTTON_THRESHOLD) escape = true; // check for power button counter and set escape flag
|
if (button_power_counter > BUTTON_THRESHOLD)
|
||||||
|
escape = true; // check for power button counter and set escape flag
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin); // pump off
|
set_bit(TRIAC_PUMP_w, TRIAC_PUMP_pin); // pump off
|
||||||
@ -187,7 +205,7 @@ int main(void)
|
|||||||
*
|
*
|
||||||
* Initializes relevant bits, timer and ADC.
|
* Initializes relevant bits, timer and ADC.
|
||||||
*/
|
*/
|
||||||
void init()
|
void init ()
|
||||||
{
|
{
|
||||||
clear_bit(ZERO_CROSSING_ddr, ZERO_CROSSING_pin); // zero crossing dection pins as input
|
clear_bit(ZERO_CROSSING_ddr, ZERO_CROSSING_pin); // zero crossing dection pins as input
|
||||||
clear_bit(ZERO_CROSSING_w, ZERO_CROSSING_pin); // no internal pull-up (for ADC)
|
clear_bit(ZERO_CROSSING_w, ZERO_CROSSING_pin); // no internal pull-up (for ADC)
|
||||||
@ -226,13 +244,13 @@ void init()
|
|||||||
clear_bit(TCCR1B, CS10);
|
clear_bit(TCCR1B, CS10);
|
||||||
OCR1C = 124; // period of 1 ms
|
OCR1C = 124; // period of 1 ms
|
||||||
|
|
||||||
cli(); // disable interrupts
|
cli (); // disable interrupts
|
||||||
|
|
||||||
clear_bit(GIMSK, INT0); // disable interrupt 0
|
clear_bit(GIMSK, INT0); // disable interrupt 0
|
||||||
|
|
||||||
set_bit(TIMSK, TOIE1); // activate timer 1
|
set_bit(TIMSK, TOIE1); // activate timer 1
|
||||||
|
|
||||||
sei(); // enable interrupts
|
sei (); // enable interrupts
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function: power_off()
|
/* function: power_off()
|
||||||
@ -240,12 +258,12 @@ void init()
|
|||||||
*
|
*
|
||||||
* Clear bits and set controller to sleep mode.
|
* Clear bits and set controller to sleep mode.
|
||||||
*/
|
*/
|
||||||
void power_off()
|
void power_off ()
|
||||||
{
|
{
|
||||||
cli(); // disable interrupts
|
cli (); // disable interrupts
|
||||||
set_bit(GIMSK, INT0); // activate interrupt 0 (for wake-up)
|
set_bit(GIMSK, INT0); // activate interrupt 0 (for wake-up)
|
||||||
clear_bit(TIMSK, TOIE1); // deactivate timer 1
|
clear_bit(TIMSK, TOIE1); // deactivate timer 1
|
||||||
sei(); // enable interrupts
|
sei (); // enable interrupts
|
||||||
|
|
||||||
clear_bit(LED_RED_w, LED_RED_pin); // clear LED outputs
|
clear_bit(LED_RED_w, LED_RED_pin); // clear LED outputs
|
||||||
clear_bit(LED_GREEN_w, LED_GREEN_pin);
|
clear_bit(LED_GREEN_w, LED_GREEN_pin);
|
||||||
@ -259,26 +277,26 @@ void power_off()
|
|||||||
// entrance after wake-up:
|
// entrance after wake-up:
|
||||||
time_counter = 0; // reset counter
|
time_counter = 0; // reset counter
|
||||||
sec_counter = 0;
|
sec_counter = 0;
|
||||||
cli(); // disable interrupts
|
cli (); // disable interrupts
|
||||||
clear_bit(GIMSK, INT0); // disable interrupt 0
|
clear_bit(GIMSK, INT0); // disable interrupt 0
|
||||||
set_bit(TIMSK, TOIE1); // enable timer 1
|
set_bit(TIMSK, TOIE1); // enable timer 1
|
||||||
sei(); // enable interrupts
|
sei (); // enable interrupts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* function: get_water()
|
/* function: get_water()
|
||||||
* return: true water OK
|
* return: true water OK
|
||||||
* false not enough water
|
* false not enough water
|
||||||
*
|
*
|
||||||
* Checks hall sensor for water state.
|
* Checks hall sensor for water state.
|
||||||
*/
|
*/
|
||||||
bool get_water()
|
bool get_water ()
|
||||||
{
|
{
|
||||||
ADMUX = SENSOR_MAGNET_adc | (1 << ADLAR); // ADLAR
|
ADMUX = SENSOR_MAGNET_adc | (1 << ADLAR); // ADLAR
|
||||||
set_bit(ADCSR, ADSC);
|
set_bit(ADCSR, ADSC);
|
||||||
loop_until_bit_is_clear(ADCSR, ADSC);
|
loop_until_bit_is_clear (ADCSR, ADSC);
|
||||||
unsigned char sense = ADCH;
|
unsigned char sense = ADCH;
|
||||||
if ((water && sense > WATER_LOW) || (!water && sense >= WATER_OK)) return true;
|
if ((water && sense > WATER_LOW) || (!water && sense >= WATER_OK))
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,13 +306,14 @@ bool get_water()
|
|||||||
*
|
*
|
||||||
* Checks NTC sensor for temperature state.
|
* Checks NTC sensor for temperature state.
|
||||||
*/
|
*/
|
||||||
bool get_temperature()
|
bool get_temperature ()
|
||||||
{
|
{
|
||||||
ADMUX = SENSOR_TEMP_adc | (1 << ADLAR); // ADLAR
|
ADMUX = SENSOR_TEMP_adc | (1 << ADLAR); // ADLAR
|
||||||
set_bit(ADCSR, ADSC);
|
set_bit(ADCSR, ADSC);
|
||||||
loop_until_bit_is_clear(ADCSR, ADSC);
|
loop_until_bit_is_clear (ADCSR, ADSC);
|
||||||
unsigned char sense = ADCH;
|
unsigned char sense = ADCH;
|
||||||
if (sense >= OPERATING_TEMPERATURE) return true;
|
if (sense >= OPERATING_TEMPERATURE)
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,67 +322,90 @@ bool get_temperature()
|
|||||||
*
|
*
|
||||||
* Checks for zero crossing (with fixed offset)
|
* Checks for zero crossing (with fixed offset)
|
||||||
*/
|
*/
|
||||||
unsigned int detect_zero_crossing()
|
unsigned int detect_zero_crossing ()
|
||||||
{
|
{
|
||||||
ADMUX = ZERO_CROSSING_adc;
|
ADMUX = ZERO_CROSSING_adc;
|
||||||
set_bit(ADCSR, ADSC);
|
set_bit(ADCSR, ADSC);
|
||||||
loop_until_bit_is_clear(ADCSR, ADSC);
|
loop_until_bit_is_clear (ADCSR, ADSC);
|
||||||
unsigned char sense_L = ADCL;
|
unsigned char sense_L = ADCL;
|
||||||
unsigned char sense_H = ADCH;
|
unsigned char sense_H = ADCH;
|
||||||
return (sense_H << 8) | sense_L;
|
return (sense_H << 8) | sense_L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* interrupt function: INT0_vect
|
/* interrupt function: INT0_vect
|
||||||
*
|
*
|
||||||
* Dummy function for wake-up.
|
* Dummy function for wake-up.
|
||||||
*/
|
*/
|
||||||
ISR(INT0_vect)
|
ISR ( INT0_vect)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* interrupt function: TIMER1_OVF1_vect
|
/* interrupt function: TIMER1_OVF1_vect
|
||||||
*
|
*
|
||||||
* Timer interrupt. Increments counters and controls LED.
|
* Timer interrupt. Increments counters and controls LED.
|
||||||
*/
|
*/
|
||||||
// Millisekundenzähler, LED-Steuerung, Tastenzähler
|
ISR ( TIMER1_OVF1_vect)
|
||||||
ISR(TIMER1_OVF1_vect)
|
|
||||||
{
|
{
|
||||||
if (time_counter < 1000) time_counter++; // blobal milliseconds counter und seconds counter (für AutoOff)
|
if (time_counter < 1000)
|
||||||
else {
|
time_counter++; // global milliseconds counter and seconds counter (for AutoOff)
|
||||||
|
else
|
||||||
|
{
|
||||||
time_counter = 0;
|
time_counter = 0;
|
||||||
sec_counter++;
|
sec_counter++;
|
||||||
}
|
}
|
||||||
user_time_counter++; // universal counter (for pump time)
|
user_time_counter++; // universal counter (for pump time)
|
||||||
|
|
||||||
bool leds_blink_on; // status flag for blinking LEDs with 1Hz
|
bool leds_blink_on; // status flag for blinking LEDs with 1Hz
|
||||||
if (time_counter < 499) leds_blink_on = true;
|
if (time_counter < 499)
|
||||||
else leds_blink_on = false;
|
leds_blink_on = true;
|
||||||
|
else
|
||||||
|
leds_blink_on = false;
|
||||||
|
|
||||||
if (led & ( 1 << LED_RED_ON ) || (led & ( 1 << LED_RED_BLINK ) && leds_blink_on)) set_bit(LED_RED_w, LED_RED_pin);
|
if (led & (1 << LED_RED_ON) || (led & (1 << LED_RED_BLINK) && leds_blink_on))
|
||||||
else clear_bit(LED_RED_w, LED_RED_pin);
|
set_bit(LED_RED_w, LED_RED_pin);
|
||||||
if (led & ( 1 << LED_GREEN_ON ) || (led & ( 1 << LED_GREEN_BLINK ) && leds_blink_on)) set_bit(LED_GREEN_w, LED_GREEN_pin);
|
else
|
||||||
else clear_bit(LED_GREEN_w, LED_GREEN_pin);
|
clear_bit(LED_RED_w, LED_RED_pin);
|
||||||
if (led & ( 1 << LED_BLUE_ON ) || (led & ( 1 << LED_BLUE_BLINK ) && leds_blink_on)) set_bit(LED_BLUE_w, LED_BLUE_pin);
|
if (led & (1 << LED_GREEN_ON)
|
||||||
else clear_bit(LED_BLUE_w, LED_BLUE_pin);
|
|| (led & (1 << LED_GREEN_BLINK) && leds_blink_on))
|
||||||
|
set_bit(LED_GREEN_w, LED_GREEN_pin);
|
||||||
|
else
|
||||||
|
clear_bit(LED_GREEN_w, LED_GREEN_pin);
|
||||||
|
if (led & (1 << LED_BLUE_ON)
|
||||||
|
|| (led & (1 << LED_BLUE_BLINK) && leds_blink_on))
|
||||||
|
set_bit(LED_BLUE_w, LED_BLUE_pin);
|
||||||
|
else
|
||||||
|
clear_bit(LED_BLUE_w, LED_BLUE_pin);
|
||||||
|
|
||||||
if (bit_is_clear(BUTTON_1_CUP_r, BUTTON_1_CUP_pin)) { // left button counter
|
if (bit_is_clear (BUTTON_1_CUP_r, BUTTON_1_CUP_pin))
|
||||||
if (button_1_cup_counter < 65535) button_1_cup_counter++;
|
{ // left button counter
|
||||||
} else {
|
if (button_1_cup_counter < 65535)
|
||||||
if (button_1_cup_counter > 0) button_1_cup_counter--;
|
button_1_cup_counter++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (button_1_cup_counter > 0)
|
||||||
|
button_1_cup_counter--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bit_is_clear(BUTTON_2_CUP_r, BUTTON_2_CUP_pin)) { // right button counter
|
if (bit_is_clear (BUTTON_2_CUP_r, BUTTON_2_CUP_pin))
|
||||||
if (button_2_cup_counter < 65535) button_2_cup_counter++;
|
{ // right button counter
|
||||||
} else {
|
if (button_2_cup_counter < 65535)
|
||||||
if (button_2_cup_counter > 0) button_2_cup_counter--;
|
button_2_cup_counter++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (button_2_cup_counter > 0)
|
||||||
|
button_2_cup_counter--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bit_is_clear(BUTTON_POWER_r, BUTTON_POWER_pin)) { // power button counter
|
if (bit_is_clear (BUTTON_POWER_r, BUTTON_POWER_pin))
|
||||||
if (button_power_counter < 255) button_power_counter++;
|
{ // power button counter
|
||||||
} else {
|
if (button_power_counter < 255)
|
||||||
if (button_power_counter > 0) button_power_counter--;
|
button_power_counter++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (button_power_counter > 0)
|
||||||
|
button_power_counter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
main.h
25
main.h
@ -7,11 +7,22 @@
|
|||||||
* License: GNU GPL v3 (see License.txt)
|
* License: GNU GPL v3 (see License.txt)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*******************
|
||||||
|
* USER SETTINGS
|
||||||
|
*/
|
||||||
|
#define TIME_1_ESPRESSO 15 // pump times in seconds
|
||||||
|
#define TIME_2_ESPRESSO 28
|
||||||
|
#define TIME_1_COFFEE 26
|
||||||
|
#define TIME_2_COFFEE 52
|
||||||
|
#define OPERATING_TEMPERATURE 125 // ADC threshold for water temperature
|
||||||
|
/*
|
||||||
|
*******************
|
||||||
|
*/
|
||||||
|
|
||||||
// functions for setting and clearing bits
|
// functions for setting and clearing bits
|
||||||
#define set_bit(var, bit) ((var) |= (1 << (bit)))
|
#define set_bit(var, bit) ((var) |= (1 << (bit)))
|
||||||
#define clear_bit(var, bit) ((var) &= (unsigned)~(1 << (bit)))
|
#define clear_bit(var, bit) ((var) &= (unsigned)~(1 << (bit)))
|
||||||
|
|
||||||
|
|
||||||
#define ZERO_CROSSING_w PORTA // zero crossing detection
|
#define ZERO_CROSSING_w PORTA // zero crossing detection
|
||||||
#define ZERO_CROSSING_r PINA
|
#define ZERO_CROSSING_r PINA
|
||||||
#define ZERO_CROSSING_pin 0
|
#define ZERO_CROSSING_pin 0
|
||||||
@ -69,8 +80,6 @@
|
|||||||
#define SENSOR_TEMP_ddr DDRA
|
#define SENSOR_TEMP_ddr DDRA
|
||||||
#define SENSOR_TEMP_adc 3
|
#define SENSOR_TEMP_adc 3
|
||||||
|
|
||||||
#define OPERATING_TEMPERATURE 115 // ADC threshold for water temperature
|
|
||||||
|
|
||||||
#define TRIAC_BOILER_w PORTA // boiler triac
|
#define TRIAC_BOILER_w PORTA // boiler triac
|
||||||
#define TRIAC_BOILER_r PINA
|
#define TRIAC_BOILER_r PINA
|
||||||
#define TRIAC_BOILER_pin 6
|
#define TRIAC_BOILER_pin 6
|
||||||
@ -87,8 +96,8 @@
|
|||||||
#define BUTTON_LONG_THR 1500 // button threshold for long time push (ms)
|
#define BUTTON_LONG_THR 1500 // button threshold for long time push (ms)
|
||||||
|
|
||||||
// prototypes:
|
// prototypes:
|
||||||
void init(); // initialization
|
void init (); // initialization
|
||||||
void power_off(); // power off to sleep mode
|
void power_off (); // power off to sleep mode
|
||||||
bool get_water(); // update water state
|
bool get_water (); // update water state
|
||||||
bool get_temperature(); // update tehmerature state
|
bool get_temperature (); // update tehmerature state
|
||||||
unsigned int detect_zero_crossing(); // detect zero crossing
|
unsigned int detect_zero_crossing (); // detect zero crossing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user