greenhouse
source
tasks
stats_task.cpp
Go to the documentation of this file.
1
#include "Thread.h"
2
#include "mbed.h"
3
#include "
tasks/stats_task.h
"
4
#include "
ui.h
"
5
#include <cstdio>
6
7
using namespace
Tasks
;
8
9
#define SAMPLE_TIME_MS 1000
10
#define MAX_THREAD_STACK 384
11
12
UI::Display
*
_display
;
13
EventQueue *
stats_queue
= mbed_event_queue();
14
int
_thread_id
;
15
Thread *
_thread
;
16
17
void
Stats::setDisplay
(
UI::Display
*
display
) {
18
_display
=
display
;
19
}
20
21
void
collect_stats
() {
22
mbed_stats_cpu_t stats;
23
mbed_stats_cpu_get(&stats);
24
_display
->
update_stats
(&stats,
SAMPLE_TIME_MS
);
25
}
26
27
void
Stats::start
() {
28
if
(
_thread
) {
29
// we're already running
30
return
;
31
}
32
33
_thread_id
=
stats_queue
->call_every(
SAMPLE_TIME_MS
,
collect_stats
);
34
35
_thread
=
new
Thread(osPriorityNormal,
MAX_THREAD_STACK
);
36
}
37
38
void
Stats::stop
() {
39
if
(
_thread
) {
40
_thread
->terminate();
41
}
42
}
Tasks::Stats::stop
void stop()
Definition:
stats_task.cpp:38
Tasks::Stats::setDisplay
void setDisplay(UI::Display *display)
Definition:
stats_task.cpp:17
Tasks::Stats::start
void start()
Definition:
stats_task.cpp:27
UI::Display
Definition:
ui.h:8
UI::Display::update_stats
void update_stats(mbed_stats_cpu_t *stats, int sample_time_ms)
Definition:
ui.cpp:88
display
UI::Display * display
Definition:
main.cpp:19
Tasks
Definition:
jukebox_task.h:4
_display
UI::Display * _display
Definition:
stats_task.cpp:12
stats_queue
EventQueue * stats_queue
Definition:
stats_task.cpp:13
_thread
Thread * _thread
Definition:
stats_task.cpp:15
collect_stats
void collect_stats()
Definition:
stats_task.cpp:21
MAX_THREAD_STACK
#define MAX_THREAD_STACK
Definition:
stats_task.cpp:10
SAMPLE_TIME_MS
#define SAMPLE_TIME_MS
Definition:
stats_task.cpp:9
_thread_id
int _thread_id
Definition:
stats_task.cpp:14
stats_task.h
ui.h
Generated on Mon Aug 16 2021 20:30:21 for greenhouse by
1.9.1