Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doorbell #30

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion gateway/Automation/Automation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void saloonClick() {
void saloonOff() {
setOutput(SALOON_1_ID, Relay::OFF);
setOutput(SALOON_2_ID, Relay::OFF);
setOutput(SALOON_SHELF_ID, Relay::OFF);
}
void gamingRoomClick() {
setOutput(GAMING_ROOM_1_ID);
Expand Down Expand Up @@ -82,8 +83,39 @@ void kitchenOff() {
setOutput(KITCHEN_TABLE_ID, Relay::OFF);
}

void doorbellClick() {
doorbellState = ON;
}

void doorbellUpdate(){
switch (doorbellState) {
case ON:
setOutput(DOORBELL_ID, Relay::ON);
doorbellState = WaitingForRellese;
break;
case WaitingForRellese:
if ( !(doorbell.isLongPressed()) ) {
setOutput(DOORBELL_ID, Relay::OFF);
doorbellState = OFF;
}
break;
}
}

void doorOpen(){
send(msgs[maxSensors+1].set(false));
}

void doorClose() {
send(msgs[maxSensors+1].set(true));
}

void setupButtons() {
// Setup the button.
shelf.attachClick(clickCallback,SALOON_SHELF_ID);
shelf.attachLongPressStop(saloonOff);
shelf.attachDoubleClick(clickCallback, SALOON_2_ID);

saloon.attachClick(saloonClick);
saloon.attachLongPressStop(saloonOff);
saloon.attachDoubleClick(clickCallback, SALOON_2_ID);
Expand All @@ -110,14 +142,20 @@ void setupButtons() {
bathroom.attachLongPressStop(bathroomOff);

mirror.attachClick(clickCallback, MIRROR_ID);
mirror.attachDoubleClick(clickCallback, FAN_ID);

kitchen.attachClick(kitchenClick);
kitchen.attachLongPressStop(kitchenOff);
kitchen.attachDoubleClick(clickCallback, KITCHEN_LED1_ID);

kitchenTable.attachClick(clickCallback, KITCHEN_TABLE_ID);

workshop.attachClick(clickCallback, WORKSHOP_ID);
//workshop.attachClick(clickCallback, WORKSHOP_ID);

corridor.attachClick(clickCallback, CORRIDOR_ID);
corridor.attachDoubleClick(clickCallback, WORKSHOP_ID);

doorbell.attachPressStart(doorbellClick);
door.attachLongPressStart(doorOpen);
door.attachLongPressStop(doorClose);
}
14 changes: 10 additions & 4 deletions gateway/Mapping/Mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const uint8_t KITCHEN_LED2_ID = 63;
const uint8_t KITCHEN_TABLE_ID = 64;
const uint8_t WORKSHOP_ID = 71;
const uint8_t CORRIDOR_ID = 81;
const uint8_t DOORBELL_ID = 82;
const uint8_t DOOR_ID = 83;
const uint8_t HEATING_1_ID = 10;
const uint8_t HEATING_2_ID = 20;
const uint8_t HEATING_3_ID = 30;
Expand Down Expand Up @@ -71,11 +73,12 @@ SensorsStruct Sensors [] = {
{ MIRROR_ID, "Lustro", 30, false },
{ FAN_ID, "Wentylator", 31, false },
{ KITCHEN_ID, "Kuchnia", 32, false },
{ KITCHEN_LED1_ID, "Kuchnia blat", 33, false },
{ KITCHEN_LED2_ID, "Kuchnia deko", 34, false },
{ KITCHEN_LED1_ID, "Kuchnia LED 1", 33, false },
{ KITCHEN_LED2_ID, "Kuchnia LED 2", 34, false },
{ KITCHEN_TABLE_ID, "Kuchnia stolik", 35, false },
{ WORKSHOP_ID, "Warsztat", 36, false },
{ CORRIDOR_ID, "Korytarz", 37, false },
{ DOORBELL_ID, "Dzwonek", 38, false },
{ HEATING_1_ID, "Strefa 1", 41, false },
{ HEATING_2_ID, "Strefa 2", 42, false },
{ HEATING_3_ID, "Strefa 3", 43, false },
Expand All @@ -85,7 +88,7 @@ SensorsStruct Sensors [] = {
{ HEATING_7_ID, "Strefa 7", 47, false },
};
const uint8_t maxSensors = sizeof(Sensors) / sizeof(SensorsStruct);
MyMessage msgs[maxSensors];
MyMessage msgs[maxSensors+1]; //door is extra case

uint8_t getIdx(uint8_t sensorId) {
for (uint8_t i = 0; i < maxSensors; i++) {
Expand All @@ -96,6 +99,7 @@ uint8_t getIdx(uint8_t sensorId) {

// Pushbuttons declaration
// Remember that names should be consistent with main loop in gateway.ino
OneButton shelf(A0,true);
OneButton saloon(A1, true);
OneButton gamingRoom(A2, true);
OneButton bedroom(A3, true);
Expand All @@ -106,5 +110,7 @@ OneButton bathroom(A7, true);
OneButton mirror(A8, true);
OneButton kitchen(A9, true);
OneButton kitchenTable(A10, true);
OneButton workshop(A11, true);
//OneButton workshop(A11, true);
OneButton corridor(A12, true);
OneButton door(A13, true);
OneButton doorbell(A14, true);
16 changes: 14 additions & 2 deletions gateway/gateway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#define MY_BAUD_RATE 115200
#endif

enum doorbellEnum {OFF, ON, WaitingForRellese};
doorbellEnum doorbellState = OFF;

// Remember to add library to Arduino path
#include <MySensors.h>
#include "./Mapping/Mapping.hpp"
Expand Down Expand Up @@ -43,22 +46,27 @@ void setup() {
digitalWrite(sensor.pin, bState);
}
setupButtons();
msgs[maxSensors+1]=MyMessage(DOOR_ID, V_TRIPPED);

}

void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Gateway", "1.5");
sendSketchInfo("Gateway", "1.7");

// Send actual states
for (uint8_t idx = 0; idx < maxSensors; idx++) {
auto sensor = Sensors[idx];
present(sensor.id, S_BINARY, sensor.description);
send(msgs[idx].set(loadState(sensor.id)));
}
present(DOOR_ID, S_DOOR, "kontaktron drzwi");
send(msgs[maxSensors+1].set(true));
}

void loop() {
// Keep sensing buttons
shelf.tick();
saloon.tick();
gamingRoom.tick();
bedroom.tick();
Expand All @@ -69,8 +77,12 @@ void loop() {
mirror.tick();
kitchen.tick();
kitchenTable.tick();
workshop.tick();
//workshop.tick();
corridor.tick();
doorbell.tick();
door.tick();

doorbellUpdate();
}

void receive(const MyMessage &message) {
Expand Down