Arduino LibHelix

HelixCommon.h
1 #pragma once
2
3 #ifndef MIN
4 #define MIN(a < b ? a : b)
5 #endif
6
7 // Activate/Deactivate logging
8 #define LOGGING_ACTIVE true
9
10 #if LOGGING_ACTIVE == true
11 static char log_buffer[120];
12 #define LOG(...) { sprintf(log_buffer,__VA_ARGS__); Serial.println(log_buffer); }
13 #endif;
14
15
16 class CommonHelix : public CommonHelix {
17 public:
22 int begin(){
23 first = true;
24 active = true;
25 }
26
28 void end(){
29 active = false;
30 }
31
33 virtual size_t write(const void *in_ptr, size_t in_size) {
34 if (active){
35 LOG("write %d",in_size);
36 int start = 0;
37 int end = 0;
38 int len = MIN(in_size, AAC_MAX_FRAME_SIZE);
39 size_t result_size=0;
40 // we can not write more then the AAC_MAX_FRAME_SIZE
41 while(result_size<in_size){
42 result_size += writeFrame(in_ptr+start, len);
43 start+=result_size;
44 len = MIN(in_size - start, AAC_MAX_FRAME_SIZE);
45 }
46 }
47 }
48
50 operator bool() {
51 return active;
52 }
53
54 protected:
55 boolean first = true;
56 boolean active = false;
57 Print *out = nullptr;
58 Stream *in = nullptr;
59
60 virtual size_t writeFrame(const void *in_ptr, size_t in_size);
61
62
63 };
CommonHelix
Definition: HelixCommon.h:16
CommonHelix::write
virtual size_t write(const void *in_ptr, size_t in_size)
decodes the next segment from the intput to the output stream. To be called in the Arduino Loop
Definition: HelixCommon.h:33
CommonHelix::end
void end()
Releases the reserved memory.
Definition: HelixCommon.h:28
CommonHelix::begin
int begin()
Starts the processing.
Definition: HelixCommon.h:22