From be51e2db35eec7154eaa13c2883b425bc4577990 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Mon, 11 May 2020 10:23:52 +0200 Subject: [PATCH] Refactored and continued integration of IR send --- main/main.ino | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/main/main.ino b/main/main.ino index 5026018..58a20fc 100644 --- a/main/main.ino +++ b/main/main.ino @@ -106,27 +106,19 @@ void dump(decode_results *results) { void setRitterGroup(int state) { transmitter.sendGroup(state); - Serial.print("The state \""); - Serial.print(state); - Serial.print("\" was send to the group \""); - Serial.print(ritter_group_address); - Serial.println("\"."); + Serial.print("The state \"" + String(state,BIN) + "\" was send to the group \"" + String(ritter_group_address,DEC) + "\"."); } // Switchs one plug on void setRitterSwitch(int unit, int state) { transmitter.sendUnit(unit, state); - Serial.print("The state \""); - Serial.print(state); - Serial.print("\" was send to the switch \""); - Serial.print(unit); - Serial.println("\"."); + Serial.print("The state \"" + String(state,BIN) + "\" was send to the switch \"" + String(unit,DEC) + "\"."); } -void setIrColor() { - uint32_t code = strtoul(server.arg("code").c_str(), NULL, 10); - irsend.sendNEC(code, 32); +void setIrColor(decode_type_t type,int data, int bits) { + // irsend.send(type, data, bits); + Serial.print("The code \"" + String(data) + "\" with \"" + String(bits) + "\"was send in format \"" + getDecodeType(type) + "\"."); } String getJsonDht(void){ @@ -150,20 +142,31 @@ bool isParameterDefined(String parameter_name){ return false; } -void handleRequest(void){ - Serial.println("Website was called."); - if(isParameterDefined("plug_id") && isParameterDefined("status")){ - if(server.arg("plug_id")=="group"){ - setRitterGroup(server.arg("status").toInt()); - }else{ - setRitterSwitch(server.arg("plug_id").toInt(),server.arg("status").toInt()); - } +void controller(void){ + if(isParameterDefined("ir_code") && isParameterDefined("ir_decode_type") && isParameterDefined("ir_data")){ + setIrColor(static_cast(server.arg("ir_decode_type").toInt()),server.arg("ir_data").toInt(),server.arg("ir_bits").toInt()); } + if(isParameterDefined("plug_id") && isParameterDefined("status")){ + if(server.arg("plug_id")=="group"){ + setRitterGroup(server.arg("status").toInt()); + }else{ + setRitterSwitch(server.arg("plug_id").toInt(),server.arg("status").toInt()); + } + } +} + +void view(void){ if(server.arg("format")=="json"){ server.send ( 200, "text/html", getJson()); }else{ server.send ( 200, "text/html", homepage_template()); } +} + +void handleRequest(void){ + Serial.println("Website was called."); + controller(); + view(); delay(100); }