struct sercom_data* sercom;
+/* Subtract the `struct timespec' values X and Y,
+ storing the result in RESULT (result = x - y).
+ Return 1 if the difference is negative, otherwise 0. */
+
+int
+timespec_subtract (struct timespec *result,
+ struct timespec *x,
+ struct timespec *y)
+{
+ /* Perform the carry for the later subtraction by updating Y. */
+ if (x->tv_nsec < y->tv_nsec) {
+ int num_sec = (y->tv_nsec - x->tv_nsec) / 1000000000 + 1;
+ y->tv_nsec -= 1000000000 * num_sec;
+ y->tv_sec += num_sec;
+ }
+ if (x->tv_nsec - y->tv_nsec > 1000000000) {
+ int num_sec = (x->tv_nsec - y->tv_nsec) / 1000000000;
+ y->tv_nsec += 1000000000 * num_sec;
+ y->tv_sec -= num_sec;
+ }
+
+ /* Compute the time remaining to wait.
+ `tv_nsec' is certainly positive. */
+ result->tv_sec = x->tv_sec - y->tv_sec;
+ result->tv_nsec = x->tv_nsec - y->tv_nsec;
+
+ /* Return 1 if result is negative. */
+ return x->tv_sec < y->tv_sec;
+}
+
+
+int miliseconds_since(struct timespec *t)
+{
+ struct timespec now, diff;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ timespec_subtract(&diff, t, &now);
+ return diff.tv_sec * 1000 + diff.tv_nsec/1000000;
+}
+
+
void rcv_pwr_voltage_cb (const ORTERecvInfo *info, void *vinstance,
void *recvCallBackParam)
{
uoled_display_status(PWR, STATUS_OK);
break;
case DEADLINE:
- printf("ORTE deadline occurred - PWR_VOLTAGE\n");
uoled_display_status(PWR, STATUS_FAILED);
break;
}
void rcv_odo_data_cb(const ORTERecvInfo *info, void *vinstance,
void *recvCallBackParam)
{
+ UDE_hw_status_t status = STATUS_FAILED;
+ static UDE_hw_status_t last_status;
+ static struct timespec last_sent;
+
//struct odo_data_type *instance = (struct odo_data_type *)vinstance;
switch (info->status) {
case NEW_DATA:
- uoled_display_status(HOK, STATUS_OK);
+ status = STATUS_OK;
break;
case DEADLINE:
- printf("ORTE deadline occurred - ODO_DATA\n");
- uoled_display_status(HOK, STATUS_FAILED);
+ status = STATUS_FAILED;
break;
}
+#warning TODO predelat vsechny statusy callbacku podle teto funkce
+ /* Neni potreba aktualizovat stav na displeji 25x za sekundu */
+ if (status != last_status ||
+ miliseconds_since(&last_sent) > 1000) {
+ uoled_display_status(HOK, STATUS_OK);
+ clock_gettime(CLOCK_MONOTONIC, &last_sent);
+ }
+ last_status = status;
}
void rcv_motion_irc_cb(const ORTERecvInfo *info, void *vinstance,