| 344 | } |
| 345 | |
| 346 | void 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 | |
| 386 | done: |
| 387 | xsEndHost(sensor->the); |
| 388 | } |
| 389 | |
| 390 | void triggerEvent(xsSensor sensor, uint8_t eventKind, const char *errorMsg) |
| 391 | { |
nothing calls this directly
no test coverage detected