giuliomoro@345: /* giuliomoro@345: * DigitalStream.h giuliomoro@345: * giuliomoro@345: * Created on: 7 Jun 2016 giuliomoro@345: * Author: giulio giuliomoro@345: */ giuliomoro@345: giuliomoro@345: #ifndef DIGITALTOMESSAGE_H_ giuliomoro@345: #define DIGITALTOMESSAGE_H_ giuliomoro@345: #include giuliomoro@345: giuliomoro@345: //class ProcessedDigitalChannel{ giuliomoro@345: // ProcessedDigitalChannel(){ giuliomoro@345: // digitalToMessageActive = false; giuliomoro@345: // messageToDigitalActive = false; giuliomoro@345: // analogToDigitalActive = false; giuliomoro@345: // }; giuliomoro@345: // void processInput(unsigned int bit, uint32_t* array, unsigned int length){ giuliomoro@345: // if(digitalToMessageActive){ giuliomoro@345: // digitalToMessage.process(bit, array, length); giuliomoro@345: // } giuliomoro@345: // }; giuliomoro@345: // void processOutput(unsigned int bit, uint32_t* digitalArray, float* analogArray, unsigned int length){ giuliomoro@345: // giuliomoro@345: // } giuliomoro@345: // DigitalToMessage* getDigitalToMessage(){ giuliomoro@345: // return digitalToMessage; giuliomoro@345: // } giuliomoro@345: // DigitalToMessage digitalToMessage; giuliomoro@345: // bool digitalToMessageActive; giuliomoro@345: // bool messageToDigitalActive; giuliomoro@345: // bool analogToDigitalActive; giuliomoro@345: //}; giuliomoro@345: giuliomoro@345: class DigitalToMessage { giuliomoro@345: public: giuliomoro@345: DigitalToMessage(); giuliomoro@345: void setCallback(void (*newCallback)(bool, unsigned int, void*), void* arg){ giuliomoro@345: callbackArg = arg; giuliomoro@345: stateChangedCallback = newCallback; giuliomoro@345: if(newCallback != NULL){ giuliomoro@345: callbackEnabled = true; giuliomoro@345: } else { giuliomoro@345: callbackEnabled = false; giuliomoro@345: } giuliomoro@345: }; giuliomoro@345: void process(unsigned int bit, uint32_t* array, unsigned int length){ giuliomoro@345: if(callbackEnabled == false){ giuliomoro@345: return; giuliomoro@345: } giuliomoro@345: for(unsigned int n = 0 ; n < length; ++n){ giuliomoro@345: bool state = ((array[n]) >> (bit)) & 1; giuliomoro@345: if(state != lastState){ //TODO: use debounceLength giuliomoro@345: stateChangedCallback(state, n, callbackArg); giuliomoro@345: } giuliomoro@345: lastState = state; giuliomoro@345: } giuliomoro@345: }; giuliomoro@345: void setDebounceLength(unsigned int length); giuliomoro@345: virtual ~DigitalToMessage(); giuliomoro@345: private: giuliomoro@345: unsigned int debounceLength; giuliomoro@345: bool callbackEnabled; giuliomoro@345: void* callbackArg; giuliomoro@345: void (*stateChangedCallback)(bool, unsigned int, void*); giuliomoro@345: bool lastState; giuliomoro@345: }; giuliomoro@345: giuliomoro@345: #endif /* DIGITALTOMESSAGE_H_ */