greenhouse
Public Member Functions
UI::Display Class Reference

#include <ui.h>

Public Member Functions

void init ()
 
void log (uint8_t *text)
 
void clear_line (int line_no)
 
void update_stats (mbed_stats_cpu_t *stats, int sample_time_ms)
 

Detailed Description

Definition at line 8 of file ui.h.

Member Function Documentation

◆ clear_line()

void Display::clear_line ( int  line_no)

Clears a line on the display

Return values
void

Definition at line 24 of file ui.cpp.

24  {
25  BSP_LCD_DisplayStringAt(0, LINE(line_no), (uint8_t *)" ", LEFT_MODE);
26  BSP_LCD_DisplayStringAt(0, LINE(line_no), (uint8_t *)" ", CENTER_MODE);
27  BSP_LCD_DisplayStringAt(0, LINE(line_no), (uint8_t *)" ", RIGHT_MODE);
28 
29  // this doesn't appear to work properly?
30  BSP_LCD_ClearStringLine(LINE(line_no));
31 }

Referenced by log(), and update_stats().

Here is the caller graph for this function:

◆ init()

void Display::init ( )

Initialize the display

Return values
void

Definition at line 33 of file ui.cpp.

33  {
34  BSP_LCD_Init();
35  BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
36  BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
37 
38  BSP_LCD_SetFont(&Font16);
39  BSP_LCD_Clear(LCD_COLOR_BLACK);
40  BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
41  BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
42 
43  BSP_LCD_DisplayStringAt(2, 2, (uint8_t *)"greenhouse (server)", LEFT_MODE);
44  BSP_LCD_DrawHLine(0, 20, 480);
45 
47 
48  BSP_LCD_DrawHLine(0, LINE(LOG_Y_POS - 1) - 1, 480);
49  BSP_LCD_DisplayStringAt(10, LINE(LOG_Y_POS) - 12, (uint8_t *)"console", LEFT_MODE);
50  BSP_LCD_DrawHLine(0, LINE(LOG_Y_POS), 480);
51 }
static const int LOG_Y_POS
Definition: ui.cpp:16
void set_default_font()
Definition: ui.cpp:20

References LOG_Y_POS, and set_default_font().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log()

void Display::log ( uint8_t *  text)

Write a log message to the display

Parameters
textText to write
Return values
void

Definition at line 53 of file ui.cpp.

53  {
54  if (log_idx > MAX_LOG_LINES) {
55  // Clear display
56  for (int i = 1; i < 10; i++) {
57  clear_line(LINE(i + LOG_Y_POS));
58  }
59 
60  log_idx = 0;
61  }
62 
63  ++log_idx;
64 
65  BSP_LCD_DisplayStringAt(10, LINE(log_idx + LOG_Y_POS), text, LEFT_MODE);
66 }
void clear_line(int line_no)
Definition: ui.cpp:24
static const int MAX_LOG_LINES
Definition: ui.cpp:15
int log_idx
Definition: ui.cpp:17

References clear_line(), log_idx, LOG_Y_POS, and MAX_LOG_LINES.

Referenced by Tasks::Storage::example(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_stats()

void Display::update_stats ( mbed_stats_cpu_t *  stats,
int  sample_time_ms 
)

Update stats display

Parameters
statspointer to mbed_stats_cpu_t
sample_time_msPolling time in milliseconds. Used for calculating usage percentage.
Return values
void

Definition at line 88 of file ui.cpp.

88  {
89  clear_line(3);
90  clear_line(4);
91 
92  string uptime = make_stat_str("Uptime: ", "s", stats->uptime);
93  string idle_time = make_stat_str("Idle: ", "s", stats->idle_time);
94  string sleep = make_stat_str("Sleep: ", "s", stats->sleep_time);
95  string deep_sleep = make_stat_str("Deep sleep: ", "s", stats->deep_sleep_time);
96 
97  BSP_LCD_DisplayStringAt(25, LINE(3), (uint8_t *)uptime.c_str(), LEFT_MODE);
98  BSP_LCD_DisplayStringAt(120, LINE(3), (uint8_t *)idle_time.c_str(), LEFT_MODE);
99  BSP_LCD_DisplayStringAt(205, LINE(3), (uint8_t *)sleep.c_str(), LEFT_MODE);
100  BSP_LCD_DisplayStringAt(300, LINE(3), (uint8_t *)deep_sleep.c_str(), LEFT_MODE);
101 
102  uint64_t diff_usec = (stats->idle_time - prev_idle_time);
103  uint8_t idle = (diff_usec * 100) / (sample_time_ms*1000);
104  uint8_t usage = 100 - ((diff_usec * 100) / (sample_time_ms*1000));
105  prev_idle_time = stats->idle_time;
106 
107  string usage_str = string("Usage: ");
108  usage_str.append(std::to_string(usage));
109  usage_str.append("%");
110 
111  BSP_LCD_DisplayStringAt(25, LINE(4), (uint8_t *)usage_str.c_str(), LEFT_MODE);
112 }
string make_stat_str(string label, string suffix, uint64_t us)
Definition: ui.cpp:80
uint64_t prev_idle_time
Definition: ui.cpp:18

References clear_line(), make_stat_str(), and prev_idle_time.

Referenced by collect_stats().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: