From 02e91af8267306a33a360375eae967d322207913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Wed, 3 Oct 2012 02:29:05 +0200 Subject: [PATCH] sync to home --- reflowctl/reflowctl.ino | 104 +++++++++++++++++++++++----------------- serialmon.py | 9 +++- 2 files changed, 66 insertions(+), 47 deletions(-) diff --git a/reflowctl/reflowctl.ino b/reflowctl/reflowctl.ino index c086c86..88a6ffb 100644 --- a/reflowctl/reflowctl.ino +++ b/reflowctl/reflowctl.ino @@ -14,6 +14,7 @@ #define E_RAMPDOWN_TOO_FAST 2 // oven cools down too fast #define E_RAMPDOWN_TOO_SLOW 3 // oven cools down too slow #define E_TIME_MAX 4 // reflow process does take too long +#define E_PEAK_TOO_LONG 5 // package was roasted unsigned int time = 0; // profile seconds unsigned int temperatur = 25; // actual oven temp @@ -36,13 +37,15 @@ unsigned int Ts_max_time = 0; unsigned int Tl_time = 0; unsigned int Tl_time_end = 0; unsigned int Tp_time = 0; +unsigned int Tp_time_end = 0; unsigned int Tl_end_time = 0; unsigned int error_condition = 0; byte state = START_STATE; +int analogPin = 2; + void setup() { - pinMode(13, OUTPUT); Serial.begin(9600); } @@ -87,50 +90,61 @@ boolean check_tal_duration() { } } -void loop() { - time = millis() / 1000; - get_temp(); - Serial.print(time); - Serial.print(" "); - Serial.print(temperatur); - Serial.print(" "); - Serial.println(last_temperatur); - switch (state) { - case START_STATE: - // going from room temp to preheat, nothing to check here - if (!check_rampup_rate()) - goto error; - if (temperatur > Ts_min) { - Serial.println("Changed state to PREHEAT_STATE"); - Ts_min_time = time; - state++; - } - case PREHEAT_STATE: - if (temperatur > Ts_max) { - Serial.println("Changed state to PREHEAT_STATE"); - Ts_max_time = time; - state++; - } - break; - case TAL_FIRST_STATE: - break; - case PEAK_STATE: - break; - case TAL_SECOND_STATE: - break; - case RAMPDOWN_STATE: - break; - case END_STATE: - default: - break; +boolean check_peak_duration() { + if (Tp_time_end - Tp_time > peak_duration) { + error_condition = E_PEAK_TOO_LONG; + return false; } - - delay(1000); - - return; - -error: - state = END_STATE; - Serial.println(error_condition); +} + + +void loop() { +// time = millis() / 1000; +// get_temp(); +// Serial.print(time); +// Serial.print(" "); +// Serial.print(temperatur); +// Serial.print(" "); +// Serial.println(last_temperatur); + + Serial.println(analogRead(analogPin)); + +// switch (state) { +// case START_STATE: +// // going from room temp to preheat, nothing to check here +// if (!check_rampup_rate()) +// goto error; +// if (temperatur > Ts_min) { +// Serial.println("Changed state to PREHEAT_STATE"); +// Ts_min_time = time; +// state++; +// } +// case PREHEAT_STATE: +// if (temperatur > Ts_max) { +// Serial.println("Changed state to PREHEAT_STATE"); +// Ts_max_time = time; +// state++; +// } +// break; +// case TAL_FIRST_STATE: +// break; +// case PEAK_STATE: +// break; +// case TAL_SECOND_STATE: +// break; +// case RAMPDOWN_STATE: +// break; +// case END_STATE: +// default: +// break; +// } +// + delay(1000); +// +// return; +// +// error: +// state = END_STATE; +// Serial.println(error_condition); } diff --git a/serialmon.py b/serialmon.py index efa7a1e..8302143 100755 --- a/serialmon.py +++ b/serialmon.py @@ -1,6 +1,11 @@ #!/usr/bin/python import serial -ser = serial.Serial('/dev/ttyUSB0', 9600) + while 1: - print ser.readline() + try: + ser = serial.Serial('/dev/ttyUSB0', 9600) + while 1: + print ser.readline() + except Exception, e: + pass