Skip to content

Commit

Permalink
test submit (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnsAnns authored May 6, 2024
2 parents b74804e + 2b0c30f commit 9ded619
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@
"iostream": "cpp",
"list": "cpp",
"ratio": "cpp",
"istream": "cpp"
"istream": "cpp",
"lcd.h": "c",
"ili9341.h": "c",
"ili9341_params.h": "c",
"lvgl_riot.h": "c"
},
"[shellscript][c][cpp]": {
"editor.tabSize": 4,
Expand Down
23 changes: 23 additions & 0 deletions node/code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ USEMODULE += ili9341
USEMODULE += ztimer
USEMODULE += ztimer_msec

DISABLE_MODULE += test_utils_interactive_sync

USEPKG += lvgl
USEMODULE += lvgl_contrib
USEMODULE += lvgl_extra_widget_chart
USEMODULE += lvgl_extra_widget_win
USEMODULE += lvgl_extra_layout_flex
USEMODULE += lvgl_extra_theme_default
USEMODULE += lvgl_extra_theme_default_dark

# As there is an 'Kconfig' we want to explicitly disable Kconfig by setting
# the variable to empty
SHOULD_RUN_KCONFIG ?=
Expand All @@ -29,6 +39,19 @@ CXXEXFLAGS +=

include $(RIOTBASE)/Makefile.include


BOARD_BLACKLIST += native64


# SDL requires more stack
ifneq (,$(filter native native64,$(BOARD)))
CFLAGS += -DTHREAD_STACKSIZE_MAIN=64*1024
else ifneq (,$(filter esp%,$(CPU_FAM)))
CFLAGS += -DTHREAD_STACKSIZE_MAIN=4*1024
else
CFLAGS += -DTHREAD_STACKSIZE_MAIN=2*1024
endif

# Note that this will probably only work for me <3
windows: all
@echo "Creating UF2"
Expand Down
2 changes: 1 addition & 1 deletion node/code/inc/ili9341_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern "C" {
#define ILI9341_PARAM_SPI SPI_DEV(0)
#endif
#ifndef ILI9341_PARAM_SPI_CLK
#define ILI9341_PARAM_SPI_CLK SPI_CLK_5MHZ
#define ILI9341_PARAM_SPI_CLK SPI_CLK_10MHZ
#endif
#ifndef ILI9341_PARAM_CS
// PIN 9 on the feather
Expand Down
11 changes: 11 additions & 0 deletions node/code/inc/init_lvgl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

int init_lvgl(void);

#ifdef __cplusplus
}
#endif
8 changes: 4 additions & 4 deletions node/code/init_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ int init_display(void) {
lcd_fill(&dev, 0, dev.params->lines / 3, 0, dev.params->rgb_channels, 0x001F);
ztimer_sleep(ZTIMER_MSEC, 1 * MS_PER_SEC);

puts("Drawing green rectangle");
lcd_fill(&dev, dev.params->lines / 3, 2 * (dev.params->lines / 3), 0,
dev.params->rgb_channels, 0x07E0);
ztimer_sleep(ZTIMER_MSEC, 1 * MS_PER_SEC);
// puts("Drawing green rectangle");
// lcd_fill(&dev, dev.params->lines / 3, 2 * (dev.params->lines / 3), 0,
// dev.params->rgb_channels, 0x07E0);
// ztimer_sleep(ZTIMER_MSEC, 1 * MS_PER_SEC);

puts("Drawing red rectangle");
lcd_fill(&dev, 2 * (dev.params->lines / 3), dev.params->lines, 0,
Expand Down
129 changes: 129 additions & 0 deletions node/code/init_lvgl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (C) 2019 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup tests
* @{
*
* @file
* @brief LVGL example application
*
* @author Alexandre Abadie <[email protected]>
*
* @}
*/

#include <string.h>

#include "lvgl/lvgl.h"
#include "lvgl_riot.h"
#include "disp_dev.h"

#define CPU_LABEL_COLOR "FF0000"
#define MEM_LABEL_COLOR "0000FF"
#define CHART_POINT_NUM 100

/* Must be lower than LVGL_INACTIVITY_PERIOD_MS for autorefresh */
#define REFR_TIME 200

static lv_obj_t *win;
static lv_obj_t *chart;
static lv_chart_series_t * cpu_ser;
static lv_chart_series_t *mem_ser;
static lv_obj_t *info_label;
static lv_timer_t *refr_task;

static void sysmon_task(lv_timer_t *param)
{
(void)param;

/* Get CPU and memory information */
uint8_t cpu_busy = 100 - lv_timer_get_idle();

lv_mem_monitor_t mem_mon;
lv_mem_monitor(&mem_mon);

uint8_t mem_used_pct = mem_mon.used_pct;

/* Add the CPU and memory data to the chart */
lv_chart_set_next_value(chart, cpu_ser, cpu_busy);
lv_chart_set_next_value(chart, mem_ser, mem_used_pct);

/* Set the text info */
lv_label_set_text_fmt(info_label,
"%s%s CPU: %d %%%s\n\n"
LV_TXT_COLOR_CMD"%s MEMORY: %d %%"LV_TXT_COLOR_CMD"\n"
"Total: %" PRIu32 " bytes\n"
"Used: %" PRIu32 " bytes\n"
"Free: %" PRIu32 " bytes\n"
"Frag: %d %%",
LV_TXT_COLOR_CMD,
CPU_LABEL_COLOR,
cpu_busy,
LV_TXT_COLOR_CMD,
MEM_LABEL_COLOR,
mem_used_pct,
mem_mon.total_size,
mem_mon.total_size - mem_mon.free_size,
mem_mon.free_size,
mem_mon.frag_pct);

/* Force a wakeup of lvgl when each task is called: this ensures an activity
is triggered and wakes up lvgl during the next LVGL_INACTIVITY_PERIOD ms */
lvgl_wakeup();
}

void sysmon_create(void)
{
lv_coord_t hres = lv_disp_get_hor_res(NULL);
lv_coord_t vres = lv_disp_get_ver_res(NULL);

win = lv_win_create(lv_scr_act(), 25);
lv_win_add_title(win, "System monitor");
lv_obj_t * cont = lv_win_get_content(win);

/* Make the window content responsive */
lv_obj_set_layout(cont, LV_LAYOUT_FLEX);

/* Create a chart with two data lines */
chart = lv_chart_create(cont);
lv_obj_set_size(chart, hres * 10L / 25, vres / 2);
lv_obj_set_pos(chart, LV_DPI_DEF / 10, LV_DPI_DEF / 10);
lv_chart_set_point_count(chart, CHART_POINT_NUM);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 100);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
cpu_ser = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
mem_ser = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y);

/* Set the data series to zero */
uint16_t i;
for (i = 0; i < CHART_POINT_NUM; i++) {
lv_chart_set_next_value(chart, cpu_ser, 0);
lv_chart_set_next_value(chart, mem_ser, 0);
}

/* Create a label for the details of Memory and CPU usage */
info_label = lv_label_create(cont);
lv_label_set_recolor(info_label, true);

/* Create the task used to refresh the chart and label */
refr_task = lv_timer_create(sysmon_task, REFR_TIME, NULL);
}

int init_lvgl(void)
{
/* Enable backlight */
gpio_init(GPIO_PIN(0,30), GPIO_OUT);//backlight controller
disp_dev_backlight_off();
/* Create the system monitor widget */
sysmon_create();

lvgl_run();

return 0;
}
6 changes: 3 additions & 3 deletions node/code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include "architecture.h"
#include "dispatch_handler.hpp"
#include "dispatcher.hpp"
#include "init_display.h"
//#include "init_display.h"
#include "init_lvgl.h"
#include "ping.hpp"
#include "pong.hpp"
#include "riot/thread.hpp"
Expand All @@ -23,8 +24,7 @@ kernel_pid_t DISPATCHER_PID;
int main() {
printf("\n************ We are in C++ 😎 ***********\n");
printf("\n");

init_display();
init_lvgl();

puts("{\"result\": \"PASS\"}");

Expand Down

0 comments on commit 9ded619

Please sign in to comment.