mirror of
				https://github.com/kevinveenbirkenbach/physical-interface.git
				synced 2025-11-03 18:28:06 +00:00 
			
		
		
		
	Refactored and continued integration of IR send
This commit is contained in:
		@@ -106,27 +106,19 @@ void dump(decode_results *results) {
 | 
				
			|||||||
void setRitterGroup(int state)
 | 
					void setRitterGroup(int state)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  transmitter.sendGroup(state);
 | 
					  transmitter.sendGroup(state);
 | 
				
			||||||
  Serial.print("The state \"");
 | 
					  Serial.print("The state \"" + String(state,BIN) + "\" was send to the group \"" + String(ritter_group_address,DEC) + "\".");
 | 
				
			||||||
  Serial.print(state);
 | 
					 | 
				
			||||||
  Serial.print("\" was send to the group \"");
 | 
					 | 
				
			||||||
  Serial.print(ritter_group_address);
 | 
					 | 
				
			||||||
  Serial.println("\".");
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Switchs one plug on
 | 
					// Switchs one plug on
 | 
				
			||||||
void setRitterSwitch(int unit, int state)
 | 
					void setRitterSwitch(int unit, int state)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  transmitter.sendUnit(unit, state);
 | 
					  transmitter.sendUnit(unit, state);
 | 
				
			||||||
  Serial.print("The state \"");
 | 
					  Serial.print("The state \"" + String(state,BIN) + "\" was send to the switch \"" + String(unit,DEC) + "\".");
 | 
				
			||||||
  Serial.print(state);
 | 
					 | 
				
			||||||
  Serial.print("\" was send to the switch \"");
 | 
					 | 
				
			||||||
  Serial.print(unit);
 | 
					 | 
				
			||||||
  Serial.println("\".");
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void setIrColor() {
 | 
					void setIrColor(decode_type_t type,int data, int bits) {
 | 
				
			||||||
  uint32_t code = strtoul(server.arg("code").c_str(), NULL, 10);
 | 
					  // irsend.send(type, data, bits);
 | 
				
			||||||
  irsend.sendNEC(code, 32);
 | 
					  Serial.print("The code \"" + String(data) + "\" with \"" + String(bits) + "\"was send in format \"" + getDecodeType(type) + "\".");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
String getJsonDht(void){
 | 
					String getJsonDht(void){
 | 
				
			||||||
@@ -150,20 +142,31 @@ bool isParameterDefined(String parameter_name){
 | 
				
			|||||||
  return false;
 | 
					  return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void handleRequest(void){
 | 
					void controller(void){
 | 
				
			||||||
  Serial.println("Website was called.");
 | 
					  if(isParameterDefined("ir_code") && isParameterDefined("ir_decode_type") && isParameterDefined("ir_data")){
 | 
				
			||||||
  if(isParameterDefined("plug_id") && isParameterDefined("status")){
 | 
					    setIrColor(static_cast<decode_type_t>(server.arg("ir_decode_type").toInt()),server.arg("ir_data").toInt(),server.arg("ir_bits").toInt());
 | 
				
			||||||
    if(server.arg("plug_id")=="group"){
 | 
					 | 
				
			||||||
      setRitterGroup(server.arg("status").toInt());
 | 
					 | 
				
			||||||
    }else{
 | 
					 | 
				
			||||||
      setRitterSwitch(server.arg("plug_id").toInt(),server.arg("status").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"){
 | 
					  if(server.arg("format")=="json"){
 | 
				
			||||||
    server.send ( 200, "text/html", getJson());
 | 
					    server.send ( 200, "text/html", getJson());
 | 
				
			||||||
  }else{
 | 
					  }else{
 | 
				
			||||||
    server.send ( 200, "text/html", homepage_template());
 | 
					    server.send ( 200, "text/html", homepage_template());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void handleRequest(void){
 | 
				
			||||||
 | 
					  Serial.println("Website was called.");
 | 
				
			||||||
 | 
					  controller();
 | 
				
			||||||
 | 
					  view();
 | 
				
			||||||
  delay(100);
 | 
					  delay(100);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user