MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / readSensor

Function readSensor

modules/drivers/w3csensor/sensor.c:346–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344}
345
346void readSensor(modTimer timer, void *refcon, int refconSize)
347{
348 xsSensor sensor = *(xsSensor *)refcon;
349 uint32_t timestamp;
350
351 xsBeginHost(sensor->the);
352
353 if (0 == sensor->timestamp) {
354 xsTry {
355 xsCall0(sensor->obj, xsID__activate);
356 }
357 xsCatch {
358 triggerErrorEvent(sensor, "NotAllowedError"); //@@ not entirely true
359 goto done;
360 }
361
362 sensor->state = kStateActivated;
363 triggerEvent(sensor, kEventKindActivate, NULL);
364 }
365
366#if defined (__ets__)
367 timestamp = modMilliseconds();
368#else
369 //@@
370 c_timeval tv;
371 c_gettimeofday(&tv, NULL);
372 timestamp = ((double)(tv.tv_sec - 1512070000) * 1000.0) + ((double)(tv.tv_usec) / 1000.0);
373#endif
374
375 xsTry {
376 xsCall0(sensor->obj, xsID__poll);
377 }
378 xsCatch {
379 triggerErrorEvent(sensor, "NotReadableError");
380 goto done;
381 }
382
383 sensor->timestamp = timestamp;
384 triggerEvent(sensor, kEventKindReading, NULL);
385
386done:
387 xsEndHost(sensor->the);
388}
389
390void triggerEvent(xsSensor sensor, uint8_t eventKind, const char *errorMsg)
391{

Callers

nothing calls this directly

Calls 4

triggerErrorEventFunction · 0.85
triggerEventFunction · 0.85
modMillisecondsFunction · 0.85
c_gettimeofdayFunction · 0.85

Tested by

no test coverage detected