Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
DigitalToMessage.h
1 /*
2  * DigitalStream.h
3  *
4  * Created on: 7 Jun 2016
5  * Author: giulio
6  */
7 
8 #ifndef DIGITALTOMESSAGE_H_
9 #define DIGITALTOMESSAGE_H_
10 #include <Bela.h>
11 
12 //class ProcessedDigitalChannel{
13 // ProcessedDigitalChannel(){
14 // digitalToMessageActive = false;
15 // messageToDigitalActive = false;
16 // analogToDigitalActive = false;
17 // };
18 // void processInput(unsigned int bit, uint32_t* array, unsigned int length){
19 // if(digitalToMessageActive){
20 // digitalToMessage.process(bit, array, length);
21 // }
22 // };
23 // void processOutput(unsigned int bit, uint32_t* digitalArray, float* analogArray, unsigned int length){
24 //
25 // }
26 // DigitalToMessage* getDigitalToMessage(){
27 // return digitalToMessage;
28 // }
29 // DigitalToMessage digitalToMessage;
30 // bool digitalToMessageActive;
31 // bool messageToDigitalActive;
32 // bool analogToDigitalActive;
33 //};
34 
36 public:
38  void setCallback(void (*newCallback)(bool, unsigned int, void*), void* arg){
39  callbackArg = arg;
40  stateChangedCallback = newCallback;
41  if(newCallback != NULL){
42  callbackEnabled = true;
43  } else {
44  callbackEnabled = false;
45  }
46  };
47  void process(unsigned int bit, uint32_t* array, unsigned int length){
48  if(callbackEnabled == false){
49  return;
50  }
51  for(unsigned int n = 0 ; n < length; ++n){
52  bool state = ((array[n]) >> (bit)) & 1;
53  if(state != lastState){ //TODO: use debounceLength
54  stateChangedCallback(state, n, callbackArg);
55  }
56  lastState = state;
57  }
58  };
59  void setDebounceLength(unsigned int length);
60  virtual ~DigitalToMessage();
61 private:
62  unsigned int debounceLength;
63  bool callbackEnabled;
64  void* callbackArg;
65  void (*stateChangedCallback)(bool, unsigned int, void*);
66  bool lastState;
67 };
68 
69 #endif /* DIGITALTOMESSAGE_H_ */
Definition: DigitalToMessage.h:35
Main Bela public API.