From 5a857ffa118728b4728562b6d0d96e56f70914dc Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Thu, 23 May 2024 09:27:31 +0200 Subject: [PATCH 1/4] use same names for input and output shifters --- src/MF_InputShifter/InputShifter.cpp | 28 ++++++++++++------------ src/MF_InputShifter/InputShifter.h | 1 - src/MF_InputShifter/MFInputShifter.cpp | 24 ++++++++++---------- src/MF_InputShifter/MFInputShifter.h | 2 +- src/MF_OutputShifter/MFOutputShifter.cpp | 8 +++---- src/MF_OutputShifter/MFOutputShifter.h | 2 +- src/MF_OutputShifter/OutputShifter.cpp | 12 +++++----- 7 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/MF_InputShifter/InputShifter.cpp b/src/MF_InputShifter/InputShifter.cpp index 143f9250..84e3deb4 100644 --- a/src/MF_InputShifter/InputShifter.cpp +++ b/src/MF_InputShifter/InputShifter.cpp @@ -10,8 +10,8 @@ namespace InputShifter { - MFInputShifter *inputShifters; - uint8_t inputShiftersRegistered = 0; + MFInputShifter *inputShifter; + uint8_t inputShifterRegistered = 0; uint8_t maxInputShifter = 0; void handlerInputShifterOnChange(uint8_t eventId, uint8_t pin, const char *name) @@ -27,23 +27,23 @@ namespace InputShifter { if (!FitInMemory(sizeof(MFInputShifter) * count)) return false; - inputShifters = new (allocateMemory(sizeof(MFInputShifter) * count)) MFInputShifter; + inputShifter = new (allocateMemory(sizeof(MFInputShifter) * count)) MFInputShifter; maxInputShifter = count; return true; } void Add(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t modules, char const *name) { - if (inputShiftersRegistered == maxInputShifter) + if (inputShifterRegistered == maxInputShifter) return; - inputShifters[inputShiftersRegistered] = MFInputShifter(); - if (!inputShifters[inputShiftersRegistered].attach(latchPin, clockPin, dataPin, modules, name)) + inputShifter[inputShifterRegistered] = MFInputShifter(); + if (!inputShifter[inputShifterRegistered].attach(latchPin, clockPin, dataPin, modules, name)) { cmdMessenger.sendCmd(kStatus, F("InputShifter array does not fit into Memory")); return; } MFInputShifter::attachHandler(handlerInputShifterOnChange); - inputShiftersRegistered++; + inputShifterRegistered++; #ifdef DEBUG2CMDMESSENGER cmdMessenger.sendCmd(kDebug, F("Added input shifter")); #endif @@ -51,10 +51,10 @@ namespace InputShifter void Clear() { - for (uint8_t i = 0; i < inputShiftersRegistered; i++) { - inputShifters[i].detach(); + for (uint8_t i = 0; i < inputShifterRegistered; i++) { + inputShifter[i].detach(); } - inputShiftersRegistered = 0; + inputShifterRegistered = 0; #ifdef DEBUG2CMDMESSENGER cmdMessenger.sendCmd(kDebug, F("Cleared input shifter")); #endif @@ -62,8 +62,8 @@ namespace InputShifter void read() { - for (uint8_t i = 0; i < inputShiftersRegistered; i++) { - inputShifters[i].update(); + for (uint8_t i = 0; i < inputShifterRegistered; i++) { + inputShifter[i].update(); } } @@ -71,8 +71,8 @@ namespace InputShifter { // Retrigger all the input shifters. This automatically sends // the release events first followed by press events. - for (uint8_t i = 0; i < inputShiftersRegistered; i++) { - inputShifters[i].retrigger(); + for (uint8_t i = 0; i < inputShifterRegistered; i++) { + inputShifter[i].retrigger(); } } diff --git a/src/MF_InputShifter/InputShifter.h b/src/MF_InputShifter/InputShifter.h index 51b06031..0efb1c7c 100644 --- a/src/MF_InputShifter/InputShifter.h +++ b/src/MF_InputShifter/InputShifter.h @@ -5,7 +5,6 @@ // #pragma once -#include namespace InputShifter { diff --git a/src/MF_InputShifter/MFInputShifter.cpp b/src/MF_InputShifter/MFInputShifter.cpp index 8703eb85..8edb3945 100644 --- a/src/MF_InputShifter/MFInputShifter.cpp +++ b/src/MF_InputShifter/MFInputShifter.cpp @@ -31,9 +31,9 @@ bool MFInputShifter::attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, if (!FitInMemory(sizeof(uint8_t) * _moduleCount)) return false; - _lastState = new (allocateMemory(sizeof(uint8_t) * _moduleCount)) uint8_t; + _inputBuffer = new (allocateMemory(sizeof(uint8_t) * _moduleCount)) uint8_t; for (uint8_t i = 0; i < _moduleCount; i++) { - _lastState[i] = 0; + _inputBuffer[i] = 0; } _initialized = true; @@ -43,6 +43,11 @@ bool MFInputShifter::attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, return true; } +void MFInputShifter::detach() +{ + _initialized = false; +} + // Reads the values from the attached modules, compares them to the previously // read values, and calls the registered event handler for any inputs that // changed from the previously read state. @@ -65,9 +70,9 @@ void MFInputShifter::poll(uint8_t doTrigger) // If an input changed on the current module from the last time it was read // then hand it off to figure out which bits specifically changed. - if (currentState != _lastState[module]) { - if (doTrigger) detectChanges(_lastState[module], currentState, module); - _lastState[module] = currentState; + if (currentState != _inputBuffer[module]) { + if (doTrigger) detectChanges(_inputBuffer[module], currentState, module); + _inputBuffer[module] = currentState; } } @@ -104,7 +109,7 @@ void MFInputShifter::retrigger() // Trigger all the released buttons for (int module = 0; module < _moduleCount; module++) { - state = _lastState[module]; + state = _inputBuffer[module]; for (uint8_t i = 0; i < 8; i++) { // Only trigger if the button is in the off position if (state & 1) { @@ -116,7 +121,7 @@ void MFInputShifter::retrigger() // Trigger all the pressed buttons for (int module = 0; module < _moduleCount; module++) { - state = _lastState[module]; + state = _inputBuffer[module]; for (uint8_t i = 0; i < 8; i++) { // Only trigger if the button is in the on position if (!(state & 1)) { @@ -142,9 +147,4 @@ void MFInputShifter::attachHandler(inputShifterEvent newHandler) _inputHandler = newHandler; } -void MFInputShifter::detach() -{ - _initialized = false; -} - // MFInputShifter.cpp diff --git a/src/MF_InputShifter/MFInputShifter.h b/src/MF_InputShifter/MFInputShifter.h index 5c7405e6..d7a84140 100644 --- a/src/MF_InputShifter/MFInputShifter.h +++ b/src/MF_InputShifter/MFInputShifter.h @@ -38,7 +38,7 @@ class MFInputShifter uint8_t _dataPin; // SDO (data) pin uint8_t _moduleCount; // Number of 8 bit modules in series. bool _initialized = false; - uint8_t *_lastState; + uint8_t *_inputBuffer; void poll(uint8_t doTrigger); void detectChanges(uint8_t lastState, uint8_t currentState, uint8_t module); diff --git a/src/MF_OutputShifter/MFOutputShifter.cpp b/src/MF_OutputShifter/MFOutputShifter.cpp index 5ac264dd..91bae05c 100644 --- a/src/MF_OutputShifter/MFOutputShifter.cpp +++ b/src/MF_OutputShifter/MFOutputShifter.cpp @@ -24,7 +24,7 @@ void MFOutputShifter::setPin(uint8_t pin, uint8_t value, uint8_t refresh) } else { _outputBuffer[idx] &= ~msk; } - if (refresh) updateShiftRegister(); + if (refresh) update(); } void MFOutputShifter::setPins(char *pins, uint8_t value) @@ -37,7 +37,7 @@ void MFOutputShifter::setPins(char *pins, uint8_t value) setPin(num, value, 0); pinTokens = strtok(0, "|"); } - updateShiftRegister(); + update(); } bool MFOutputShifter::attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount) @@ -72,10 +72,10 @@ void MFOutputShifter::clear() for (uint8_t i = 0; i < _moduleCount; i++) { _outputBuffer[i] = 0xFF * MF_LOW; } - updateShiftRegister(); + update(); } -void MFOutputShifter::updateShiftRegister() +void MFOutputShifter::update() { digitalWrite(_latchPin, LOW); for (uint8_t i = _moduleCount; i > 0; i--) { diff --git a/src/MF_OutputShifter/MFOutputShifter.h b/src/MF_OutputShifter/MFOutputShifter.h index b69f601d..a36b0784 100644 --- a/src/MF_OutputShifter/MFOutputShifter.h +++ b/src/MF_OutputShifter/MFOutputShifter.h @@ -25,7 +25,7 @@ class MFOutputShifter bool attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount); void detach(); void clear(); - void updateShiftRegister(); + void update(); private: uint8_t _latchPin; // Latch pin diff --git a/src/MF_OutputShifter/OutputShifter.cpp b/src/MF_OutputShifter/OutputShifter.cpp index 2c34d25e..34305c5a 100644 --- a/src/MF_OutputShifter/OutputShifter.cpp +++ b/src/MF_OutputShifter/OutputShifter.cpp @@ -10,7 +10,7 @@ namespace OutputShifter { - MFOutputShifter *outputShifters; + MFOutputShifter *outputShifter; uint8_t outputShifterRegistered = 0; uint8_t maxOutputShifter = 0; @@ -18,7 +18,7 @@ namespace OutputShifter { if (!FitInMemory(sizeof(MFOutputShifter) * count)) return false; - outputShifters = new (allocateMemory(sizeof(MFOutputShifter) * count)) MFOutputShifter; + outputShifter = new (allocateMemory(sizeof(MFOutputShifter) * count)) MFOutputShifter; maxOutputShifter = count; return true; } @@ -27,8 +27,8 @@ namespace OutputShifter { if (outputShifterRegistered == maxOutputShifter) return; - outputShifters[outputShifterRegistered] = MFOutputShifter(); - if (!outputShifters[outputShifterRegistered].attach(latchPin, clockPin, dataPin, modules)) + outputShifter[outputShifterRegistered] = MFOutputShifter(); + if (!outputShifter[outputShifterRegistered].attach(latchPin, clockPin, dataPin, modules)) { cmdMessenger.sendCmd(kStatus, F("OutputShifter array does not fit into Memory")); return; @@ -43,7 +43,7 @@ namespace OutputShifter void Clear() { for (uint8_t i = 0; i < outputShifterRegistered; i++) { - outputShifters[i].detach(); + outputShifter[i].detach(); } outputShifterRegistered = 0; @@ -58,7 +58,7 @@ namespace OutputShifter int module = cmdMessenger.readInt16Arg(); char *pins = cmdMessenger.readStringArg(); int value = cmdMessenger.readInt16Arg(); - outputShifters[module].setPins(pins, value); + outputShifter[module].setPins(pins, value); } } // namespace From 8381b101fa1a6bf656b8587b5c29f255e169ee6d Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Thu, 23 May 2024 09:30:19 +0200 Subject: [PATCH 2/4] delete not required function declaration --- src/MF_InputShifter/MFInputShifter.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MF_InputShifter/MFInputShifter.h b/src/MF_InputShifter/MFInputShifter.h index d7a84140..1c42e2f3 100644 --- a/src/MF_InputShifter/MFInputShifter.h +++ b/src/MF_InputShifter/MFInputShifter.h @@ -23,7 +23,6 @@ class MFInputShifter MFInputShifter(); bool attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount, const char *name); static void attachHandler(inputShifterEvent newHandler); - void clear(); void detach(); void retrigger(); void update(); From 3c57729df9606d18bf5f60548967a2ea88a22c93 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Thu, 23 May 2024 10:04:04 +0200 Subject: [PATCH 3/4] same names and functions for buttons and input shifters --- src/MF_Button/Button.cpp | 7 +++- src/MF_Button/MFButton.cpp | 21 ++++++---- src/MF_Button/MFButton.h | 10 +++-- src/MF_InputShifter/InputShifter.cpp | 11 ++++-- src/MF_InputShifter/MFInputShifter.cpp | 53 +++++++++++++++----------- src/MF_InputShifter/MFInputShifter.h | 14 ++++--- 6 files changed, 71 insertions(+), 45 deletions(-) diff --git a/src/MF_Button/Button.cpp b/src/MF_Button/Button.cpp index faac049d..5fa39def 100644 --- a/src/MF_Button/Button.cpp +++ b/src/MF_Button/Button.cpp @@ -14,7 +14,7 @@ namespace Button uint8_t buttonsRegistered = 0; uint8_t maxButtons = 0; - void handlerOnButton(uint8_t eventId, const char *name) + void handlerButtonOnChange(uint8_t eventId, const char *name) { cmdMessenger.sendCmdStart(kButtonChange); cmdMessenger.sendCmdArg(name); @@ -37,7 +37,7 @@ namespace Button return; buttons[buttonsRegistered] = MFButton(); buttons[buttonsRegistered].attach(pin, name); - MFButton::attachHandler(handlerOnButton); + MFButton::attachHandler(handlerButtonOnChange); buttonsRegistered++; #ifdef DEBUG2CMDMESSENGER cmdMessenger.sendCmd(kDebug, F("Added button ") /* + name */); @@ -46,6 +46,9 @@ namespace Button void Clear(void) { + for (uint8_t i = 0; i < buttonsRegistered; i++) { + buttons[i].detach(); + } buttonsRegistered = 0; #ifdef DEBUG2CMDMESSENGER cmdMessenger.sendCmd(kDebug, F("Cleared buttons")); diff --git a/src/MF_Button/MFButton.cpp b/src/MF_Button/MFButton.cpp index 561f154a..d51adb17 100644 --- a/src/MF_Button/MFButton.cpp +++ b/src/MF_Button/MFButton.cpp @@ -5,7 +5,7 @@ // #include "MFButton.h" -buttonEvent MFButton::_handler = NULL; +buttonEvent MFButton::_inputHandler = NULL; MFButton::MFButton() { @@ -16,11 +16,16 @@ void MFButton::attach(uint8_t pin, const char *name) { _pin = pin; _name = name; - pinMode(_pin, INPUT_PULLUP); // set pin to input - _state = digitalRead(_pin); // initialize on actual status + pinMode(_pin, INPUT_PULLUP); // set pin to input + _state = digitalRead(_pin); // initialize on actual status _initialized = true; } +void MFButton::detach() +{ + _initialized = false; +} + void MFButton::update() { if (!_initialized) @@ -41,8 +46,8 @@ void MFButton::triggerOnPress() { if (!_initialized) return; - if (_handler && _state == LOW) { - (*_handler)(btnOnPress, _name); + if (_inputHandler && _state == LOW) { + (*_inputHandler)(btnOnPress, _name); } } @@ -50,14 +55,14 @@ void MFButton::triggerOnRelease() { if (!_initialized) return; - if (_handler && _state == HIGH) { - (*_handler)(btnOnRelease, _name); + if (_inputHandler && _state == HIGH) { + (*_inputHandler)(btnOnRelease, _name); } } void MFButton::attachHandler(buttonEvent newHandler) { - _handler = newHandler; + _inputHandler = newHandler; } // MFButton.cpp \ No newline at end of file diff --git a/src/MF_Button/MFButton.h b/src/MF_Button/MFButton.h index 69920046..e7342718 100644 --- a/src/MF_Button/MFButton.h +++ b/src/MF_Button/MFButton.h @@ -26,17 +26,19 @@ class MFButton MFButton(); static void attachHandler(buttonEvent newHandler); void attach(uint8_t pin, const char *name); + void detach(); void update(); void trigger(uint8_t state); void triggerOnPress(); void triggerOnRelease(); + +private: const char *_name; uint8_t _pin; + bool _initialized; + bool _state; -private: - static buttonEvent _handler; - bool _state; - bool _initialized; + static buttonEvent _inputHandler; }; // MFButton.h \ No newline at end of file diff --git a/src/MF_InputShifter/InputShifter.cpp b/src/MF_InputShifter/InputShifter.cpp index 84e3deb4..50671ac5 100644 --- a/src/MF_InputShifter/InputShifter.cpp +++ b/src/MF_InputShifter/InputShifter.cpp @@ -37,8 +37,7 @@ namespace InputShifter if (inputShifterRegistered == maxInputShifter) return; inputShifter[inputShifterRegistered] = MFInputShifter(); - if (!inputShifter[inputShifterRegistered].attach(latchPin, clockPin, dataPin, modules, name)) - { + if (!inputShifter[inputShifterRegistered].attach(latchPin, clockPin, dataPin, modules, name)) { cmdMessenger.sendCmd(kStatus, F("InputShifter array does not fit into Memory")); return; } @@ -71,8 +70,14 @@ namespace InputShifter { // Retrigger all the input shifters. This automatically sends // the release events first followed by press events. + + // Trigger all button release events first... + for (uint8_t i = 0; i < inputShifterRegistered; i++) { + inputShifter[i].triggerOnRelease(); + } + // ... then trigger all the press events for (uint8_t i = 0; i < inputShifterRegistered; i++) { - inputShifter[i].retrigger(); + inputShifter[i].triggerOnPress(); } } diff --git a/src/MF_InputShifter/MFInputShifter.cpp b/src/MF_InputShifter/MFInputShifter.cpp index 8edb3945..6d625b1d 100644 --- a/src/MF_InputShifter/MFInputShifter.cpp +++ b/src/MF_InputShifter/MFInputShifter.cpp @@ -30,7 +30,7 @@ bool MFInputShifter::attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, if (!FitInMemory(sizeof(uint8_t) * _moduleCount)) return false; - + _inputBuffer = new (allocateMemory(sizeof(uint8_t) * _moduleCount)) uint8_t; for (uint8_t i = 0; i < _moduleCount; i++) { _inputBuffer[i] = 0; @@ -98,27 +98,22 @@ void MFInputShifter::detectChanges(uint8_t lastState, uint8_t currentState, uint } } -// Reads the current state for all connected modules then fires -// release events for every released button followed by -// press events for every pressed button. -void MFInputShifter::retrigger() +// Triggers the event handler for the associated input shift register pin, +// if a handler is registered. +void MFInputShifter::trigger(uint8_t pin, bool state) { + (*_inputHandler)((state == LOW ? inputShifterOnPress : inputShifterOnRelease), pin, _name); +} + +void MFInputShifter::triggerOnPress() +{ + if (!_initialized || !_inputHandler) + return; + uint8_t state; poll(DONT_TRIGGER); - // Trigger all the released buttons - for (int module = 0; module < _moduleCount; module++) { - state = _inputBuffer[module]; - for (uint8_t i = 0; i < 8; i++) { - // Only trigger if the button is in the off position - if (state & 1) { - trigger(i + (module * 8), HIGH); - } - state = state >> 1; - } - } - // Trigger all the pressed buttons for (int module = 0; module < _moduleCount; module++) { state = _inputBuffer[module]; @@ -133,12 +128,26 @@ void MFInputShifter::retrigger() } } -// Triggers the event handler for the associated input shift register pin, -// if a handler is registered. -void MFInputShifter::trigger(uint8_t pin, bool state) +void MFInputShifter::triggerOnRelease() { - if (!_inputHandler) return; - (*_inputHandler)((state == LOW ? inputShifterOnPress : inputShifterOnRelease), pin, _name); + if (!_initialized || !_inputHandler) + return; + + uint8_t state; + + poll(DONT_TRIGGER); + + // Trigger all the released buttons + for (int module = 0; module < _moduleCount; module++) { + state = _inputBuffer[module]; + for (uint8_t i = 0; i < 8; i++) { + // Only trigger if the button is in the off position + if (state & 1) { + trigger(i + (module * 8), HIGH); + } + state = state >> 1; + } + } } // Attaches a new event handler for the specified event. diff --git a/src/MF_InputShifter/MFInputShifter.h b/src/MF_InputShifter/MFInputShifter.h index 1c42e2f3..1b5c650b 100644 --- a/src/MF_InputShifter/MFInputShifter.h +++ b/src/MF_InputShifter/MFInputShifter.h @@ -21,11 +21,12 @@ class MFInputShifter { public: MFInputShifter(); - bool attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount, const char *name); static void attachHandler(inputShifterEvent newHandler); + bool attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t moduleCount, const char *name); void detach(); - void retrigger(); void update(); + void triggerOnPress(); + void triggerOnRelease(); private: enum { DONT_TRIGGER = 0, @@ -37,11 +38,12 @@ class MFInputShifter uint8_t _dataPin; // SDO (data) pin uint8_t _moduleCount; // Number of 8 bit modules in series. bool _initialized = false; - uint8_t *_inputBuffer; + uint8_t *_inputBuffer; + + void poll(uint8_t doTrigger); + void detectChanges(uint8_t lastState, uint8_t currentState, uint8_t module); + void trigger(uint8_t pin, bool state); - void poll(uint8_t doTrigger); - void detectChanges(uint8_t lastState, uint8_t currentState, uint8_t module); - void trigger(uint8_t pin, bool state); static inputShifterEvent _inputHandler; }; From 9fc3de1eedc0a18effc9e7c78172d1c2311ca0de Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 27 May 2024 22:13:41 +0200 Subject: [PATCH 4/4] common name for buffers --- src/MF_InputShifter/MFInputShifter.cpp | 14 +++++++------- src/MF_InputShifter/MFInputShifter.h | 2 +- src/MF_OutputShifter/MFOutputShifter.cpp | 10 +++++----- src/MF_OutputShifter/MFOutputShifter.h | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/MF_InputShifter/MFInputShifter.cpp b/src/MF_InputShifter/MFInputShifter.cpp index 6d625b1d..d8bdfb9c 100644 --- a/src/MF_InputShifter/MFInputShifter.cpp +++ b/src/MF_InputShifter/MFInputShifter.cpp @@ -31,9 +31,9 @@ bool MFInputShifter::attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, if (!FitInMemory(sizeof(uint8_t) * _moduleCount)) return false; - _inputBuffer = new (allocateMemory(sizeof(uint8_t) * _moduleCount)) uint8_t; + _lastState = new (allocateMemory(sizeof(uint8_t) * _moduleCount)) uint8_t; for (uint8_t i = 0; i < _moduleCount; i++) { - _inputBuffer[i] = 0; + _lastState[i] = 0; } _initialized = true; @@ -70,9 +70,9 @@ void MFInputShifter::poll(uint8_t doTrigger) // If an input changed on the current module from the last time it was read // then hand it off to figure out which bits specifically changed. - if (currentState != _inputBuffer[module]) { - if (doTrigger) detectChanges(_inputBuffer[module], currentState, module); - _inputBuffer[module] = currentState; + if (currentState != _lastState[module]) { + if (doTrigger) detectChanges(_lastState[module], currentState, module); + _lastState[module] = currentState; } } @@ -116,7 +116,7 @@ void MFInputShifter::triggerOnPress() // Trigger all the pressed buttons for (int module = 0; module < _moduleCount; module++) { - state = _inputBuffer[module]; + state = _lastState[module]; for (uint8_t i = 0; i < 8; i++) { // Only trigger if the button is in the on position if (!(state & 1)) { @@ -139,7 +139,7 @@ void MFInputShifter::triggerOnRelease() // Trigger all the released buttons for (int module = 0; module < _moduleCount; module++) { - state = _inputBuffer[module]; + state = _lastState[module]; for (uint8_t i = 0; i < 8; i++) { // Only trigger if the button is in the off position if (state & 1) { diff --git a/src/MF_InputShifter/MFInputShifter.h b/src/MF_InputShifter/MFInputShifter.h index 1b5c650b..287e109e 100644 --- a/src/MF_InputShifter/MFInputShifter.h +++ b/src/MF_InputShifter/MFInputShifter.h @@ -38,7 +38,7 @@ class MFInputShifter uint8_t _dataPin; // SDO (data) pin uint8_t _moduleCount; // Number of 8 bit modules in series. bool _initialized = false; - uint8_t *_inputBuffer; + uint8_t *_lastState; void poll(uint8_t doTrigger); void detectChanges(uint8_t lastState, uint8_t currentState, uint8_t module); diff --git a/src/MF_OutputShifter/MFOutputShifter.cpp b/src/MF_OutputShifter/MFOutputShifter.cpp index 91bae05c..c4d827e8 100644 --- a/src/MF_OutputShifter/MFOutputShifter.cpp +++ b/src/MF_OutputShifter/MFOutputShifter.cpp @@ -20,9 +20,9 @@ void MFOutputShifter::setPin(uint8_t pin, uint8_t value, uint8_t refresh) uint8_t msk = (0x01 << (pin & 0x07)); if (value != MF_LOW) { - _outputBuffer[idx] |= msk; + _lastState[idx] |= msk; } else { - _outputBuffer[idx] &= ~msk; + _lastState[idx] &= ~msk; } if (refresh) update(); } @@ -55,7 +55,7 @@ bool MFOutputShifter::attach(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin if (!FitInMemory(sizeof(uint8_t) * _moduleCount)) return false; - _outputBuffer = new (allocateMemory(sizeof(uint8_t) * _moduleCount)) uint8_t; + _lastState = new (allocateMemory(sizeof(uint8_t) * _moduleCount)) uint8_t; clear(); @@ -70,7 +70,7 @@ void MFOutputShifter::detach() void MFOutputShifter::clear() { for (uint8_t i = 0; i < _moduleCount; i++) { - _outputBuffer[i] = 0xFF * MF_LOW; + _lastState[i] = 0xFF * MF_LOW; } update(); } @@ -79,7 +79,7 @@ void MFOutputShifter::update() { digitalWrite(_latchPin, LOW); for (uint8_t i = _moduleCount; i > 0; i--) { - shiftOut(_dataPin, _clockPin, MSBFIRST, _outputBuffer[i - 1]); // LSBFIRST, MSBFIRST, + shiftOut(_dataPin, _clockPin, MSBFIRST, _lastState[i - 1]); // LSBFIRST, MSBFIRST, } digitalWrite(_latchPin, HIGH); } diff --git a/src/MF_OutputShifter/MFOutputShifter.h b/src/MF_OutputShifter/MFOutputShifter.h index a36b0784..5f8ea737 100644 --- a/src/MF_OutputShifter/MFOutputShifter.h +++ b/src/MF_OutputShifter/MFOutputShifter.h @@ -32,7 +32,7 @@ class MFOutputShifter uint8_t _clockPin; // Clock pin uint8_t _dataPin; // Data/SI pin uint8_t _moduleCount; // Number of 8 bit modules in series. For a shift register with 16 bit one needs to select 2 modules a 8...... - uint8_t *_outputBuffer; + uint8_t *_lastState; bool _initialized = false; };