remote ctl via serialmon
This commit is contained in:
parent
7e8bd83523
commit
501ea3995e
|
@ -11,8 +11,8 @@ Profile _profile;
|
|||
OvenCtl::OvenCtl() {
|
||||
|
||||
time = 0;
|
||||
temperature = 25;
|
||||
last_temperature = 25;
|
||||
temperature = 0;
|
||||
last_temperature = 0;
|
||||
actual_dt = 0;
|
||||
// timestamps of event beginnings/ends
|
||||
Ts_time_start = 0;
|
||||
|
@ -34,19 +34,31 @@ OvenCtl::OvenCtl() {
|
|||
|
||||
// ui stuff
|
||||
led_on = false;
|
||||
disable_checks = true;
|
||||
disable_checks = false;
|
||||
lcd = &_lcd;
|
||||
keypad = &_keypad;
|
||||
profile = &_profile;
|
||||
lcd->begin(16, 2);
|
||||
}
|
||||
|
||||
void OvenCtl::reset() {
|
||||
digitalWrite(7, LOW);
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::send_state() {
|
||||
Serial.write(time);
|
||||
Serial.write(temperature);
|
||||
Serial.write(last_temperature);
|
||||
Serial.write(state);
|
||||
Serial.write(error_condition);
|
||||
Serial.write(time & 0xff);
|
||||
Serial.write((time>>8) & 0xff);
|
||||
Serial.write(temperature & 0xff);
|
||||
Serial.write((temperature >> 8) & 0xff);
|
||||
Serial.write(last_temperature & 0xff);
|
||||
Serial.write((last_temperature >> 8) & 0xff);
|
||||
Serial.write(state & 0xff);
|
||||
Serial.write((state >> 8) & 0xff);
|
||||
Serial.write(error_condition & 0xff);
|
||||
Serial.write((error_condition >> 8) & 0xff);
|
||||
Serial.write(is_oven_heating);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void OvenCtl::send_config() {
|
||||
|
@ -57,22 +69,52 @@ void OvenCtl::send_config() {
|
|||
Serial.write(tmp & 0xff);
|
||||
Serial.write((tmp >> 8 ) & 0xff);
|
||||
}
|
||||
// Serial.print("\n");
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void OvenCtl::dispatch_input_config(int cmd) {
|
||||
if (cmd == 255)
|
||||
send_config();
|
||||
else if (cmd == 254)
|
||||
recv_config();
|
||||
else if (cmd == 250)
|
||||
reset();
|
||||
else if (cmd == 253)
|
||||
;
|
||||
}
|
||||
|
||||
void OvenCtl::recv_config() {
|
||||
|
||||
}
|
||||
|
||||
void OvenCtl::handle_states() {
|
||||
if (state > 0)
|
||||
time++;
|
||||
get_temp();
|
||||
check_dt();
|
||||
int cmd = -1;
|
||||
|
||||
if (state > 0)
|
||||
{
|
||||
time++;
|
||||
get_temp();
|
||||
check_dt();
|
||||
}
|
||||
|
||||
if (error_condition != 0) {
|
||||
set_error_state();
|
||||
}
|
||||
|
||||
if (Serial.available() > 0) {
|
||||
cmd = Serial.read();
|
||||
if (cmd == 255)
|
||||
send_config();
|
||||
else if (cmd == 254)
|
||||
send_state();
|
||||
else if (cmd == 253)
|
||||
recv_config();
|
||||
else if (cmd == 252)
|
||||
reset();
|
||||
else if (cmd == 251)
|
||||
set_start_state();
|
||||
}
|
||||
|
||||
// if (!error_condition) {
|
||||
// print_debug();
|
||||
// }
|
||||
// else {
|
||||
// set_error_state();
|
||||
// }
|
||||
//
|
||||
switch (state) {
|
||||
case CONFIG_STATE:
|
||||
if (profile->handle_config_state(lcd, keypad))
|
||||
|
@ -113,55 +155,74 @@ void OvenCtl::handle_states() {
|
|||
control_oven();
|
||||
if (state > 0) {
|
||||
print_status();
|
||||
send_state();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::print_profile_state() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::print_status() {
|
||||
String tmp("T: ");
|
||||
if (time < 10)
|
||||
tmp += "00";
|
||||
else if (time < 100)
|
||||
tmp += "0";
|
||||
tmp += time;
|
||||
tmp += " Tmp: ";
|
||||
if (temperature < 10)
|
||||
tmp += "00";
|
||||
else if (temperature < 100)
|
||||
tmp += "0";
|
||||
tmp += temperature;
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->print(tmp);
|
||||
if (error_condition == 0) {
|
||||
String tmp("T: ");
|
||||
if (time < 10)
|
||||
tmp += "00";
|
||||
else if (time < 100)
|
||||
tmp += "0";
|
||||
tmp += time;
|
||||
tmp += " Tmp: ";
|
||||
if (temperature < 10)
|
||||
tmp += "00";
|
||||
else if (temperature < 100)
|
||||
tmp += "0";
|
||||
tmp += temperature;
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->print(tmp);
|
||||
|
||||
tmp = "Profile: ";
|
||||
tmp += state;
|
||||
tmp += "/";
|
||||
tmp += END_STATE;
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->print(tmp);
|
||||
lcd->setCursor(13, 1);
|
||||
if (is_oven_heating)
|
||||
lcd->print("on ");
|
||||
else
|
||||
lcd->print("off");
|
||||
tmp = "Profile: ";
|
||||
tmp += state;
|
||||
tmp += "/";
|
||||
tmp += END_STATE;
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->print(tmp);
|
||||
lcd->setCursor(13, 1);
|
||||
if (is_oven_heating)
|
||||
lcd->print("on ");
|
||||
else
|
||||
lcd->print("off");
|
||||
}
|
||||
else {
|
||||
lcd->clear();
|
||||
lcd->print("Error:");
|
||||
lcd->setCursor(0, 1);
|
||||
if (error_condition & E_DT_MIN)
|
||||
lcd->print("K/s too low");
|
||||
if (error_condition & E_DT_MAX)
|
||||
lcd->print("K/s too high");
|
||||
if (error_condition & E_TIME_MAX)
|
||||
lcd->print("reflow too long");
|
||||
if (error_condition & E_TS_TOO_SHORT)
|
||||
lcd->print("ts too short");
|
||||
if (error_condition & E_TS_TOO_LONG)
|
||||
lcd->print("ts too long");
|
||||
if (error_condition & E_TL_TOO_SHORT)
|
||||
lcd->print("tal too short");
|
||||
if (error_condition & E_TL_TOO_LONG)
|
||||
lcd->print("tal too long");
|
||||
if (error_condition & E_TP_TOO_LONG)
|
||||
lcd->print("peak too short");
|
||||
if (error_condition & E_TP_TOO_SHORT)
|
||||
lcd->print("peak too long");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::control_oven() {
|
||||
if (temperature < set_min && !is_oven_heating) {
|
||||
is_oven_heating = true;
|
||||
Serial.println("Oven turned on");
|
||||
// Serial.println("Oven turned on");
|
||||
}
|
||||
else if (temperature > set_min && is_oven_heating) {
|
||||
is_oven_heating = false;
|
||||
Serial.println("Oven turned off");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,11 +255,9 @@ void OvenCtl::check_dt() {
|
|||
void OvenCtl::check_max_duration() {
|
||||
if (disable_checks)
|
||||
return;
|
||||
Serial.println(time);
|
||||
if (time > profile->data[PI_TIME_MAX]) {
|
||||
error_condition |= E_TIME_MAX;
|
||||
}
|
||||
Serial.println(time);
|
||||
}
|
||||
|
||||
void OvenCtl::check_Ts_duration_min() {
|
||||
|
@ -252,7 +311,6 @@ void OvenCtl::check_Tp_duration_max() {
|
|||
}
|
||||
|
||||
void OvenCtl::set_config_state() {
|
||||
send_config();
|
||||
profile->print_config_state_0(lcd);
|
||||
}
|
||||
|
||||
|
@ -270,51 +328,44 @@ void OvenCtl::set_start_state() {
|
|||
|
||||
|
||||
void OvenCtl::set_preheat_state() {
|
||||
Serial.println("Changing state to PREHEAT_STATE");
|
||||
// Serial.println("Changing state to PREHEAT_STATE");
|
||||
state++;
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::set_ramp_up_state() {
|
||||
Serial.println("Changed state to RAMP_UP_STATE");
|
||||
state++;
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::set_tal_first_state() {
|
||||
Serial.println("Changed state to TAL_FIRST_STATE");
|
||||
state++;
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::set_peak_state() {
|
||||
Serial.println("Changed state to PEAK_STATE");
|
||||
state++;
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::set_tal_second_state() {
|
||||
Serial.println("Changed state to TAL_SECOND_STATE");
|
||||
set_temp(25, 25, -3, -6);
|
||||
set_temp(0, 25, -3, -6);
|
||||
state++;
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::set_ramp_down_state() {
|
||||
Serial.println("Changed state to RAMP_DOWN_STATE");
|
||||
state++;
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::set_end_state() {
|
||||
Serial.println("Changed state to END_STATE");
|
||||
state++;
|
||||
}
|
||||
|
||||
|
||||
void OvenCtl::set_error_state() {
|
||||
if (state != ERROR_STATE) {
|
||||
Serial.println("Changed state to ERROR_STATE");
|
||||
set_temp(0, 0, 0, 0);
|
||||
state = ERROR_STATE;
|
||||
}
|
||||
|
@ -328,8 +379,7 @@ void OvenCtl::handle_config_state() {
|
|||
|
||||
void OvenCtl::handle_start_state() {
|
||||
check_max_duration();
|
||||
Serial.println(time);
|
||||
if (temperature > profile->data[PI_TS_MIN]) {
|
||||
if (temperature > profile->data[PI_TS_MIN]) {
|
||||
Ts_time_start = time;
|
||||
set_preheat_state();
|
||||
}
|
||||
|
@ -391,13 +441,9 @@ void OvenCtl::handle_ramp_down_state() {
|
|||
|
||||
|
||||
void OvenCtl::handle_end_state() {
|
||||
// while(true) {
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OvenCtl::handle_error_state() {
|
||||
if (led_on) {
|
||||
digitalWrite(13, LOW);
|
||||
|
@ -407,22 +453,4 @@ void OvenCtl::handle_error_state() {
|
|||
digitalWrite(13, HIGH);
|
||||
led_on = true;
|
||||
}
|
||||
// if (error_condition & E_DT_MIN)
|
||||
// Serial.println(PSTR("Error: delta °K/second too low"));
|
||||
// if (error_condition & E_DT_MAX)
|
||||
// Serial.println("Error: delta °K/second too big");
|
||||
// if (error_condition & E_TIME_MAX)
|
||||
// Serial.println("Error: reflow process does take too long");
|
||||
// if (error_condition & E_TS_TOO_SHORT)
|
||||
// Serial.println("Error: heatup duration was too short");
|
||||
// if (error_condition & E_TS_TOO_LONG)
|
||||
// Serial.println("Error: heatup duration was too long");
|
||||
// if (error_condition & E_TL_TOO_SHORT)
|
||||
// Serial.println("Error: temperature above liquidus duration was too short");
|
||||
// if (error_condition & E_TL_TOO_LONG)
|
||||
// Serial.println("Error: temperature above liquidus duration was too long");
|
||||
// if (error_condition & E_TP_TOO_LONG)
|
||||
// Serial.println("Error: peak temperature duration was too short");
|
||||
// if (error_condition & E_TP_TOO_SHORT)
|
||||
// Serial.println("Error: peak temperature duration was too long");
|
||||
}
|
||||
|
|
|
@ -35,6 +35,12 @@ class Profile;
|
|||
|
||||
class OvenCtl {
|
||||
public:
|
||||
|
||||
OvenCtl();
|
||||
void handle_states();
|
||||
void set_config_state();
|
||||
|
||||
private:
|
||||
// system time, timestamps and temperatures from sensors
|
||||
int time; // profile seconds
|
||||
int temperature; // actual oven temp
|
||||
|
@ -68,10 +74,6 @@ public:
|
|||
DFR_Key * keypad;
|
||||
Profile * profile;
|
||||
|
||||
OvenCtl();
|
||||
void handle_states();
|
||||
|
||||
void print_profile_state();
|
||||
void print_status();
|
||||
void control_oven();
|
||||
void set_temp(int, int, int, int);
|
||||
|
@ -79,7 +81,6 @@ public:
|
|||
void check_dt();
|
||||
void check_max_duration();
|
||||
|
||||
void set_config_state();
|
||||
void set_start_state();
|
||||
void set_preheat_state();
|
||||
void set_tal_first_state();
|
||||
|
@ -110,6 +111,11 @@ public:
|
|||
|
||||
void send_state();
|
||||
void send_config();
|
||||
void reset();
|
||||
|
||||
void recv_config();
|
||||
|
||||
void dispatch_input_config(int);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -43,7 +43,7 @@ Profile::Profile() :
|
|||
180,
|
||||
60,
|
||||
150,
|
||||
20,
|
||||
1,
|
||||
40}),
|
||||
config_index(0),
|
||||
config_state(0),
|
||||
|
|
98
serialmon.py
98
serialmon.py
|
@ -1,31 +1,81 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import serial, struct
|
||||
import serial, struct, time
|
||||
|
||||
try:
|
||||
ser = serial.Serial('/dev/ttyUSB0', 9600)
|
||||
i = ser.read(30)
|
||||
data = list(struct.unpack("hhhhhhhhhhhhhhh", i))
|
||||
print "ts_min", data[0]
|
||||
print "ts_max", data[1]
|
||||
print "tl", data[2]
|
||||
print "tp", data[3]
|
||||
print "time_max", data[4]
|
||||
print "ramp_up_min", data[5]
|
||||
print "ramp_up_max", data[6]
|
||||
print "ramp_down_min", data[7]
|
||||
print "ramp_down_max", data[8]
|
||||
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=2)
|
||||
|
||||
print "ts_duration_min", data[9]
|
||||
print "ts_duration_max", data[10]
|
||||
print "tl_duration_min", data[11]
|
||||
print "tl_duration_max", data[12]
|
||||
print "tp_duration_min", data[13]
|
||||
print "tp_duration_max", data[14]
|
||||
|
||||
buf = ""
|
||||
alles = []
|
||||
|
||||
#def parse():
|
||||
#buffer = list()
|
||||
#while 1:
|
||||
#print ser.read(5)
|
||||
except Exception, e:
|
||||
pass
|
||||
#try:
|
||||
#i = ser.read(1)
|
||||
#if ord(i) == 255:
|
||||
#except Exception, e:
|
||||
#print e
|
||||
#else:
|
||||
|
||||
def recv_config():
|
||||
ser.write(chr(255))
|
||||
ser.flush()
|
||||
read(30)
|
||||
ser.flushInput()
|
||||
data = struct.unpack("hhhhhhhhhhhhhhh", buf)
|
||||
print
|
||||
print "Profile:"
|
||||
print "ts_min:", data[0]
|
||||
print "ts_max:", data[1]
|
||||
print "tl:", data[2]
|
||||
print "tp:", data[3]
|
||||
print "time_max:", data[4]
|
||||
print "ramp_up_min:", data[5]
|
||||
print "ramp_up_max:", data[6]
|
||||
print "ramp_down_min:", data[7]
|
||||
print "ramp_down_max:", data[8]
|
||||
|
||||
print "ts_duration_min:", data[9]
|
||||
print "ts_duration_max:", data[10]
|
||||
print "tl_duration_min:", data[11]
|
||||
print "tl_duration_max:", data[12]
|
||||
print "tp_duration_min:", data[13]
|
||||
print "tp_duration_max:", data[14]
|
||||
print
|
||||
|
||||
|
||||
def recv_state():
|
||||
ser.write(chr(254))
|
||||
ser.flush()
|
||||
read(11)
|
||||
data = struct.unpack("hhhhhb", buf)
|
||||
print "time: %ds, temperature: %d°C, last temperature: %d°C, state: %d, error condition: %d, heating: %d" % data
|
||||
|
||||
|
||||
def send_config():
|
||||
ser.write(chr(253))
|
||||
ser.write(buf)
|
||||
ser.flushInput()
|
||||
|
||||
|
||||
def read(l):
|
||||
global buf
|
||||
global alles
|
||||
buf = ""
|
||||
while len(buf) < l:
|
||||
try:
|
||||
buf += ser.read(l)
|
||||
alles.append(buf)
|
||||
except Exception, e:
|
||||
print e
|
||||
ser.flushInput()
|
||||
|
||||
|
||||
time.sleep(2)
|
||||
recv_config()
|
||||
while 1:
|
||||
recv_state()
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue