Optimized general things

This commit is contained in:
Kevin Veen-Birkenbach 2020-05-15 08:55:50 +02:00
parent 0577c51cd4
commit cc4c4694c9
2 changed files with 23 additions and 22 deletions

View File

@ -7,13 +7,14 @@ const char* hostname = "physical-interface";
/** /**
* Pin layout * Pin layout
* I recommend to don't use D10, D9 and D0
*/ */
const uint16_t PIN_RADIO_TRANSMITTER = D7; const uint16_t PIN_RADIO_TRANSMITTER = D5;
const uint16_t PIN_RADIO_RECIEVER = D8; const uint16_t PIN_RADIO_RECIEVER = D4;
const uint16_t PIN_PIR = D1; const uint16_t PIN_PIR = D8;
const uint16_t PIN_DHT = D6; const uint16_t PIN_DHT = D7;
const uint16_t PIN_IR_RECIEVER = D4; const uint16_t PIN_IR_RECIEVER = D1;
const uint16_t PIN_IR_SEND = D2; const uint16_t PIN_IR_SEND = D6;
const uint16_t PIN_LDR = A0; const uint16_t PIN_LDR = A0;
const uint16_t PIN_ACTIVE_BUZZER = D5; const uint16_t PIN_SIGNAL = D2;
const uint16_t PINS_SOIL_MOISTURE[] = {D3,D9,D10}; const uint16_t PINS_SOIL_MOISTURE[] = {};

View File

@ -27,8 +27,8 @@ const char* PARAMETER_IR_TYPE="ir_type";
const char* PARAMETER_IR_CODE="ir_code"; const char* PARAMETER_IR_CODE="ir_code";
const char* PARAMETER_IR_BITS="ir_bits"; const char* PARAMETER_IR_BITS="ir_bits";
const char* PARAMETER_PRE_DELAY_TIME_IN_MS="pre_delay_time_in_ms"; const char* PARAMETER_PRE_DELAY_TIME_IN_MS="pre_delay_time_in_ms";
const char* PARAMETER_SOUND="sound_enabled"; const char* PARAMETER_SIGNAL="signal";
const char* PARAMETER_LIST[]={PARAMETER_PLUG_ADDRESS,PARAMETER_PLUG_ID,PARAMETER_PLUG_STATUS,PARAMETER_IR_TYPE,PARAMETER_IR_CODE,PARAMETER_IR_BITS,PARAMETER_PRE_DELAY_TIME_IN_MS,PARAMETER_SOUND}; const char* PARAMETER_LIST[]={PARAMETER_PLUG_ADDRESS,PARAMETER_PLUG_ID,PARAMETER_PLUG_STATUS,PARAMETER_IR_TYPE,PARAMETER_IR_CODE,PARAMETER_IR_BITS,PARAMETER_PRE_DELAY_TIME_IN_MS,PARAMETER_SIGNAL};
/** /**
* Define variables * Define variables
@ -95,14 +95,14 @@ void sendIrCode(decode_type_t type,uint32_t code, uint16_t bits) {
/** /**
* Actors * Actors
*/ */
void switchSound(boolean status){ void switchSignal(boolean status){
Serial.println("Switching sound \"" + String((status)?("on"):("off")) + "."); Serial.println("Switching signal\"" + String((status)?("on"):("off")) + ".");
if(status){ if(status){
pinMode(PIN_ACTIVE_BUZZER,OUTPUT); pinMode(PIN_SIGNAL,OUTPUT);
digitalWrite(PIN_ACTIVE_BUZZER,LOW); digitalWrite(PIN_SIGNAL,LOW);
}else{ }else{
digitalWrite(PIN_ACTIVE_BUZZER,HIGH); digitalWrite(PIN_SIGNAL,HIGH);
pinMode(PIN_ACTIVE_BUZZER,INPUT); pinMode(PIN_SIGNAL,INPUT);
} }
} }
@ -135,7 +135,7 @@ String getParameterType(const char* parameter){
} }
if( if(
parameter==PARAMETER_SOUND || parameter==PARAMETER_SIGNAL ||
parameter==PARAMETER_PLUG_STATUS parameter==PARAMETER_PLUG_STATUS
){ ){
return "boolean"; return "boolean";
@ -144,8 +144,8 @@ String getParameterType(const char* parameter){
} }
void controller(void){ void controller(void){
if(isParameterDefined(PARAMETER_SOUND)){ if(isParameterDefined(PARAMETER_SIGNAL)){
switchSound(server.arg(PARAMETER_SOUND).equals("on")); switchSignal(server.arg(PARAMETER_SIGNAL).equals("on"));
} }
if(isParameterDefined(PARAMETER_IR_TYPE) && isParameterDefined(PARAMETER_IR_CODE) && isParameterDefined(PARAMETER_IR_BITS)){ if(isParameterDefined(PARAMETER_IR_TYPE) && isParameterDefined(PARAMETER_IR_CODE) && isParameterDefined(PARAMETER_IR_BITS)){
sendIrCode(static_cast<decode_type_t>(server.arg(PARAMETER_IR_TYPE).toInt()),server.arg(PARAMETER_IR_CODE).toInt(),server.arg(PARAMETER_IR_BITS).toInt()); sendIrCode(static_cast<decode_type_t>(server.arg(PARAMETER_IR_TYPE).toInt()),server.arg(PARAMETER_IR_CODE).toInt(),server.arg(PARAMETER_IR_BITS).toInt());
@ -279,10 +279,10 @@ void setup(void)
server.onNotFound(handleRequest); server.onNotFound(handleRequest);
server.begin(); server.begin();
Serial.println("HTTP server started."); Serial.println("HTTP server started.");
Serial.println("Generate test sound."); Serial.println("Generate test signal.");
switchSound(true); switchSignal(true);
delay(200); delay(200);
switchSound(false); switchSignal(false);
} }
void loop() void loop()