-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
858 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.13.1) | ||
|
||
set(SHIELD adafruit_2_8_tft_touch_v2) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(lvgl) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
&i2c1 { | ||
status = "okay"; | ||
sda-pin = <34>; // P1.02 (34) | ||
scl-pin = <35>; // P1.03 (35) | ||
|
||
/* Sparkfun Environment Combo uses second I2C address */ | ||
ccs811: ccs811@5b { | ||
compatible = "ams,ccs811"; | ||
reg = <0x5a>; | ||
label = "CCS811"; | ||
irq-gpios = <&gpio0 36 GPIO_ACTIVE_LOW>; // P1.04 (36) | ||
wake-gpios = <&gpio0 5 GPIO_ACTIVE_LOW>; | ||
reset-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>; | ||
}; | ||
|
||
bme280@76 { | ||
compatible = "bosch,bme280"; | ||
reg = <0x76>; | ||
label = "BME280"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CONFIG_HEAP_MEM_POOL_SIZE=16384 | ||
CONFIG_MAIN_STACK_SIZE=4096 | ||
|
||
CONFIG_NEWLIB_LIBC=y | ||
|
||
CONFIG_LOG=y | ||
|
||
CONFIG_BT=y | ||
CONFIG_BT_DEBUG_LOG=y | ||
CONFIG_BT_DEVICE_NAME="IAQ" | ||
|
||
CONFIG_SENSOR=y | ||
|
||
CONFIG_BME280=y | ||
CONFIG_CCS811=y | ||
|
||
|
||
CONFIG_DISPLAY=y | ||
CONFIG_DISPLAY_LOG_LEVEL_ERR=y | ||
|
||
CONFIG_LVGL=y | ||
CONFIG_LVGL_USE_THEME_MATERIAL=y | ||
CONFIG_LVGL_USE_LABEL=y | ||
CONFIG_LVGL_USE_LINEMETER=y | ||
CONFIG_LVGL_FONT_MONTSERRAT_14=y | ||
CONFIG_LVGL_FONT_MONTSERRAT_16=y | ||
CONFIG_LVGL_FONT_MONTSERRAT_18=y | ||
CONFIG_LVGL_FONT_MONTSERRAT_22=y | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
#include <zephyr.h> | ||
#include <device.h> | ||
#include <drivers/display.h> | ||
#include <drivers/sensor.h> | ||
#include <lvgl.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "gui.h" | ||
|
||
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL | ||
#include <logging/log.h> | ||
LOG_MODULE_REGISTER(gui); | ||
|
||
const struct device *display_dev; | ||
|
||
/* GUI objects ... | ||
*/ | ||
lv_obj_t *headline; | ||
lv_obj_t *qualitiy_meter; | ||
lv_obj_t *qualitiy_label; | ||
lv_obj_t *temp_label; | ||
lv_obj_t *temp_value_label; | ||
lv_obj_t *pressure_label; | ||
lv_obj_t *press_value_label; | ||
lv_obj_t *humidity_label; | ||
lv_obj_t *humid_value_label; | ||
lv_obj_t *co2_label; | ||
lv_obj_t *co2_value_label; | ||
lv_obj_t *tvoc_label; | ||
lv_obj_t *tvoc_value_label; | ||
|
||
/* GUI setup ... | ||
*/ | ||
void gui_setup(void) | ||
{ | ||
display_dev = device_get_binding(CONFIG_LVGL_DISPLAY_DEV_NAME); | ||
|
||
if (display_dev == NULL) | ||
{ | ||
LOG_ERR("Display device not found!"); | ||
return; | ||
} | ||
|
||
display_blanking_off(display_dev); | ||
|
||
lv_theme_t *theme = lv_theme_material_init(LV_COLOR_GREEN, LV_COLOR_WHITE, LV_THEME_MATERIAL_FLAG_DARK, &lv_font_montserrat_14, &lv_font_montserrat_16, &lv_font_montserrat_18, &lv_font_montserrat_22); | ||
lv_theme_set_act(theme); | ||
|
||
headline = lv_label_create(lv_scr_act(), NULL); | ||
qualitiy_meter = lv_linemeter_create(lv_scr_act(), NULL); | ||
qualitiy_label = lv_label_create(lv_scr_act(), NULL); | ||
temp_label = lv_label_create(lv_scr_act(), NULL); | ||
temp_value_label = lv_label_create(lv_scr_act(), NULL); | ||
pressure_label = lv_label_create(lv_scr_act(), NULL); | ||
press_value_label = lv_label_create(lv_scr_act(), NULL); | ||
humidity_label = lv_label_create(lv_scr_act(), NULL); | ||
humid_value_label = lv_label_create(lv_scr_act(), NULL); | ||
co2_label = lv_label_create(lv_scr_act(), NULL); | ||
co2_value_label = lv_label_create(lv_scr_act(), NULL); | ||
tvoc_label = lv_label_create(lv_scr_act(), NULL); | ||
tvoc_value_label = lv_label_create(lv_scr_act(), NULL); | ||
|
||
static lv_style_t large_style; | ||
lv_style_init(&large_style); | ||
lv_style_set_text_font(&large_style, LV_STATE_DEFAULT, lv_theme_get_font_title()); | ||
|
||
lv_obj_add_style(headline, LV_LABEL_PART_MAIN, &large_style); | ||
lv_obj_set_x(headline, 115); | ||
lv_obj_set_y(headline, 10); | ||
lv_obj_set_height(headline, 20); | ||
lv_obj_set_width(headline, 50); | ||
lv_label_set_text(headline, "Air Quality"); | ||
|
||
lv_obj_set_x(qualitiy_meter, 10); | ||
lv_obj_set_y(qualitiy_meter, 75); | ||
lv_obj_set_width(qualitiy_meter, 90); | ||
lv_obj_set_height(qualitiy_meter, 90); | ||
lv_linemeter_set_range(qualitiy_meter, 0, 100); | ||
|
||
lv_obj_set_x(qualitiy_label, 30); | ||
lv_obj_set_y(qualitiy_label, 170); | ||
lv_obj_set_width(qualitiy_label, 60); | ||
lv_obj_set_height(qualitiy_label, 40); | ||
lv_label_set_text(qualitiy_label, "Quality"); | ||
|
||
unsigned int line0_y = 50; | ||
unsigned int line_space = 40; | ||
unsigned int line = 0; | ||
|
||
lv_obj_set_x(temp_label, 115); | ||
lv_obj_set_y(temp_label, line0_y + line_space * line); | ||
lv_label_set_text(temp_label, "Temp (C°)"); | ||
lv_obj_add_style(temp_value_label, LV_LABEL_PART_MAIN, &large_style); | ||
lv_obj_set_x(temp_value_label, 245); | ||
lv_obj_set_y(temp_value_label, line0_y + line_space * line); | ||
lv_label_set_text(temp_value_label, "..."); | ||
|
||
line++; | ||
lv_obj_set_x(pressure_label, 115); | ||
lv_obj_set_y(pressure_label, line0_y + line_space * line); | ||
lv_label_set_text(pressure_label, "Pressure (hPa)"); | ||
lv_obj_add_style(press_value_label, LV_LABEL_PART_MAIN, &large_style); | ||
lv_obj_set_x(press_value_label, 245); | ||
lv_obj_set_y(press_value_label, line0_y + line_space * line); | ||
lv_label_set_text(press_value_label, "..."); | ||
|
||
line++; | ||
lv_obj_set_x(humidity_label, 115); | ||
lv_obj_set_y(humidity_label, line0_y + line_space * line); | ||
lv_label_set_text(humidity_label, "Humidity (%)"); | ||
lv_obj_add_style(humid_value_label, LV_LABEL_PART_MAIN, &large_style); | ||
lv_obj_set_x(humid_value_label, 245); | ||
lv_obj_set_y(humid_value_label, line0_y + line_space * line); | ||
lv_label_set_text(humid_value_label, "..."); | ||
|
||
line++; | ||
lv_obj_set_x(co2_label, 115); | ||
lv_obj_set_y(co2_label, line0_y + line_space * line); | ||
lv_label_set_text(co2_label, "eCO2 (ppm)"); | ||
lv_obj_add_style(co2_value_label, LV_LABEL_PART_MAIN, &large_style); | ||
lv_obj_set_x(co2_value_label, 245); | ||
lv_obj_set_y(co2_value_label, line0_y + line_space * line); | ||
lv_label_set_text(co2_value_label, "..."); | ||
|
||
line++; | ||
lv_obj_set_x(tvoc_label, 115); | ||
lv_obj_set_y(tvoc_label, line0_y + line_space * line); | ||
lv_label_set_text(tvoc_label, "TVOC (ppb)"); | ||
lv_obj_add_style(tvoc_value_label, LV_LABEL_PART_MAIN, &large_style); | ||
lv_obj_set_x(tvoc_value_label, 245); | ||
lv_obj_set_y(tvoc_value_label, line0_y + line_space * line); | ||
lv_label_set_text(tvoc_value_label, "..."); | ||
} | ||
|
||
/* Updates the value label for the refered sensor channel / value ... | ||
*/ | ||
void gui_update_sensor_value(enum sensor_channel channel, struct sensor_value value) | ||
{ | ||
value.val2 = value.val2 / 10000; | ||
switch (channel) | ||
{ | ||
case SENSOR_CHAN_AMBIENT_TEMP: | ||
lv_label_set_text_fmt(temp_value_label, "%d.%02d", value.val1, value.val2); | ||
break; | ||
case SENSOR_CHAN_PRESS: | ||
lv_label_set_text_fmt(press_value_label, "%d.%02d", value.val1, value.val2); | ||
break; | ||
case SENSOR_CHAN_HUMIDITY: | ||
lv_label_set_text_fmt(humid_value_label, "%d.%02d", value.val1, value.val2); | ||
break; | ||
case SENSOR_CHAN_CO2: | ||
lv_label_set_text_fmt(co2_value_label, "%u", value.val1); | ||
break; | ||
case SENSOR_CHAN_VOC: | ||
lv_label_set_text_fmt(tvoc_value_label, "%u", value.val1); | ||
break; | ||
} | ||
} | ||
|
||
/* Updates the line meter and it's label with the 'relative IQAI' and the rating ... | ||
*/ | ||
void gui_update_qmeter(int8_t quality, const char *rating) | ||
{ | ||
lv_linemeter_set_value(qualitiy_meter, quality); | ||
lv_label_set_text(qualitiy_label, rating); | ||
} | ||
|
||
/* Thread for activating the LVGL taskhandler periodicly ... | ||
*/ | ||
void gui_run(void) | ||
{ | ||
while (1) | ||
{ | ||
lv_task_handler(); | ||
k_sleep(K_MSEC(20)); | ||
} | ||
} | ||
|
||
// Define our GUI thread, using a stack size of 4096 and a priority of 7 | ||
K_THREAD_DEFINE(gui_thread, 4096, gui_run, NULL, NULL, NULL, 7, 0, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef __GUI_H | ||
#define __GUI_H | ||
|
||
#include <zephyr.h> | ||
#include <drivers/sensor.h> | ||
|
||
void gui_setup(void); | ||
|
||
void gui_update_sensor_value(enum sensor_channel channel, struct sensor_value value); | ||
|
||
void gui_update_qmeter(int8_t quality, const char *rating); | ||
|
||
void gui_update_headline(const char *str); | ||
|
||
#endif |
Oops, something went wrong.