comparison include/DigitalToMessage.h @ 345:0e1e0dfe24c5 prerelease

Added embryonal support for digital messages with libpd. TODO: test it, only process used channels, add defines. It is quite CPU-intensive
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 07 Jun 2016 03:40:01 +0100
parents
children
comparison
equal deleted inserted replaced
344:1c35a5d0ce32 345:0e1e0dfe24c5
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
35 class DigitalToMessage {
36 public:
37 DigitalToMessage();
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_ */