Skip to content

Commit 3022fa4

Browse files
authored
Merge pull request #195 from taligentx/develop
Release 2.0
2 parents a21ce53 + 27176a1 commit 3022fa4

File tree

59 files changed

+23106
-3796
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+23106
-3796
lines changed

README.md

Lines changed: 188 additions & 79 deletions
Large diffs are not rendered by default.

examples/Arduino/HomeAssistant-MQTT/HomeAssistant-MQTT.ino

Lines changed: 179 additions & 74 deletions
Large diffs are not rendered by default.

examples/Arduino/Homebridge-MQTT/Homebridge-MQTT.ino

Lines changed: 231 additions & 83 deletions
Large diffs are not rendered by default.

examples/Arduino/KeybusReader/KeybusReader.ino

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
/*
2-
* DSC Keybus Reader 1.0 (Arduino)
2+
* DSC Keybus Reader 1.2 (Arduino)
33
*
44
* Decodes and prints data from the Keybus to a serial interface, including reading from serial for the virtual
5-
* keypad. This is primarily to help decode the Keybus protocol - see the Status examples to put the interface
5+
* keypad. This is primarily to help decode the Keybus protocol - see the Status example to put the interface
66
* to productive use.
77
*
8+
* Release notes:
9+
* 1.2 - Handle spurious data while keybus is disconnected
10+
* Removed redundant data processing
11+
* 1.0 - Initial release
12+
*
813
* Wiring:
914
* DSC Aux(+) --- Arduino Vin pin
1015
*
@@ -39,76 +44,88 @@
3944
// Configures the Keybus interface with the specified pins - dscWritePin is optional, leaving it out disables the
4045
// virtual keypad.
4146
#define dscClockPin 3 // Arduino Uno hardware interrupt pin: 2,3
42-
#define dscReadPin 5 // Arduino Uno: 2-12
47+
#define dscReadPin 5 // Arduino Uno: 2-12
4348
#define dscWritePin 6 // Arduino Uno: 2-12
49+
50+
// Initialize components
4451
dscKeybusInterface dsc(dscClockPin, dscReadPin, dscWritePin);
4552

4653

4754
void setup() {
4855
Serial.begin(115200);
56+
delay(1000);
4957
Serial.println();
5058
Serial.println();
5159

5260
// Optional configuration
53-
dsc.hideKeypadDigits = false; // Controls if keypad digits are hidden for publicly posted logs (default: false)
54-
dsc.processRedundantData = false; // Controls if repeated periodic commands are processed and displayed (default: true)
55-
dsc.processModuleData = true; // Controls if keypad and module data is processed and displayed (default: false)
56-
dsc.displayTrailingBits = false; // Controls if bits read as the clock is reset are displayed, appears to be spurious data (default: false)
61+
dsc.hideKeypadDigits = false; // Controls if keypad digits are hidden for publicly posted logs
62+
dsc.processModuleData = true; // Controls if keypad and module data is processed and displayed
63+
dsc.displayTrailingBits = false; // Controls if bits read as the clock is reset are displayed, appears to be spurious data
5764

5865
// Starts the Keybus interface and optionally specifies how to print data.
5966
// begin() sets Serial by default and can accept a different stream: begin(Serial1), etc.
6067
dsc.begin();
61-
6268
Serial.println(F("DSC Keybus Interface is online."));
6369
}
6470

6571

6672
void loop() {
6773

6874
// Reads from serial input and writes to the Keybus as a virtual keypad
69-
if (Serial.available() > 0 && dsc.writeReady) {
70-
dsc.write(Serial.read());
71-
}
75+
if (Serial.available() > 0) dsc.write(Serial.read());
7276

73-
if (dsc.handlePanel()) {
77+
if (dsc.loop()) {
78+
79+
if (dsc.statusChanged) { // Checks if the security system status has changed
80+
dsc.statusChanged = false; // Reset the status tracking flag
81+
82+
// Checks if the interface is connected to the Keybus
83+
if (dsc.keybusChanged) {
84+
dsc.keybusChanged = false; // Resets the Keybus data status flag
85+
if (dsc.keybusConnected) Serial.println(F("Keybus connected"));
86+
else Serial.println(F("Keybus disconnected"));
87+
}
88+
}
7489

7590
// If the Keybus data buffer is exceeded, the sketch is too busy to process all Keybus commands. Call
76-
// handlePanel() more often, or increase dscBufferSize in the library: src/dscKeybusInterface.h
77-
if (dsc.bufferOverflow) Serial.println(F("Keybus buffer overflow"));
78-
dsc.bufferOverflow = false;
91+
// loop() more often, or increase dscBufferSize in the library: src/dscKeybusInterface.h
92+
if (dsc.bufferOverflow) {
93+
Serial.println(F("Keybus buffer overflow"));
94+
dsc.bufferOverflow = false;
95+
}
7996

8097
// Prints panel data
81-
printTimestamp();
82-
Serial.print(" ");
83-
dsc.printPanelBinary(); // Optionally prints without spaces: printPanelBinary(false);
84-
Serial.print(" [");
85-
dsc.printPanelCommand(); // Prints the panel command as hex
86-
Serial.print("] ");
87-
dsc.printPanelMessage(); // Prints the decoded message
88-
Serial.println();
89-
90-
// Prints keypad and module data when valid panel data is printed
91-
if (dsc.handleModule()) {
98+
if (dsc.keybusConnected) {
9299
printTimestamp();
93100
Serial.print(" ");
94-
dsc.printModuleBinary(); // Optionally prints without spaces: printKeybusBinary(false);
95-
Serial.print(" ");
96-
dsc.printModuleMessage(); // Prints the decoded message
101+
dsc.printPanelBinary(); // Optionally prints without spaces: printPanelBinary(false);
102+
Serial.print(" [");
103+
dsc.printPanelCommand(); // Prints the panel command as hex
104+
Serial.print("] ");
105+
dsc.printPanelMessage(); // Prints the decoded message
97106
Serial.println();
107+
108+
// Prints keypad and module data when valid panel data is printed
109+
if (dsc.handleModule()) printModule();
98110
}
99111
}
100112

101113
// Prints keypad and module data when valid panel data is not available
102-
else if (dsc.handleModule()) {
103-
printTimestamp();
104-
Serial.print(" ");
105-
dsc.printModuleBinary(); // Optionally prints without spaces: printKeybusBinary(false);
106-
Serial.print(" ");
107-
dsc.printModuleMessage();
108-
Serial.println();
109-
}
114+
else if (dsc.keybusConnected && dsc.handleModule()) printModule();
115+
}
116+
117+
118+
// Prints keypad and module data
119+
void printModule() {
120+
printTimestamp();
121+
Serial.print(" ");
122+
dsc.printModuleBinary(); // Optionally prints without spaces: printKeybusBinary(false);
123+
Serial.print(" ");
124+
dsc.printModuleMessage(); // Prints the decoded message
125+
Serial.println();
110126
}
111127

128+
112129
// Prints a timestamp in seconds (with 2 decimal precision) - this is useful to determine when
113130
// the panel sends a group of messages immediately after each other due to an event.
114131
void printTimestamp() {

0 commit comments

Comments
 (0)