annotate include/DigitalToMessage.h @ 519:5406a719910b prerelease

Restored wav files corrupted in 2a8afa6fa118
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 22 Jun 2016 21:38:43 +0100
parents 0e1e0dfe24c5
children
rev   line source
giuliomoro@345 1 /*
giuliomoro@345 2 * DigitalStream.h
giuliomoro@345 3 *
giuliomoro@345 4 * Created on: 7 Jun 2016
giuliomoro@345 5 * Author: giulio
giuliomoro@345 6 */
giuliomoro@345 7
giuliomoro@345 8 #ifndef DIGITALTOMESSAGE_H_
giuliomoro@345 9 #define DIGITALTOMESSAGE_H_
giuliomoro@345 10 #include <Bela.h>
giuliomoro@345 11
giuliomoro@345 12 //class ProcessedDigitalChannel{
giuliomoro@345 13 // ProcessedDigitalChannel(){
giuliomoro@345 14 // digitalToMessageActive = false;
giuliomoro@345 15 // messageToDigitalActive = false;
giuliomoro@345 16 // analogToDigitalActive = false;
giuliomoro@345 17 // };
giuliomoro@345 18 // void processInput(unsigned int bit, uint32_t* array, unsigned int length){
giuliomoro@345 19 // if(digitalToMessageActive){
giuliomoro@345 20 // digitalToMessage.process(bit, array, length);
giuliomoro@345 21 // }
giuliomoro@345 22 // };
giuliomoro@345 23 // void processOutput(unsigned int bit, uint32_t* digitalArray, float* analogArray, unsigned int length){
giuliomoro@345 24 //
giuliomoro@345 25 // }
giuliomoro@345 26 // DigitalToMessage* getDigitalToMessage(){
giuliomoro@345 27 // return digitalToMessage;
giuliomoro@345 28 // }
giuliomoro@345 29 // DigitalToMessage digitalToMessage;
giuliomoro@345 30 // bool digitalToMessageActive;
giuliomoro@345 31 // bool messageToDigitalActive;
giuliomoro@345 32 // bool analogToDigitalActive;
giuliomoro@345 33 //};
giuliomoro@345 34
giuliomoro@345 35 class DigitalToMessage {
giuliomoro@345 36 public:
giuliomoro@345 37 DigitalToMessage();
giuliomoro@345 38 void setCallback(void (*newCallback)(bool, unsigned int, void*), void* arg){
giuliomoro@345 39 callbackArg = arg;
giuliomoro@345 40 stateChangedCallback = newCallback;
giuliomoro@345 41 if(newCallback != NULL){
giuliomoro@345 42 callbackEnabled = true;
giuliomoro@345 43 } else {
giuliomoro@345 44 callbackEnabled = false;
giuliomoro@345 45 }
giuliomoro@345 46 };
giuliomoro@345 47 void process(unsigned int bit, uint32_t* array, unsigned int length){
giuliomoro@345 48 if(callbackEnabled == false){
giuliomoro@345 49 return;
giuliomoro@345 50 }
giuliomoro@345 51 for(unsigned int n = 0 ; n < length; ++n){
giuliomoro@345 52 bool state = ((array[n]) >> (bit)) & 1;
giuliomoro@345 53 if(state != lastState){ //TODO: use debounceLength
giuliomoro@345 54 stateChangedCallback(state, n, callbackArg);
giuliomoro@345 55 }
giuliomoro@345 56 lastState = state;
giuliomoro@345 57 }
giuliomoro@345 58 };
giuliomoro@345 59 void setDebounceLength(unsigned int length);
giuliomoro@345 60 virtual ~DigitalToMessage();
giuliomoro@345 61 private:
giuliomoro@345 62 unsigned int debounceLength;
giuliomoro@345 63 bool callbackEnabled;
giuliomoro@345 64 void* callbackArg;
giuliomoro@345 65 void (*stateChangedCallback)(bool, unsigned int, void*);
giuliomoro@345 66 bool lastState;
giuliomoro@345 67 };
giuliomoro@345 68
giuliomoro@345 69 #endif /* DIGITALTOMESSAGE_H_ */