|
RSeries astromech firmware
|
|
Go to the documentation of this file. 1 #ifndef ButtonController_h
2 #define ButtonController_h
8 #ifdef LedControlMAX7221_h
9 #define DBC_TEECES_D_PIN 6
10 #define DBC_TEECES_C_PIN 7
11 #define DBC_TEECES_L_PIN 8
14 #define DBC_PIN_DISABLED 255
15 #define DBC_PIN_MAIN_POWER_RELAY 16
16 #define DBC_POWER_DOWN_DELAY 2000 // milliseconds time between Power Down Sound Trigger and Turning OFF Main Power Relay
19 #define DBC_LEFT_BUTTON_MAX 4 //4; A, B, C, D
20 #define DBC_RIGHT_BUTTON_MAX 4 //4; 1, 2, 3 // this will be increased to 4 to allow the full 16 outputs (A1 to D4)
33 #define PSI_ALTERNATE 4
36 static const byte DBC_PIN_MAP[] PROGMEM = {
54 #ifdef DBC_TEECES_L_PIN
59 #ifdef DBC_TEECES_D_PIN
64 #ifdef DBC_TEECES_D_PIN
72 #define DBC_PIN_MAP_SIZE sizeof(DBC_PIN_MAP)/sizeof(DBC_PIN_MAP[0])
93 void (*flasher)(
byte color,
int rate) = NULL,
94 const byte leftInputPin = 2,
95 const byte rightInputPin = 3) :
96 fLeftInputPin(leftInputPin),
97 fRightInputPin(rightInputPin),
106 fRightButtonCount(0),
107 fInvalidInput(false),
117 fPowerDownInitialize(false),
122 for (
byte i = 0; i <
sizeof(fIO); i++)
129 pinMode(fLeftInputPin, INPUT);
131 pinMode(fRightInputPin, INPUT);
134 digitalWrite(fLeftInputPin, HIGH);
135 digitalWrite(fRightInputPin, HIGH);
140 unsigned long now = millis();
159 if (digitalRead(fLeftInputPin) == HIGH && digitalRead(fRightInputPin) == HIGH)
162 if (fNONECounter++ > 100)
192 if (digitalRead(fLeftInputPin) == LOW && digitalRead(fRightInputPin) == LOW)
195 if (fBOTHCounter++ > 20)
201 if (fBOTHCounter++ > 1000)
244 if (digitalRead(fLeftInputPin) == HIGH && digitalRead(fRightInputPin) == HIGH)
247 if (fNONECounter++ > 20)
281 if (digitalRead(fLeftInputPin) == LOW && digitalRead(fRightInputPin) == HIGH)
289 if (fLEFTCounter++ > 20)
309 else if (digitalRead(fRightInputPin) == LOW && digitalRead(fLeftInputPin) == HIGH)
316 if (fRIGHTCounter++ > 20)
336 else if (digitalRead(fRightInputPin) == LOW && digitalRead(fLeftInputPin) == LOW)
343 if (fBOTHCounter++ > 20)
350 if (!fLeftButtonCount || !fRightButtonCount)
370 if (fNONECounter++ > 4000)
386 if (digitalRead(fLeftInputPin) == HIGH && digitalRead(fRightInputPin) == HIGH)
388 if (fNONECounter++ > 20)
416 fMainState = (fInvalidInput) ? 13 : 11;
442 #ifdef DBC_PIN_MAIN_POWER_RELAY
487 if (fIO[address] == HIGH)
491 #ifdef DBC_PIN_MAIN_POWER_RELAY
495 fPowerDownInitialize= 1;
503 #ifdef DBC_PIN_MAIN_POWER_RELAY
512 fPowerDownInitialize = 1;
531 if (digitalRead(fLeftInputPin) == LOW && digitalRead(fRightInputPin) == LOW)
534 if (fBOTHCounter++ > 50)
539 fLeftButtonCount = 0;
540 fRightButtonCount = 0;
556 switch (fLedStatusState)
563 if (fYellowRate++ > 300)
575 if (fYellowRate++ > 75)
589 if (fYellowRate++ > 150)
594 if (++fYellowFlash >= fLeftButtonCount)
613 if (fGreenRate++ > 75)
627 if (fGreenRate++ > 150)
631 if (++fGreenFlash >= fRightButtonCount)
647 if (fGreenRate++ > 300)
659 if (++fDisplaySequence > 1)
661 fDisplaySequence = 0;
674 if (fGreenRate++ > 100)
677 fLeftButtonCount = 0;
678 fRightButtonCount = 0;
700 if (digitalRead(fLeftInputPin) == LOW && digitalRead(fRightInputPin) == LOW)
703 if (fBOTHCounter++ > 50)
708 fLeftButtonCount = 0;
709 fRightButtonCount = 0;
724 fLeftButtonCount = 0;
725 fRightButtonCount = 0;
728 if (fInvalidTime++ > 2000)
739 if (fFlasher != NULL)
740 fFlasher(fLEDColor, fLEDRate);
746 if (fPowerDownInitialize && fPowerDownTime > fPowerDownDelay)
750 fPowerDownInitialize = 0;
762 for (
unsigned n = 0; n < 17; n++)
782 digitalWrite(pin, state);
786 const byte fLeftInputPin;
787 const byte fRightInputPin;
788 void (*fFlasher)(
byte color,
int rate);
793 unsigned long fLastTime;
795 unsigned fNONECounter;
796 unsigned fBOTHCounter;
797 unsigned fLEFTCounter;
798 unsigned fRIGHTCounter;
801 byte fLeftButtonCount;
803 byte fRightButtonCount;
809 byte fLedStatusState;
818 bool fFirstTime =
true;
820 bool fPowerDownInitialize;
824 byte fDisplaySequence;
827 static inline int pinMap(
byte pin)
Base class for all animated devices. AnimatedEvent::animate() is called for each device once through ...
Definition: AnimatedEvent.h:18
static void send_end()
Definition: ReelTwoSMQ.h:463
Base class for all devices that require setup that cannot happen in the constructor....
Definition: SetupEvent.h:15
#define MSGID(str)
Definition: ReelTwo.h:360
static void send_start(const smq_id id)
Definition: ReelTwoSMQ.h:173
static void send_uint16(const msg_id id, uint16_t val)
Definition: ReelTwoSMQ.h:316
#define SMQID(str)
Definition: ReelTwo.h:359
static void send_uint8(const msg_id id, uint8_t val)
Definition: ReelTwoSMQ.h:292
static void send_boolean(const msg_id id, bool val)
Definition: ReelTwoSMQ.h:412