Select one of the symbols to view example projects that use it.
 
Outline
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
#include <touchgfx/hal/HAL.hpp>
#include <ctime>
#include <sys/time.h>
lastUs
freqMHz
Model::Model()
mcuLoadLast
Model::tick()
Model::screenSaverMinorTick()
Model::screenSaverMajorTick()
Files
loading...
CodeScopeSTM32 Libraries and SamplesTouchGFXGui/gui/src/model/Model.cpp
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * This file is part of the TouchGFX 4.10.0 distribution. * * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ #include <gui/model/Model.hpp> #include <gui/model/ModelListener.hpp> #include <touchgfx/hal/HAL.hpp> #ifdef SIMULATOR #include <ctime> #ifndef _MSC_VER #include <sys/time.h> #endif /* _MSC_VER*//* ... */ #else static volatile long lastUs; extern uint32_t SystemCoreClock; static int freqMHz;/* ... */ #endif /* SIMULATOR */ Model::Model() : modelListener(0), mcuLoadActive(true), selectedMenuIndex(0) { #ifndef SIMULATOR lastUs = touchgfx::HAL::getInstance()->getCPUCycles(); freqMHz = SystemCoreClock / 1000000;/* ... */ #endif }{ ... } #ifndef SIMULATOR //extern volatile uint32_t mcu_load_pct; static uint8_t mcuLoadLast = 0;/* ... */ #endif // SIMULATOR void Model::tick() { Time previousTime = currentTime; #ifdef SIMULATOR #ifdef _MSC_VER time_t rawtime; struct tm timenow; time(&rawtime); localtime_s(&timenow, &rawtime); currentTime.hours = timenow.tm_hour; currentTime.minutes = timenow.tm_min; currentTime.seconds = timenow.tm_sec; currentTime.milliseconds = 0; /* ... */ #else timeval timenow; gettimeofday(&timenow, NULL); currentTime.hours = (timenow.tv_sec / 60 / 60) % 24; currentTime.minutes = (timenow.tv_sec / 60) % 60; currentTime.seconds = timenow.tv_sec % 60; currentTime.milliseconds = timenow.tv_usec / 1000;/* ... */ #endif /*_MSC_VER*//* ... */ #else static int milliseconds = 123456; uint8_t mcuLoadPct = touchgfx::HAL::getInstance()->getMCULoadPct(); if (mcuLoadLast != /*mcu_load_pct*/ mcuLoadPct) { mcuLoadLast = mcuLoadPct; modelListener->mcuLoadUpdated(mcuLoadLast); }if (mcuLoadLast != /*mcu_load_pct*/ mcuLoadPct) { ... } //long now = cpu_cycles(); long now = touchgfx::HAL::getInstance()->getCPUCycles(); milliseconds += (now - lastUs + freqMHz / 2) / freqMHz / 1000; lastUs = now; currentTime.hours = (milliseconds / 1000 / 60 / 60) % 24; currentTime.minutes = (milliseconds / 1000 / 60) % 60; currentTime.seconds = (milliseconds / 1000) % 60; currentTime.milliseconds = milliseconds % 1000; /* ... */ #endif /* SIMULATOR */ if (currentTime.seconds != previousTime.seconds) { if (modelListener) { modelListener->timeUpdated(currentTime); }if (modelListener) { ... } }if (currentTime.seconds != previousTime.seconds) { ... } }{ ... } void Model::screenSaverMinorTick() { modelListener->screenSaverMinorTick(); }{ ... } void Model::screenSaverMajorTick() { modelListener->screenSaverMajorTick(); }{ ... }