123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // Button handling for RC5 and RC6 Remotes
- // - these send a toggle bit on every new button press, so it is easy to differ hold and re-pressing
- // - on re-pressing this function will send the button again immediately. it uses the _currPrefix which has to be passed by the calling function
- // and which must be only the single byte of the RCx code containing the toggle bit
- // - if a button is held down, the remote will not toggle this bit and goes on sending the same code every 100ms or so
- // this function will then, after some ignored codes, start with some slow repeats, then switch to medium repeat rate and finally repeat with the rate of the incoming codes
- // configuration variables for RCx button handling
- uint8_t handleButton_RCx_ignoreFirstRepeats = 4; // repeats to ignore when a button is beeing held (the first one is always sent)
- uint8_t handleButton_RCx_slowRepeats = 4; // amount of slow repeats to send
- uint8_t handleButton_RCx_slowRepeatsNumFastRepeats = 4; // how many fast repeats (=sending rate of the RC remote) represent one slow repeat?
- uint8_t handleButton_RCx_mediumRepeats = 5; // amount of medium repeats to send
- uint8_t handleButton_RCx_mediumRepeatsNumFastRepeats = 2; // how many fast repeats (=sending rate of the RC remote) represent one slow repeat?
- uint8_t handleButton_RC5_holdButton_releaseTimeout = 146; // release keys after a button was held (_btnMode=BUTTON_HOLD) after this ms if triggered by handleButton_RCx function
- uint8_t handleButton_RC6_holdButton_releaseTimeout = 100; // release keys after a button was held (_btnMode=BUTTON_HOLD) after this ms if triggered by handleButton_RCx function
- // global variables for RCx button handling
- unsigned int handleButton_RCx_btnRepeatsCounter;
- uint8_t handleButton_RCx_lastButton, handleButton_RCx_lastPrefix;
- uint8_t handleButton_RCx_btnSlowRepeatsCounter, handleButton_RCx_btnSlowRepeatsCounter2;
- uint8_t handleButton_RCx_btnMediumRepeatsCounter, handleButton_RCx_btnMediumRepeatsCounter2;
- // the function
- //void handleButton_RCx(uint8_t _btn, uint8_t _btnMode, uint8_t _currPrefix) {
- // handleButton_RCx(_btn, _btnMode, _currPrefix, REMOTETYPE_RC6);
- //}
- void handleButton_RCx(uint8_t _btn, uint8_t _btnMode, uint8_t _currPrefix, uint8_t _remoteType) {
- bool _repeatMode = false;
- bool _holdMode = false;
- if (_btnMode == 1) _repeatMode = true;
- else if (_btnMode == 2) _holdMode = true;
- if (_btn != handleButton_RCx_lastButton || (_btn == handleButton_RCx_lastButton) && (_currPrefix != handleButton_RCx_lastPrefix)) {
- if (debug2) {
- Serial.println(F("RCx BUTTON INITIAL"));
- }
-
- if (_holdMode) {
- releaseAllKeys();
- sendKey(_btn, true);
- if(_remoteType == REMOTETYPE_RC6) holdButton_releaseTimeout = handleButton_RC6_holdButton_releaseTimeout;
- else if(_remoteType == REMOTETYPE_RC5) holdButton_releaseTimeout = handleButton_RC5_holdButton_releaseTimeout;
-
- holdButton_lastTriggeredMillis = millis();
- }
- else sendKey(_btn, false);
- handleButton_RCx_btnRepeatsCounter = 0;
- handleButton_RCx_btnSlowRepeatsCounter = 0;
- handleButton_RCx_btnMediumRepeatsCounter = 0;
- }
- // REPEAT BUTTON
- else if ((_btn == handleButton_RCx_lastButton) && (_currPrefix == handleButton_RCx_lastPrefix) && _repeatMode) {
- if (handleButton_RCx_btnRepeatsCounter >= handleButton_RCx_ignoreFirstRepeats) {
- if (handleButton_RCx_btnSlowRepeatsCounter == 0) {
- handleButton_RCx_btnSlowRepeatsCounter++;
- handleButton_RCx_btnSlowRepeatsCounter2 = 0;
- if (debug2) {
- Serial.print(F("RCx BUTTON REPEAT SLOW #"));
- Serial.println(handleButton_RCx_btnSlowRepeatsCounter);
- }
- sendKey(_btn, false);
- }
- else if (handleButton_RCx_btnSlowRepeatsCounter < handleButton_RCx_slowRepeats) {
- if (handleButton_RCx_btnSlowRepeatsCounter2 < handleButton_RCx_slowRepeatsNumFastRepeats) {
- handleButton_RCx_btnSlowRepeatsCounter2++;
- }
- else {
- handleButton_RCx_btnSlowRepeatsCounter++;
- handleButton_RCx_btnSlowRepeatsCounter2 = 0;
- if (debug2) {
- Serial.print(F("RCx BUTTON REPEAT SLOW #"));
- Serial.println(handleButton_RCx_btnSlowRepeatsCounter);
- }
- sendKey(_btn, false);
- }
- }
- else if (handleButton_RCx_btnMediumRepeatsCounter <= handleButton_RCx_mediumRepeats) {
- if (handleButton_RCx_btnMediumRepeatsCounter2 < handleButton_RCx_mediumRepeatsNumFastRepeats) {
- handleButton_RCx_btnMediumRepeatsCounter2++;
- }
- else {
- handleButton_RCx_btnMediumRepeatsCounter++;
- handleButton_RCx_btnMediumRepeatsCounter2 = 0;
- if (debug2) {
- Serial.print(F("RCx BUTTON REPEAT MEDIUM #"));
- Serial.println(handleButton_RCx_btnMediumRepeatsCounter);
- }
- sendKey(_btn, false);
- }
- }
- else {
- if (debug2) {
- Serial.println(F("RCx BUTTON REPEAT FAST"));
- }
- sendKey(_btn, false);
- }
- }
- handleButton_RCx_btnRepeatsCounter++;
- }
- // HOLD BUTTON
- else if ((_btn == handleButton_RCx_lastButton) && (_currPrefix == handleButton_RCx_lastPrefix) && _holdMode) {
- holdButton_lastTriggeredMillis = millis();
- }
- handleButton_RCx_lastPrefix = _currPrefix;
- handleButton_RCx_lastButton = _btn;
- }
|