more code, less void

This commit is contained in:
Stefan Kögl 2012-10-02 15:03:02 +02:00
parent f63103174a
commit cf064e6a4d
3 changed files with 92 additions and 51 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*~
build

View File

@ -808,9 +808,7 @@ function(setup_arduino_bootloader_upload TARGET_NAME BOARD_ID PORT AVRDUDE_FLAGS
endif()
list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_NAME}.hex")
message("\n")
message(${AVRDUDE_ARGS})
message("\n")
add_custom_target(${UPLOAD_TARGET}
${ARDUINO_AVRDUDE_PROGRAM}
${AVRDUDE_ARGS}

View File

@ -1,6 +1,7 @@
unsigned int time = 0; // profile seconds
unsigned int degrees = 25; // actual oven temp
unsigned int temperatur = 25; // actual oven temp
unsigned int last_temperatur = 25;
unsigned int Ts_max = 200; // °C
unsigned int Ts_min = 150; // °C
@ -13,7 +14,26 @@ unsigned int peak_duration = 30; // 20-40s
unsigned int rampdown_max = 6; // 6°C/s max
unsigned int time_max = 480; // 8*60s max
byte state; // 0 = start, 1 = preheat, 2 = tal, 3 = max, 4 = rampdown
#define START_STATE 0
#define PREHEAT_STATE 1
#define TAL_STATE 2
#define MAX_STATE 3
#define RAMPDOWN_STATE 4
#define END_STATE 5
#define ERROR_STATE 6
byte state = START_STATE;
unsigned int Ts_min_time = 0;
unsigned int Ts_max_time = 0;
unsigned int Tl_time = 0;
unsigned int Tp_time = 0;
unsigned int Tl_end_time = 0;
#define RAMPUP_TOO_FAST 1
#define RAMPDOWN_TOO_FAST 2
unsigned int error_condition = 0;
void setup() {
pinMode(13, OUTPUT);
@ -21,33 +41,54 @@ void setup() {
}
void get_temp() {
// simulating an +1K/s rampup oven
last_temperatur = ++temperatur;
}
boolean check_rampup_rate() {
if (temperatur - last_temperatur > rampup_rate) {
error_condition = RAMPUP_TOO_FAST;
return false;
}
return true;
}
void loop() {
time = millis() / 1000;
get_temp();
Serial.print(time);
Serial.print(" ");
Serial.print(temperatur);
Serial.print(" ");
Serial.println(last_temperatur);
// wait a second so as not to send massive amounts of data
delay(1000);
switch (state) {
case 0:
if (degrees > Ts_min) {
case START_STATE:
// going from room temp to preheat, nothing to check here
if (!check_rampup_rate())
goto error;
if (temperatur > Ts_min) {
state++;
}
case 1:
case PREHEAT_STATE:
if (temperatur > Ts_max)
state++;
break;
case 2:
case TAL_STATE:
break;
case 3:
case MAX_STATE:
break;
case 4:
case RAMPDOWN_STATE:
break;
default:
break;
}
if (degrees > 60) {
Serial.print("seconds: ");
Serial.println(time);
}
error:
state = END_STATE;
Serial.println(error_condition);
}