1// This file is generated by WOWCube SDK project wizard
2
3#include <stdint.h>
4#include <string>
5#include <vector>
6#include <string>
7#include <memory>
8
9#include "AppManager.h"
10#include "TimeAndTimers.h"
11
12using namespace Cubios::Gfx;
13
14//Applicaton initialization callback. Called once when CUB application starts
15void OnInit(Cubios::AppManager& appMgr)
16{
17 TimeAndTimers* theApp = new TimeAndTimers();
18
19 appMgr.SetApplication(theApp,"AAbbCCddEE");
20
21 theApp->InitializeResources();
22}
23
24
25TimeAndTimers::TimeAndTimers()
26{
27 this->deltaTime = 0;
28 this->fps = 0;
29 this->seconds = 0;
30}
31
32TimeAndTimers::~TimeAndTimers()
33{
34}
35
36void TimeAndTimers::InitializeResources()
37{
38 //Set a timer that ticks once a second
39 this->SetTimer(Timers::myTimer,1000);
40}
41
42//This callback is called every "tick" of cubeapp application loop
43void TimeAndTimers::on_Tick(uint32_t currentTime, uint32_t deltaTime)
44{
45 this->deltaTime = deltaTime;
46
47 if(this->deltaTime>0)
48 {
49 this->fps = 1000.0/(float)this->deltaTime;
50 }
51 else
52 {
53 this->fps = 0;
54 }
55
56}
57
58//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
59void TimeAndTimers::on_Render(std::array<Cubios::Screen, 3>& screens)
60{
61 char buff[256];
62
63 for(auto it = screens.begin(); it != screens.end(); ++it)
64 {
65 Cubios::GFX_setRenderTarget(it->ID());
66 Cubios::GFX_clear(Colors::black);
67
68 sprintf(buff,"dt: %d ms",this->deltaTime);
69 Cubios::GFX_drawText(120,80, TEXT_SIZE, 0, Cubios::text_align_t::TEXT_ALIGN_CENTER, Colors::white, buff);
70
71 sprintf(buff,"fps: %.2f",this->fps);
72 Cubios::GFX_drawText(120,120, TEXT_SIZE, 0, Cubios::text_align_t::TEXT_ALIGN_CENTER, Colors::green, buff);
73
74 sprintf(buff,"timer: %d s",this->seconds);
75 Cubios::GFX_drawText(120,160, TEXT_SIZE, 0, Cubios::text_align_t::TEXT_ALIGN_CENTER, Colors::blue, buff);
76
77 Cubios::GFX_render();
78 }
79}
80
81//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
82void TimeAndTimers::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
83{
84}
85
86//This callback is called on programmable timer (if any)
87void TimeAndTimers::on_Timer(uint8_t timerID)
88{
89 switch(timerID)
90 {
91 case Timers::myTimer:
92 {
93 this->seconds++;
94 if(this->seconds>99) this->seconds = 0;
95 }
96 break;
97 default:
98 break;
99 }
100}
101
102//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
103void TimeAndTimers::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
104{
105}
106
107//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
108void TimeAndTimers::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
109{
110}
111
112//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
113void TimeAndTimers::on_ExternalMessage(uint8_t* pkt, u32_t size)
114{
115}
116
117//Screen pat callback
118void TimeAndTimers::on_Pat(uint32_t count)
119{
120}