Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
taligentx committed Jun 13, 2018
1 parent d496f9b commit af68826
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 167 deletions.
64 changes: 32 additions & 32 deletions examples/Arduino/Status/Status.ino
Original file line number Diff line number Diff line change
Expand Up @@ -78,61 +78,61 @@ void loop() {
dsc.bufferOverflow = false;

// Checks status per partition
for (byte partitionIndex = 0; partitionIndex < dscPartitions; partitionIndex++) {
for (byte partition = 0; partition < dscPartitions; partition++) {

if (dsc.armedChanged[partitionIndex]) {
dsc.armedChanged[partitionIndex] = false; // Resets the partition armed status flag
if (dsc.armed[partitionIndex]) {
if (dsc.armedChanged[partition]) {
dsc.armedChanged[partition] = false; // Resets the partition armed status flag
if (dsc.armed[partition]) {
Serial.print(F("Partition "));
Serial.print(partitionIndex + 1);
Serial.print(partition + 1);
Serial.print(F(" armed"));
if (dsc.armedAway[partitionIndex]) Serial.println(F(" away"));
if (dsc.armedStay[partitionIndex]) Serial.println(F(" stay"));
if (dsc.armedAway[partition]) Serial.println(F(" away"));
if (dsc.armedStay[partition]) Serial.println(F(" stay"));
}
else {
Serial.print(F("Partition "));
Serial.print(partitionIndex + 1);
Serial.print(partition + 1);
Serial.println(F(" disarmed"));
}
}

if (dsc.alarmChanged[partitionIndex]) {
dsc.alarmChanged[partitionIndex] = false; // Resets the partition alarm status flag
if (dsc.alarm[partitionIndex]) {
if (dsc.alarmChanged[partition]) {
dsc.alarmChanged[partition] = false; // Resets the partition alarm status flag
if (dsc.alarm[partition]) {
Serial.print(F("Partition "));
Serial.print(partitionIndex + 1);
Serial.print(partition + 1);
Serial.println(F(" in alarm"));
}
}

if (dsc.exitDelayChanged[partitionIndex]) {
dsc.exitDelayChanged[partitionIndex] = false; // Resets the exit delay status flag
if (dsc.exitDelay[partitionIndex]) {
if (dsc.exitDelayChanged[partition]) {
dsc.exitDelayChanged[partition] = false; // Resets the exit delay status flag
if (dsc.exitDelay[partition]) {
Serial.print(F("Partition "));
Serial.print(partitionIndex + 1);
Serial.print(partition + 1);
Serial.println(F(" exit delay in progress"));
}
}

if (dsc.entryDelayChanged[partitionIndex]) {
dsc.entryDelayChanged[partitionIndex] = false; // Resets the exit delay status flag
if (dsc.entryDelay[partitionIndex]) {
if (dsc.entryDelayChanged[partition]) {
dsc.entryDelayChanged[partition] = false; // Resets the exit delay status flag
if (dsc.entryDelay[partition]) {
Serial.print(F("Partition "));
Serial.print(partitionIndex + 1);
Serial.print(partition + 1);
Serial.println(F(" entry delay in progress"));
}
}

if (dsc.fireChanged[partitionIndex]) {
dsc.fireChanged[partitionIndex] = false; // Resets the fire status flag
if (dsc.fire[partitionIndex]) {
if (dsc.fireChanged[partition]) {
dsc.fireChanged[partition] = false; // Resets the fire status flag
if (dsc.fire[partition]) {
Serial.print(F("Partition "));
Serial.print(partitionIndex + 1);
Serial.print(partition + 1);
Serial.println(F(" fire alarm on"));
}
else {
Serial.print(F("Partition "));
Serial.print(partitionIndex + 1);
Serial.print(partition + 1);
Serial.println(F(" fire alarm restored"));
}
}
Expand All @@ -149,13 +149,13 @@ void loop() {
for (byte zoneBit = 0; zoneBit < 8; zoneBit++) {
if (bitRead(dsc.openZonesChanged[zoneGroup], zoneBit)) { // Checks an individual open zone status flag
bitWrite(dsc.openZonesChanged[zoneGroup], zoneBit, 0); // Resets the individual open zone status flag
if (bitRead(dsc.openZones[zoneGroup], zoneBit)) {
if (bitRead(dsc.openZones[zoneGroup], zoneBit)) { // Zone open
Serial.print(F("Zone open: "));
Serial.println(zoneBit + 1 + (zoneGroup * 8));
Serial.println(zoneBit + 1 + (zoneGroup * 8)); // Determines the zone number
}
else {
else { // Zone closed
Serial.print(F("Zone restored: "));
Serial.println(zoneBit + 1 + (zoneGroup * 8));
Serial.println(zoneBit + 1 + (zoneGroup * 8)); // Determines the zone number
}
}
}
Expand All @@ -173,13 +173,13 @@ void loop() {
for (byte zoneBit = 0; zoneBit < 8; zoneBit++) {
if (bitRead(dsc.alarmZonesChanged[zoneGroup], zoneBit)) { // Checks an individual alarm zone status flag
bitWrite(dsc.alarmZonesChanged[zoneGroup], zoneBit, 0); // Resets the individual alarm zone status flag
if (bitRead(dsc.alarmZones[zoneGroup], zoneBit)) {
if (bitRead(dsc.alarmZones[zoneGroup], zoneBit)) { // Zone alarm
Serial.print(F("Zone alarm: "));
Serial.println(zoneBit + 1 + (zoneGroup * 8));
Serial.println(zoneBit + 1 + (zoneGroup * 8)); // Determines the zone number
}
else {
Serial.print(F("Zone alarm restored: "));
Serial.println(zoneBit + 1 + (zoneGroup * 8));
Serial.println(zoneBit + 1 + (zoneGroup * 8)); // Determines the zone number
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions examples/esp8266/Status-Email/Status-Email.ino
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,29 @@ void loop() {
}

// Checks status per partition
for (byte partitionIndex = 0; partitionIndex < dscPartitions; partitionIndex++) {
for (byte partition = 0; partition < dscPartitions; partition++) {

if (dsc.alarmChanged[partitionIndex]) {
dsc.alarmChanged[partitionIndex] = false; // Resets the partition alarm status flag
if (dsc.alarmChanged[partition]) {
dsc.alarmChanged[partition] = false; // Resets the partition alarm status flag

char emailBody[12] = "Partition ";
char partition[2];
itoa(partitionIndex + 1, partition, 10);
strcat(emailBody, partition);
char partitionNumber[2];
itoa(partition + 1, partitionNumber, 10);
strcat(emailBody, partitionNumber);

if (dsc.alarm[partitionIndex]) sendEmail("Security system in alarm", emailBody);
if (dsc.alarm[partition]) sendEmail("Security system in alarm", emailBody);
else sendEmail("Security system disarmed after alarm", emailBody);
}

if (dsc.fireChanged[partitionIndex]) {
dsc.fireChanged[partitionIndex] = false; // Resets the fire status flag
if (dsc.fireChanged[partition]) {
dsc.fireChanged[partition] = false; // Resets the fire status flag

char emailBody[12] = "Partition ";
char partition[2];
itoa(partitionIndex + 1, partition, 10);
strcat(emailBody, partition);
char partitionNumber[2];
itoa(partition + 1, partitionNumber, 10);
strcat(emailBody, partitionNumber);

if (dsc.fire[partitionIndex]) sendEmail("Security system fire alarm", emailBody);
if (dsc.fire[partition]) sendEmail("Security system fire alarm", emailBody);
else sendEmail("Security system fire alarm restored", emailBody);
}
}
Expand Down
10 changes: 5 additions & 5 deletions examples/esp8266/Status-Homey/Status-Homey.ino
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ void loop() {

// Handles messages received from Homey

// Stay Arm
// Arm stay
void armStay() {
if (Homey.value.toInt() == 1 && !dsc.partitionArmed && !dsc.exitDelay) { // Read the argument sent from the homey flow
if (Homey.value.toInt() == 1 && !dsc.armed[0] && !dsc.exitDelay[0]) { // Read the argument sent from the homey flow
while (!dsc.writeReady) dsc.handlePanel(); // Continues processing Keybus data until ready to write
dsc.write('s'); // Keypad stay arm

}
}


// Away arm
// Arm away
void armAway() {
if (Homey.value.toInt() == 1 && !dsc.partitionArmed && !dsc.exitDelay) { // Read the argument sent from the homey flow
if (Homey.value.toInt() == 1 && !dsc.armed[0] && !dsc.exitDelay[0]) { // Read the argument sent from the homey flow
while (!dsc.writeReady) dsc.handlePanel(); // Continues processing Keybus data until ready to write
dsc.write('w'); // Keypad away arm
}
Expand All @@ -203,7 +203,7 @@ void armAway() {

// Disarm
void disarm() {
if (Homey.value.toInt() == 1 && (dsc.partitionArmed || dsc.exitDelay)) {
if (Homey.value.toInt() == 1 && (dsc.armed[0] || dsc.exitDelay[0])) {
while (!dsc.writeReady) dsc.handlePanel(); // Continues processing Keybus data until ready to write
dsc.write(accessCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,70 +193,70 @@ void loop() {
}

// Publishes status per partition
for (byte partitionIndex = 0; partitionIndex < dscPartitions; partitionIndex++) {
for (byte partition = 0; partition < dscPartitions; partition++) {

// Publishes exit delay status
if (dsc.exitDelayChanged[partitionIndex]) {
dsc.exitDelayChanged[partitionIndex] = false; // Resets the exit delay status flag
if (dsc.exitDelayChanged[partition]) {
dsc.exitDelayChanged[partition] = false; // Resets the exit delay status flag

// Appends the mqttPartitionTopic with the partition number
char publishTopic[strlen(mqttPartitionTopic) + 1];
char partition[2];
char partitionNumber[2];
strcpy(publishTopic, mqttPartitionTopic);
itoa(partitionIndex + 1, partition, 10);
strcat(publishTopic, partition);
itoa(partition + 1, partitionNumber, 10);
strcat(publishTopic, partitionNumber);

if (dsc.exitDelay[partitionIndex]) mqtt.publish(publishTopic, "pending", true); // Publish as a retained message
else if (!dsc.exitDelay[partitionIndex] && !dsc.armed[partitionIndex]) mqtt.publish(publishTopic, "disarmed", true);
if (dsc.exitDelay[partition]) mqtt.publish(publishTopic, "pending", true); // Publish as a retained message
else if (!dsc.exitDelay[partition] && !dsc.armed[partition]) mqtt.publish(publishTopic, "disarmed", true);
}

// Publishes armed/disarmed status
if (dsc.armedChanged[partitionIndex]) {
dsc.armedChanged[partitionIndex] = false; // Resets the partition armed status flag
if (dsc.armedChanged[partition]) {
dsc.armedChanged[partition] = false; // Resets the partition armed status flag

// Appends the mqttPartitionTopic with the partition number
char publishTopic[strlen(mqttPartitionTopic) + 1];
char partition[2];
char partitionNumber[2];
strcpy(publishTopic, mqttPartitionTopic);
itoa(partitionIndex + 1, partition, 10);
strcat(publishTopic, partition);
itoa(partition + 1, partitionNumber, 10);
strcat(publishTopic, partitionNumber);

if (dsc.armed[partitionIndex]) {
if (dsc.armedAway[partitionIndex]) mqtt.publish(publishTopic, "armed_away", true);
else if (dsc.armedStay[partitionIndex]) mqtt.publish(publishTopic, "armed_home", true);
if (dsc.armed[partition]) {
if (dsc.armedAway[partition]) mqtt.publish(publishTopic, "armed_away", true);
else if (dsc.armedStay[partition]) mqtt.publish(publishTopic, "armed_home", true);
}
else mqtt.publish(publishTopic, "disarmed", true);
}

// Publishes alarm status
if (dsc.alarmChanged[partitionIndex]) {
dsc.alarmChanged[partitionIndex] = false; // Resets the partition alarm status flag
if (dsc.alarm[partitionIndex]) {
if (dsc.alarmChanged[partition]) {
dsc.alarmChanged[partition] = false; // Resets the partition alarm status flag
if (dsc.alarm[partition]) {

// Appends the mqttPartitionTopic with the partition number
char publishTopic[strlen(mqttPartitionTopic) + 1];
char partition[2];
char partitionNumber[2];
strcpy(publishTopic, mqttPartitionTopic);
itoa(partitionIndex + 1, partition, 10);
strcat(publishTopic, partition);
itoa(partition + 1, partitionNumber, 10);
strcat(publishTopic, partitionNumber);

mqtt.publish(publishTopic, "triggered", true); // Alarm tripped
}
}

// Publishes alarm status
if (dsc.fireChanged[partitionIndex]) {
dsc.fireChanged[partitionIndex] = false; // Resets the fire status flag
// Publishes fire alarm status
if (dsc.fireChanged[partition]) {
dsc.fireChanged[partition] = false; // Resets the fire status flag

// Appends the mqttFireTopic with the partition number
char firePublishTopic[strlen(mqttFireTopic) + 1];
char partition[2];
char partitionNumber[2];
strcpy(firePublishTopic, mqttFireTopic);
itoa(partitionIndex + 1, partition, 10);
strcat(firePublishTopic, partition);
itoa(partition + 1, partitionNumber, 10);
strcat(firePublishTopic, partitionNumber);

if (dsc.fire[partitionIndex]) mqtt.publish(firePublishTopic, "1"); // Fire alarm tripped
else mqtt.publish(firePublishTopic, "0"); // Fire alarm restored
if (dsc.fire[partition]) mqtt.publish(firePublishTopic, "1"); // Fire alarm tripped
else mqtt.publish(firePublishTopic, "0"); // Fire alarm restored
}
}

Expand Down Expand Up @@ -301,33 +301,33 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
(void)topic;
(void)length;

byte partitionIndex = 0;
byte partition = 0;
byte payloadIndex = 0;

// Checks if a partition number 1-8 has been sent and sets the second character as the payload
if (payload[0] >= 0x31 && payload[0] <= 0x38) {
partitionIndex = payload[0] - 49;
partition = payload[0] - 49;
payloadIndex = 1;
}

// Arm stay
if (payload[payloadIndex] == 'S' && !dsc.armed[partitionIndex] && !dsc.exitDelay[partitionIndex]) {
if (payload[payloadIndex] == 'S' && !dsc.armed[partition] && !dsc.exitDelay[partition]) {
while (!dsc.writeReady) dsc.handlePanel(); // Continues processing Keybus data until ready to write
dsc.writePartition = partitionIndex + 1; // Sets writes to the partition number
dsc.writePartition = partition + 1; // Sets writes to the partition number
dsc.write('s'); // Virtual keypad arm stay
}

// Arm away
else if (payload[payloadIndex] == 'A' && !dsc.armed[partitionIndex] && !dsc.exitDelay[partitionIndex]) {
else if (payload[payloadIndex] == 'A' && !dsc.armed[partition] && !dsc.exitDelay[partition]) {
while (!dsc.writeReady) dsc.handlePanel(); // Continues processing Keybus data until ready to write
dsc.writePartition = partitionIndex + 1; // Sets writes to the partition number
dsc.writePartition = partition + 1; // Sets writes to the partition number
dsc.write('w'); // Virtual keypad arm away
}

// Disarm
else if (payload[payloadIndex] == 'D' && (dsc.armed[partitionIndex] || dsc.exitDelay[partitionIndex])) {
else if (payload[payloadIndex] == 'D' && (dsc.armed[partition] || dsc.exitDelay[partition])) {
while (!dsc.writeReady) dsc.handlePanel(); // Continues processing Keybus data until ready to write
dsc.writePartition = partitionIndex + 1; // Sets writes to the partition number
dsc.writePartition = partition + 1; // Sets writes to the partition number
dsc.write(accessCode);
}
}
Expand Down
Loading

0 comments on commit af68826

Please sign in to comment.