@@ -255,88 +255,12 @@ class ModulinoKnob : public Module {
255
255
std::vector<uint8_t > match = { 0x74 , 0x76 };
256
256
};
257
257
258
- #define RETURN_IF_NOT_ZERO (func ) do { int ret = func; if (ret != 0 ) { return 0 ; } } while (0 )
259
-
260
- class APDS9999 {
261
- public:
262
- APDS9999 (TwoWire& wire)
263
- : _wire(&wire) {}
264
- int begin () {
265
- RETURN_IF_NOT_ZERO (writeRegister (0x0 , 0x6 ));
266
- RETURN_IF_NOT_ZERO (writeRegister (0x1 , 0x73 ));
267
- RETURN_IF_NOT_ZERO (writeRegister (0x2 , 0x0 ));
268
- RETURN_IF_NOT_ZERO (writeRegister (0x5 , 0x4 ));
269
- return 1 ;
270
- }
271
- int available () {
272
- uint8_t buf[1 ] = { 0x7 };
273
- _wire->beginTransmission (address);
274
- _wire->write (buf, sizeof (buf));
275
- auto ret = _wire->endTransmission (false );
276
- if (ret == 0 ) {
277
- _wire->requestFrom (address, 1 );
278
- auto res = (_wire->read () & (1 | (1 << 3 )));
279
- return res;
280
- }
281
- return 0 ;
282
- }
283
- int read (int & r, int & g, int & b) {
284
- int uv;
285
- return read (r, g, b, uv);
286
- }
287
- int read (int & r, int & g, int & b, int & uv) {
288
- uint8_t buf[1 ] = { 0xA };
289
- _wire->beginTransmission (address);
290
- _wire->write (buf, sizeof (buf));
291
- auto ret = _wire->endTransmission (false );
292
- if (ret == 0 ) {
293
- _wire->requestFrom (address, 4 * 3 ); // 4 registers * 3 bytes each
294
- uint8_t resp_buf[12 ];
295
- for (int i = 0 ; i < sizeof (resp_buf); i++) {
296
- resp_buf[i] = _wire->read ();
297
- }
298
- // resultion is 18bit, compress to 8
299
- uv = (resp_buf[0 ] | (resp_buf[1 ] << 8 ) | (resp_buf[2 ] << 16 )) >> 10 ;
300
- g = (resp_buf[3 ] | (resp_buf[4 ] << 8 ) | (resp_buf[5 ] << 16 )) >> 10 ;
301
- b = (resp_buf[6 ] | (resp_buf[7 ] << 8 ) | (resp_buf[8 ] << 16 )) >> 10 ;
302
- r = (resp_buf[9 ] | (resp_buf[10 ] << 8 ) | (resp_buf[11 ] << 16 )) >> 10 ;
303
- }
304
- }
305
- int read (int & light) {
306
- uint8_t buf[1 ] = { 0x8 };
307
- _wire->beginTransmission (address);
308
- _wire->write (buf, sizeof (buf));
309
- auto ret = _wire->endTransmission (false );
310
- if (ret == 0 ) {
311
- _wire->requestFrom (address, 2 ); // 4 registers * 3 bytes each
312
- return _wire->read () | ((_wire->read () & 0x3 ) << 8 );
313
- }
314
- return 0 ;
315
- }
316
- private:
317
- TwoWire* _wire;
318
- const uint8_t address = 0x52 ;
319
- int writeRegister (uint8_t reg, uint8_t value) {
320
- _wire->beginTransmission (address);
321
- _wire->write (reg);
322
- _wire->write (value);
323
- auto ret = _wire->endTransmission ();
324
- return ret;
325
- }
326
- };
327
-
328
-
329
258
extern ModulinoColor RED;
330
259
extern ModulinoColor BLUE;
331
260
extern ModulinoColor GREEN;
332
261
extern ModulinoColor VIOLET;
333
262
extern ModulinoColor WHITE;
334
263
335
- /*
336
- TODO: These classes need to be ported to Modulino ecosystem, as per the tof_sensor example
337
- */
338
- extern APDS9999 color; // TODO: need to change to APDS9999 https://docs.broadcom.com/doc/APDS-9999-DS
339
-
340
264
class ModulinoMovement : public Module {
341
265
public:
342
266
bool begin () {
0 commit comments