Implement led control in another module
This commit is contained in:
13
barista/test/compat.c
Normal file
13
barista/test/compat.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* Copyright (c) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
|
||||
#include "compat.h"
|
||||
#include <time.h>
|
||||
|
||||
unsigned long millis(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
return ts.tv_sec * 1000UL + ts.tv_nsec / 1000000UL;
|
||||
}
|
||||
17
barista/test/compat.h
Normal file
17
barista/test/compat.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/* Copyright (c) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
|
||||
#ifndef BARISTA_COMPAT_H
|
||||
#define BARISTA_COMPAT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
unsigned long millis(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BARISTA_COMPAT_H */
|
||||
42
barista/test/test_led.c
Normal file
42
barista/test/test_led.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Copyright (c) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "led.h"
|
||||
#include "compat.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct led led;
|
||||
unsigned long t0 = millis();
|
||||
unsigned long step = 1000UL;
|
||||
|
||||
led_pattern(&led, t0, step, "000123456789abcdefff");
|
||||
|
||||
int last_level = -1;
|
||||
|
||||
unsigned long last_t = millis();
|
||||
while (1) {
|
||||
unsigned long t = millis();
|
||||
|
||||
if (t - t0 >= 10000UL)
|
||||
break;
|
||||
|
||||
if (t - last_t < 50UL)
|
||||
continue;
|
||||
|
||||
int level = led_level(&led, millis());
|
||||
printf("|");
|
||||
for (int i = 0; i < 256; i+=4) {
|
||||
if (i < level)
|
||||
printf("=");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf("|\n");
|
||||
last_level = level;
|
||||
last_t = t;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user