Skip to content

Commit 7617a6a

Browse files
committed
sys/light grid: consolidate OS code
This moves OS-level code from src/light/light_grid.c and platform/sys.c to a new file so that it can be shared in the future - similar to how the status light works. It also makes src/light/light_grid completely generic now.
1 parent dbdc5c1 commit 7617a6a

File tree

19 files changed

+236
-112
lines changed

19 files changed

+236
-112
lines changed

bricks/stm32/stm32.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
348348
src/uartdev.c \
349349
sys/battery.c \
350350
sys/hmi.c \
351+
sys/light_grid.c \
351352
sys/light.c \
352353
sys/status.c \
353354
sys/supervisor.c \

lib/pbio/include/pbio/light_grid.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef _PBIO_LIGHT_GRID_H_
1010
#define _PBIO_LIGHT_GRID_H_
1111

12+
#include <stdint.h>
13+
1214
#include <pbio/config.h>
1315
#include <pbio/error.h>
1416

@@ -17,16 +19,37 @@ typedef struct _pbio_light_grid_t pbio_light_grid_t;
1719

1820
#if PBIO_CONFIG_LIGHT_GRID
1921

20-
extern const uint8_t pbio_light_grid_sys_pattern[1000];
21-
22-
pbio_error_t pbio_light_grid_get_dev(pbio_light_grid_t **light_grid);
2322
uint8_t pbio_light_grid_get_size(pbio_light_grid_t *light_grid);
2423
pbio_error_t pbio_light_grid_set_rows(pbio_light_grid_t *light_grid, const uint8_t *rows);
2524
pbio_error_t pbio_light_grid_set_pixel(pbio_light_grid_t *light_grid, uint8_t row, uint8_t col, uint8_t brightness);
2625
pbio_error_t pbio_light_grid_set_image(pbio_light_grid_t *light_grid, const uint8_t *image);
2726
void pbio_light_grid_start_animation(pbio_light_grid_t *light_grid, const uint8_t *cells, uint8_t num_cells, uint16_t interval);
2827
void pbio_light_grid_stop_animation(pbio_light_grid_t *light_grid);
2928

29+
#else // PBIO_CONFIG_LIGHT_GRID
30+
31+
static inline uint8_t pbio_light_grid_get_size(pbio_light_grid_t *light_grid) {
32+
return 0;
33+
}
34+
35+
static inline pbio_error_t pbio_light_grid_set_rows(pbio_light_grid_t *light_grid, const uint8_t *rows) {
36+
return PBIO_ERROR_NOT_SUPPORTED;
37+
}
38+
39+
static inline pbio_error_t pbio_light_grid_set_pixel(pbio_light_grid_t *light_grid, uint8_t row, uint8_t col, uint8_t brightness) {
40+
return PBIO_ERROR_NOT_SUPPORTED;
41+
}
42+
43+
static inline pbio_error_t pbio_light_grid_set_image(pbio_light_grid_t *light_grid, const uint8_t *image) {
44+
return PBIO_ERROR_NOT_SUPPORTED;
45+
}
46+
47+
static inline void pbio_light_grid_start_animation(pbio_light_grid_t *light_grid, const uint8_t *cells, uint8_t num_cells, uint16_t interval) {
48+
}
49+
50+
static inline void pbio_light_grid_stop_animation(pbio_light_grid_t *light_grid) {
51+
}
52+
3053
#endif // PBIO_CONFIG_LIGHT_GRID
3154

3255
#endif // _PBIO_LIGHT_GRID_H_

lib/pbio/include/pbsys/light.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
#ifndef _PBSYS_LIGHT_H_
1010
#define _PBSYS_LIGHT_H_
1111

12-
#include <pbio/light.h>
1312
#include <pbsys/config.h>
1413

1514
#if PBSYS_CONFIG_STATUS_LIGHT
15+
#include <pbio/light.h>
1616
extern pbio_color_light_t *pbsys_status_light;
1717
#endif
1818

19+
#if PBSYS_CONFIG_HUB_LIGHT_GRID
20+
#include <pbio/light_grid.h>
21+
extern pbio_light_grid_t *pbsys_hub_light_grid;
22+
#endif
23+
1924
#endif // _PBSYS_LIGHT_H_
2025

2126
/** @} */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2020 The Pybricks Authors
33

4+
#define PBSYS_CONFIG_HUB_LIGHT_GRID (0)
45
#define PBSYS_CONFIG_STATUS_LIGHT (1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2020 The Pybricks Authors
33

4+
#define PBSYS_CONFIG_HUB_LIGHT_GRID (0)
45
#define PBSYS_CONFIG_STATUS_LIGHT (1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2020 The Pybricks Authors
33

4+
#define PBSYS_CONFIG_HUB_LIGHT_GRID (0)
45
#define PBSYS_CONFIG_STATUS_LIGHT (1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2020 The Pybricks Authors
33

4+
#define PBSYS_CONFIG_HUB_LIGHT_GRID (0)
45
#define PBSYS_CONFIG_STATUS_LIGHT (1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2020 The Pybricks Authors
33

4+
#define PBSYS_CONFIG_HUB_LIGHT_GRID (0)
45
#define PBSYS_CONFIG_STATUS_LIGHT (0)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2020 The Pybricks Authors
33

4+
#define PBSYS_CONFIG_HUB_LIGHT_GRID (1)
45
#define PBSYS_CONFIG_STATUS_LIGHT (1)

lib/pbio/platform/prime_hub/sys.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
#include <contiki.h>
77

8-
#include "pbio/color.h"
98
#include "pbio/event.h"
10-
#include "pbio/light_grid.h"
119
#include "pbio/main.h"
1210

1311
#include <pbsys/status.h>
@@ -30,11 +28,6 @@ void pbsys_prepare_user_program(const pbsys_user_program_callbacks_t *callbacks)
3028
user_stop_func = NULL;
3129
user_stdin_event_func = NULL;
3230
}
33-
34-
pbio_light_grid_t *light_grid;
35-
if (pbio_light_grid_get_dev(&light_grid) == PBIO_SUCCESS) {
36-
pbio_light_grid_start_animation(light_grid, pbio_light_grid_sys_pattern, 40, 25);
37-
}
3831
pbsys_status_set(PBSYS_STATUS_USER_PROGRAM_RUNNING);
3932
}
4033

@@ -43,14 +36,6 @@ void pbsys_unprepare_user_program(void) {
4336
pbio_stop_all();
4437
user_stop_func = NULL;
4538
user_stdin_event_func = NULL;
46-
47-
pbio_light_grid_t *light_grid;
48-
if (pbio_light_grid_get_dev(&light_grid) == PBIO_SUCCESS) {
49-
uint8_t rows[5] = {0};
50-
// 3x3 "stop sign" at top center of light grid
51-
rows[0] = rows[1] = rows[2] = 0b01110;
52-
pbio_light_grid_set_rows(light_grid, rows);
53-
}
5439
}
5540

5641
PROCESS_THREAD(pbsys_process, ev, data) {

0 commit comments

Comments
 (0)