led added
This commit is contained in:
parent
4bdc98bd7b
commit
5f1849caf1
src
@ -12,7 +12,7 @@
|
|||||||
#define FLAT_NUMBER_MQTT_TOPIC "/digitum/intercom_bridge4823/out/flat_number"
|
#define FLAT_NUMBER_MQTT_TOPIC "/digitum/intercom_bridge4823/out/flat_number"
|
||||||
#define STATE_MQTT_TOPIC "/digitum/intercom_bridge4823/out/state"
|
#define STATE_MQTT_TOPIC "/digitum/intercom_bridge4823/out/state"
|
||||||
|
|
||||||
#define LEDS_PIN 32
|
#define LED_PIN 32
|
||||||
#define DRY_CONT_PIN 15
|
#define DRY_CONT_PIN 15
|
||||||
#define DOOR_SENS_PIN 114
|
#define DOOR_SENS_PIN 114
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "utils/print.h"
|
#include "utils/print.h"
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "infra/mqtt.h"
|
#include "infra/mqtt.h"
|
||||||
|
#include "infra/led.h"
|
||||||
#include "domain/stateMachine.h"
|
#include "domain/stateMachine.h"
|
||||||
|
|
||||||
State currentState = NOT_CONNECTED;
|
State currentState = NOT_CONNECTED;
|
||||||
@ -25,35 +26,7 @@ void writeState(char* message) {
|
|||||||
publishToMQTT(STATE_MQTT_TOPIC, message);
|
publishToMQTT(STATE_MQTT_TOPIC, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateStateMachine(int data) {
|
void receiveData(int data) {
|
||||||
switch (currentState) {
|
|
||||||
case NOT_CONNECTED:
|
|
||||||
if (data == 0) {
|
|
||||||
// Stay in the NOT_CONNECTED state
|
|
||||||
} else if (data == 1) {
|
|
||||||
currentState = CONNECTED;
|
|
||||||
writeState("connected");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CONNECTED:
|
|
||||||
if (data == 0) {
|
|
||||||
countZeros++;
|
|
||||||
if (countZeros >= NOT_CONNECTED_THRESHOLD) {
|
|
||||||
currentState = NOT_CONNECTED;
|
|
||||||
writeState("not connected");
|
|
||||||
resetCounters();
|
|
||||||
}
|
|
||||||
} else if (data == 1) {
|
|
||||||
if (countZeros >= INITIALIZING_CALL_THRESHOLD) {
|
|
||||||
currentState = RECEIVING_DATA;
|
|
||||||
writeState("receiving data");
|
|
||||||
resetCounters();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RECEIVING_DATA:
|
|
||||||
if (data != previousData) {
|
if (data != previousData) {
|
||||||
if (previousData == HIGH) {
|
if (previousData == HIGH) {
|
||||||
dataLength++;
|
dataLength++;
|
||||||
@ -63,60 +36,105 @@ void updateStateMachine(int data) {
|
|||||||
signalDuration++;
|
signalDuration++;
|
||||||
}
|
}
|
||||||
previousData = data;
|
previousData = data;
|
||||||
if (data == 0) {
|
}
|
||||||
|
|
||||||
|
void changeState(State state, bool resetCountersFlag=true) {
|
||||||
|
currentState = state;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case NOT_CONNECTED:
|
||||||
|
ledTurnOff();
|
||||||
|
writeState("not connected");
|
||||||
|
break;
|
||||||
|
case CONNECTED:
|
||||||
|
ledTurnOn();
|
||||||
|
writeState("connected");
|
||||||
|
break;
|
||||||
|
case RECEIVING_DATA:
|
||||||
|
writeState("receiving data");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resetCountersFlag)
|
||||||
|
resetCounters();
|
||||||
|
}
|
||||||
|
|
||||||
|
void flatReceived() {
|
||||||
|
int flat = dataLength/2;
|
||||||
|
|
||||||
|
if (flat < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
println("| data length: ", dataLength);
|
||||||
|
println("| flat: ", flat);
|
||||||
|
publishToMQTT(FLAT_NUMBER_MQTT_TOPIC, flat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateStateMachine(int data) {
|
||||||
|
switch (currentState) {
|
||||||
|
case NOT_CONNECTED:
|
||||||
|
if (data == LOW) {}
|
||||||
|
else if (data == HIGH) {
|
||||||
|
changeState(CONNECTED);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONNECTED:
|
||||||
|
if (data == LOW) {
|
||||||
|
countZeros++;
|
||||||
|
if (countZeros >= NOT_CONNECTED_THRESHOLD) {
|
||||||
|
changeState(NOT_CONNECTED);
|
||||||
|
}
|
||||||
|
} else if (data == HIGH) {
|
||||||
|
if (countZeros >= INITIALIZING_CALL_THRESHOLD) {
|
||||||
|
changeState(RECEIVING_DATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RECEIVING_DATA:
|
||||||
|
receiveData(data);
|
||||||
|
|
||||||
|
if (data == LOW) {
|
||||||
countOnes = 0;
|
countOnes = 0;
|
||||||
countZeros++;
|
countZeros++;
|
||||||
if (countZeros >= DATA_RECEIVED_THESHOLD) {
|
if (countZeros >= DATA_RECEIVED_THESHOLD) {
|
||||||
println("| data length: ", dataLength);
|
flatReceived();
|
||||||
println("| flat: ", dataLength/2);
|
changeState(DATA_RECEIVED);
|
||||||
publishToMQTT(FLAT_NUMBER_MQTT_TOPIC, dataLength/2);
|
|
||||||
|
|
||||||
currentState = DATA_RECEIVED;
|
|
||||||
resetCounters();
|
|
||||||
}
|
}
|
||||||
} else if (data == 1) {
|
} else if (data == HIGH) {
|
||||||
countZeros = 0;
|
countZeros = 0;
|
||||||
countOnes++;
|
countOnes++;
|
||||||
if (countOnes >= CONNECTED_THRESHOLD) {
|
if (countOnes >= CONNECTED_THRESHOLD) {
|
||||||
currentState = CONNECTED;
|
changeState(CONNECTED);
|
||||||
writeState("connected");
|
|
||||||
resetCounters();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATA_RECEIVED:
|
case DATA_RECEIVED:
|
||||||
if (data == 0) {
|
if (data == LOW) {
|
||||||
countZeros++;
|
countZeros++;
|
||||||
if (countZeros >= CALL_ENDED_THRESHOLD) {
|
if (countZeros >= CALL_ENDED_THRESHOLD) {
|
||||||
currentState = CALL_ENDED;
|
changeState(CALL_ENDED);
|
||||||
writeState("call ended");
|
|
||||||
resetCounters();
|
|
||||||
}
|
}
|
||||||
} else if (data == 1) {
|
} else if (data == HIGH) {
|
||||||
countOnes++;
|
countOnes++;
|
||||||
if (countOnes >= CONNECTED_THRESHOLD) {
|
if (countOnes >= CONNECTED_THRESHOLD) {
|
||||||
currentState = CONNECTED;
|
changeState(CONNECTED);
|
||||||
writeState("connected");
|
|
||||||
resetCounters();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CALL_ENDED:
|
case CALL_ENDED:
|
||||||
if (data == 0) {
|
if (data == LOW) {
|
||||||
countZeros++;
|
countZeros++;
|
||||||
if (countZeros >= NOT_CONNECTED_THRESHOLD) {
|
if (countZeros >= NOT_CONNECTED_THRESHOLD) {
|
||||||
currentState = NOT_CONNECTED;
|
changeState(NOT_CONNECTED);
|
||||||
writeState("not connected");
|
|
||||||
resetCounters();
|
|
||||||
}
|
}
|
||||||
} else if (data == 1) {
|
} else if (data == HIGH) {
|
||||||
countOnes++;
|
countOnes++;
|
||||||
if (countOnes >= CONNECTED_THRESHOLD) {
|
if (countOnes >= CONNECTED_THRESHOLD) {
|
||||||
currentState = CONNECTED;
|
changeState(CONNECTED);
|
||||||
writeState("connected");
|
|
||||||
resetCounters();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
12
src/infra/led.cpp
Normal file
12
src/infra/led.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "config/config.h"
|
||||||
|
#include "infra/led.h"
|
||||||
|
|
||||||
|
void ledTurnOn() {
|
||||||
|
digitalWrite(LED_PIN, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ledTurnOff() {
|
||||||
|
digitalWrite(LED_PIN, HIGH);
|
||||||
|
}
|
4
src/infra/led.h
Normal file
4
src/infra/led.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void ledTurnOn();
|
||||||
|
void ledTurnOff();
|
12
src/main.cpp
12
src/main.cpp
@ -10,6 +10,7 @@
|
|||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "infra/eth.h"
|
#include "infra/eth.h"
|
||||||
#include "infra/mqtt.h"
|
#include "infra/mqtt.h"
|
||||||
|
#include "infra/led.h"
|
||||||
#include "domain/stateMachine.h"
|
#include "domain/stateMachine.h"
|
||||||
|
|
||||||
uint32_t lastMillis;
|
uint32_t lastMillis;
|
||||||
@ -28,13 +29,16 @@ void setup() {
|
|||||||
initMQTT();
|
initMQTT();
|
||||||
|
|
||||||
pinMode(DATA_PIN, INPUT);
|
pinMode(DATA_PIN, INPUT);
|
||||||
|
pinMode(LED_PIN, OUTPUT);
|
||||||
pinMode(DRY_CONT_PIN, OUTPUT);
|
pinMode(DRY_CONT_PIN, OUTPUT);
|
||||||
digitalWrite(DRY_CONT_PIN, 0);
|
|
||||||
|
digitalWrite(LED_PIN, HIGH);
|
||||||
|
|
||||||
|
digitalWrite(DRY_CONT_PIN, LOW);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
digitalWrite(DRY_CONT_PIN, 1);
|
digitalWrite(DRY_CONT_PIN, HIGH);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
digitalWrite(DRY_CONT_PIN, 0);
|
digitalWrite(DRY_CONT_PIN, LOW);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user