1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
27
28
32
33
34
35
36
37
38
45
46
47
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
75
76
77
78
79
84
85
86
87
88
89
90
91
92
93
94
95
96
103
104
105
109
110
114
/* ... */
#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 /* ... */
#else
static volatile long lastUs;
extern uint32_t SystemCoreClock;
static int freqMHz;/* ... */
#endif
Model::Model() :
modelListener(0),
mcuLoadActive(true),
selectedDemoScreenIndex(0),
previousSelectedMenuType(ANIMATING_BUTTONS_MENU)
{
#ifndef SIMULATOR
lastUs = touchgfx::HAL::getInstance()->getCPUCycles();
freqMHz = SystemCoreClock / 1000000;/* ... */
#endif
}{ ... }
#ifndef SIMULATOR
static uint8_t mcuLoadLast = 0;/* ... */
#endif
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 /* ... */
#else
static int milliseconds = 123456;
uint8_t mcuLoadPct = touchgfx::HAL::getInstance()->getMCULoadPct();
if (mcuLoadLast != mcuLoadPct)
{
mcuLoadLast = mcuLoadPct;
modelListener->mcuLoadUpdated(mcuLoadLast);
}if (mcuLoadLast != /*mcu_load_pct*/ mcuLoadPct) { ... }
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
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();
}{ ... }