Skip to content

Commit e9b0044

Browse files
motion detection
1 parent b7859bd commit e9b0044

21 files changed

+1208
-0
lines changed

src/eloquent/io/json.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//
2+
// Created by Simone on 17/03/2022.
3+
//
4+
5+
#pragma once
6+
7+
#include "./json/JsonEncoder.h"

src/eloquent/io/json/JsonEncoder.h

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
//
2+
// Created by Simone on 17/03/2022.
3+
//
4+
5+
#pragma once
6+
7+
8+
namespace Eloquent {
9+
namespace IO {
10+
namespace Json {
11+
12+
/**
13+
* Encode data to JSON to the given stream
14+
*
15+
* @tparam Stream
16+
*/
17+
template<class Stream>
18+
class JsonEncoder {
19+
public:
20+
21+
/**
22+
*
23+
* @param stream
24+
*/
25+
JsonEncoder(Stream &stream) : _stream(&stream) {
26+
27+
}
28+
29+
/**
30+
* Print object opening
31+
*/
32+
void openObject() {
33+
print('{');
34+
}
35+
36+
/**
37+
* Print object closing
38+
*
39+
* @param addNewLine
40+
*/
41+
void closeObject(bool addNewLine = true) {
42+
print('}');
43+
44+
if (addNewLine)
45+
print('\n');
46+
}
47+
48+
/**
49+
* Print attributes separator
50+
*/
51+
void then() {
52+
print(',');
53+
}
54+
55+
/**
56+
* Encode float
57+
*
58+
* @param key
59+
* @param value
60+
* @param precision
61+
*/
62+
void encode(const char *key, float value, uint8_t precision = 3) {
63+
encode_key(key);
64+
print(value, precision);
65+
}
66+
67+
/**
68+
* Encode int
69+
*
70+
* @param key
71+
* @param value
72+
*/
73+
void encode(const char *key, int value) {
74+
encode_key(key);
75+
print(value);
76+
}
77+
78+
/**
79+
* Encode string
80+
*
81+
* @param key
82+
* @param value
83+
*/
84+
void encode(const char *key, String value) {
85+
encode_key(key);
86+
quote(value);
87+
}
88+
89+
/**
90+
*
91+
* @tparam T
92+
* @param key
93+
* @param array
94+
* @param length
95+
*/
96+
template<typename T>
97+
void encode(const char *key, T *array, uint16_t length) {
98+
encode_key(key);
99+
print('[');
100+
101+
for (uint16_t i = 0; i < length - 1; i++) {
102+
print(array[i]);
103+
print(',');
104+
}
105+
106+
print(array[length - 1]);
107+
print(']');
108+
}
109+
110+
/**
111+
*
112+
* @tparam T
113+
* @param key
114+
* @param array
115+
* @param length
116+
* @param precision
117+
*/
118+
template<typename T>
119+
void encode(const char *key, T *array, uint16_t length, uint8_t precision) {
120+
encode_key(key);
121+
print('[');
122+
123+
for (uint16_t i = 0; i < length - 1; i++) {
124+
print(array[i], precision);
125+
print(',');
126+
}
127+
128+
print(array[length - 1], precision);
129+
print(']');
130+
}
131+
132+
protected:
133+
Stream *_stream;
134+
135+
/**
136+
* Print to stream
137+
*
138+
* @tparam T
139+
* @param value
140+
*/
141+
template<typename T>
142+
void print(T value) {
143+
_stream->print(value);
144+
}
145+
146+
/**
147+
* Print to stream with given precision
148+
*
149+
* @tparam T
150+
* @param value
151+
*/
152+
template<typename T>
153+
void print(T value, uint8_t precision) {
154+
_stream->print(value, precision);
155+
}
156+
157+
/**
158+
* Encode key
159+
*
160+
* @param key
161+
*/
162+
void encode_key(const char *key) {
163+
quote(key);
164+
print(':');
165+
}
166+
167+
/**
168+
* Quote value
169+
*
170+
* @tparam T
171+
* @param value
172+
*/
173+
template<typename T>
174+
void quote(T value) {
175+
print('"');
176+
print(value);
177+
print('"');
178+
}
179+
180+
/**
181+
* Quote string
182+
*
183+
* @param value
184+
*/
185+
void quote(String value) {
186+
value.replace("\"", "\\\"");
187+
188+
print('"');
189+
print(value);
190+
print('"');
191+
}
192+
};
193+
}
194+
}
195+
}

src/eloquent/macros.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// Created by Simone on 04/03/2022.
3+
//
4+
5+
#pragma once
6+
7+
8+
#ifdef ELOQUENT_NO_SINGLETON
9+
#define ELOQUENT_SINGLETON(expr)
10+
#else
11+
#define ELOQUENT_SINGLETON(expr) expr;
12+
#endif

src/eloquent/print.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Created by Simone on 08/03/2022.
3+
//
4+
5+
#pragma once
6+
7+
#include <stdarg.h>
8+
9+
10+
namespace eloquent {
11+
namespace print {
12+
13+
/**
14+
*
15+
* @param fmt
16+
* @param ...
17+
*/
18+
template<typename Stream>
19+
void printf(Stream &stream, char *fmt, ...) {
20+
char buf[128];
21+
22+
va_list args;
23+
va_start (args, fmt );
24+
vsnprintf(buf, 128, fmt, args);
25+
va_end (args);
26+
stream.print(buf);
27+
}
28+
}
29+
}

src/eloquent/vision.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Created by Simone on 04/03/2022.
3+
//
4+
5+
#pragma once
6+
7+
#include "./vision/transform.h"
8+
#include "./vision/MonoImage.h"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy