-
Notifications
You must be signed in to change notification settings - Fork 0
/
cameraSensor.h
142 lines (94 loc) · 2.28 KB
/
cameraSensor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <Arduino.h>
#include <debugLogger.h>
#include <ArduinoJson.h>
#include "announce.h"
#include <queue>
#include <functional>
class baseCamera : public baseThing
{
public:
baseCamera(debugBaseClass*dbg):baseThing(dbg)
{
}
virtual bool InitialisedOk()=0;
virtual int requestFrame()=0;
virtual bool fetchFrame(uint8_t **toHere, size_t *len)=0;
virtual void releaseFrame()=0;
};
#ifdef ARDUINO_ARCH_ESP32
//#include <freertos/include/freertos/semphr.h>
class espCamera : public baseCamera
{
public:
espCamera(debugBaseClass*dbg):baseCamera(dbg)
{
m_qSemaphore=xSemaphoreCreateMutex();
}
virtual void DoWork()
{
if(m_requests.size())
{
// call the front lambda
while(xSemaphoreTake(m_qSemaphore,10)!=true)
yield();
std::function<void(baseCamera*)> fn=m_requests.front();
m_requests.pop();
xSemaphoreGive(m_qSemaphore);
fn(this);
}
}
void AddWork(std::function<void(baseCamera*)> fn)
{
while(xSemaphoreTake(m_qSemaphore,0)!=true)
yield();
m_requests.push(fn);
xSemaphoreGive(m_qSemaphore);
}
protected:
std::queue<std::function<void(baseCamera*)>> m_requests;
SemaphoreHandle_t m_qSemaphore;
};
class fakeCamera : public espCamera
{
public:
fakeCamera(debugBaseClass*dbg):espCamera(dbg)
{
thingName="fakeCamera";
}
virtual bool InitialisedOk()
{
return true;
}
virtual int requestFrame();
virtual bool fetchFrame(uint8_t **toHere, size_t *len);
};
#include "esp_camera.h"
class esp32Cam:public espCamera
{
public:
esp32Cam(debugBaseClass*dbg):espCamera(dbg),m_frameBuffer(NULL)
{
thingName="esp32Cam";
m_initErr=initialiseCam();
}
virtual bool InitialisedOk()
{
return m_initErr==ESP_OK;
}
virtual int requestFrame();
virtual bool fetchFrame(uint8_t **toHere, size_t *len);
void releaseFrame()
{
if(m_frameBuffer)
{
esp_camera_fb_return(m_frameBuffer);
m_frameBuffer=NULL;
}
}
protected:
esp_err_t initialiseCam();
esp_err_t m_initErr;
private:
camera_fb_t *m_frameBuffer;
};
#endif