Skip to content

Commit 694f593

Browse files
committed
pbio/sys/light_matrix: Add display mode.
This is not restricted to LED arrays.
1 parent 343e567 commit 694f593

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/pbio/platform/prime_hub/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define PBSYS_CONFIG_BLUETOOTH_TOGGLE_BUTTON (512) // PBIO_BUTTON_RIGHT_UP, but enum value cannot be used here.
1313
#define PBSYS_CONFIG_HMI_NUM_SLOTS (5)
1414
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (1)
15+
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX_LED_ARRAY (1)
1516
#define PBSYS_CONFIG_HOST (1)
1617
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (64)
1718
#define PBSYS_CONFIG_MAIN (1)

lib/pbio/sys/light_matrix.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
#include <contiki.h>
1111

12+
#include <pbdrv/display.h>
1213
#include <pbdrv/led.h>
14+
#include <pbio/image.h>
1315
#include <pbio/error.h>
1416
#include <pbio/light_matrix.h>
1517
#include <pbio/util.h>
@@ -32,14 +34,24 @@ static pbsys_hub_light_matrix_t pbsys_hub_light_matrix_instance;
3234
pbio_light_matrix_t *pbsys_hub_light_matrix = &pbsys_hub_light_matrix_instance.light_matrix;
3335

3436
static pbio_error_t pbsys_hub_light_matrix_set_pixel(pbio_light_matrix_t *light_matrix, uint8_t row, uint8_t col, uint8_t brightness) {
37+
#if PBSYS_CONFIG_HUB_LIGHT_MATRIX_LED_ARRAY
3538
// REVISIT: currently hub light matrix is hard-coded as LED array at index 0
3639
// on all platforms
3740
pbdrv_led_array_dev_t *array;
3841
if (pbdrv_led_array_get_dev(0, &array) == PBIO_SUCCESS) {
3942
return pbdrv_led_array_set_brightness(array, row * light_matrix->size + col, brightness);
4043
}
41-
44+
#elif PBSYS_CONFIG_HUB_LIGHT_MATRIX_DISPLAY
45+
pbio_image_t *display = pbdrv_display_get_image();
46+
uint8_t value = brightness * (pbdrv_display_get_max_value() + 1) / 100;
47+
const uint32_t size = PBDRV_CONFIG_DISPLAY_NUM_ROWS / PBSYS_CONFIG_HMI_NUM_SLOTS;
48+
const uint32_t width = size * 4 / 5;
49+
const uint32_t offset = (PBDRV_CONFIG_DISPLAY_NUM_COLS - (PBSYS_CONFIG_HMI_NUM_SLOTS * size)) / 2;
50+
pbio_image_fill_rect(display, col * size + offset, row * size, width, width, value);
51+
pbdrv_display_update();
4252
return PBIO_SUCCESS;
53+
#endif
54+
return PBIO_ERROR_NOT_SUPPORTED;
4355
}
4456

4557
static const pbio_light_matrix_funcs_t pbsys_hub_light_matrix_funcs = {

0 commit comments

Comments
 (0)