/* Vela OS SDK 1.0 teaching example. Copyright Polymath. */ #include #include #include static int present(unsigned value) { char frame[128]; int length = snprintf(frame, sizeof frame, "VELA_CARD/1\tRemote Counter\t%u / 99. Left and Right adjust. OK resets.\n", value); if (length < 0 || (size_t)length >= sizeof frame) return 1; size_t sent = 0; while (sent < (size_t)length) { ssize_t n = write(STDOUT_FILENO, frame + sent, (size_t)length - sent); if (n < 0 && errno == EINTR) continue; if (n <= 0) return 1; sent += (size_t)n; } return 0; } int main(void) { unsigned value = 0; if (present(value)) return 1; for (;;) { char key; ssize_t count = read(STDIN_FILENO, &key, 1); if (count < 0 && errno == EINTR) continue; if (count <= 0) return count < 0; unsigned previous = value; if (key == 'L' && value > 0) --value; if (key == 'R' && value < 99) ++value; if (key == 'O') value = 0; if (value != previous && present(value)) return 1; } }