#include "ovencontroller.h" OvenController::OvenController(QObject *parent, Oven *oven) : OvenInterface(parent), oven(oven) { bzero(&control, sizeof(control)); bzero(&state, sizeof(state)); } void OvenController::setUdpHandler(UdpHandler *udp) { this->udp = udp; connect(udp, SIGNAL(changed()), this, SLOT(onDataChanged())); } void OvenController::onDataChanged() { bool opened = state.door_state != 0; udp->fillControl(control); udp->fillData(state); if (opened) { if (state.door_state == 0) emit doorClosed(); } else { if (state.door_state != 0) emit doorOpened(); } oven->setCurrentHumidity(currentHumidity()); oven->setCurrentTemp(currentTemp()); oven->setCurrentInterTemp(currentInterTemp()); } int OvenController::currentTemp() { return state.curr_heat; } int OvenController::currentHumidity() { return state.curr_humidity; } int OvenController::currentInterTemp() { return qMin(qMin(state.sensor6, state.sensor7), qMin(state.sensor8, state.sensor9)); } bool OvenController::door() { return state.door_state != 0; } void OvenController::setMode(Define::Mode mode) { int m; switch (mode) { case Define::SteamMode: m = 2; break; case Define::DryMode: m = 0; break; case Define::CombiMode: m = 1; break; default: return; } qDebug() << "Set Mode" << m; udp->set(TG_COOK_MODE, m); } void OvenController::setHumidity(int percentage) { qDebug() << "Set Humidity" << percentage; udp->set(TG_HUMIDITY, percentage); } void OvenController::setTemp(int celsius) { qDebug() << "Set Temperature" << celsius; udp->set(TG_HEAT, celsius); } void OvenController::setTime(int secs) { qDebug() << "Set Time" << secs; udp->set(TG_TIME, secs); } void OvenController::setInterTemp(int celsius) { if (celsius > 0) { qDebug() << "Set Core Temperature" << celsius << "+5"; udp->set(TG_INNER_TEMP, celsius + 5); } else { qDebug() << "Set Core Temperature 0"; udp->set(TG_INNER_TEMP, 0); } } void OvenController::setFan(int rpm) { qDebug() << "Set Fan RPM" << rpm; udp->set(TG_CONV_RPM, rpm); } void OvenController::startCooking() { qDebug() << "Start Cooking"; udp->set(TG_OVEN_MODE, 1); udp->set(TG_TIME, 1440); udp->turnOn(TG_COOKING); } void OvenController::stopCooking() { qDebug() << "Stop Cooking"; udp->turnOff(TG_COOKING); } void OvenController::startPreheating() { qDebug() << "Start Preheating"; udp->set(TG_OVEN_MODE, 1); udp->set(TG_TIME, 1440); udp->turnOn(TG_PREHEAT); } void OvenController::stopPreheating() { qDebug() << "Stop Preheating"; udp->turnOff(TG_PREHEAT); } void OvenController::startCooldown() { qDebug() << "Start Cooldown"; udp->turnOn(TG_COOLDOWN); } void OvenController::stopCooldown() { qDebug() << "Stop Cooldown"; udp->turnOff(TG_COOLDOWN); } void OvenController::startHumidification() { qDebug() << "Start Humidification"; udp->turnOn(TG_INNERWATER); } void OvenController::stopHumidification() { qDebug() << "Stop Humidification"; udp->turnOff(TG_INNERWATER); } void OvenController::startWashing() { } void OvenController::stopWashing() { } void OvenController::openDamper() { qDebug() << "Open Damper"; udp->turnOn(TG_OUTHUMIDITY); } void OvenController::closeDamper() { qDebug() << "Close Damper"; udp->turnOff(TG_OUTHUMIDITY); }