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 "HandleTwists.h"
11
12using namespace Cubios::Gfx;
13
14//Applicaton initialization callback. Called once when CUB application starts
15void OnInit(Cubios::AppManager& appMgr)
16{
17 HandleTwists* theApp = new HandleTwists();
18
19 appMgr.SetApplication(theApp,"AAbbCCddEE");
20
21 theApp->InitializeResources();
22
23}
24
25
26HandleTwists::HandleTwists():screen(-1),direction(Cubios::TOPOLOGY_twist_t::TWIST_UNINDENTIFIED),animationOffset(0)
27{
28}
29
30HandleTwists::~HandleTwists()
31{
32}
33
34void HandleTwists::InitializeResources()
35{
36 LOG_i("\n");
37 LOG_i("WOWCube SDK Example \"Topology - Handling Twists\" ***\n");
38
39 LOG_i("Cubeapp is initializing...");
40 LOG_i("Cubeapp is started on module %d",this->Module);
41
42 this->left = Cubios::GFX_getAssetId("left.png");
43 this->right = Cubios::GFX_getAssetId("right.png");
44 this->dbl = Cubios::GFX_getAssetId("dbl.png");
45
46 this->iconPos.X = 120;
47 this->iconPos.Y = 120;
48
49 LOG_i("Done.");
50}
51
52
53//This callback is called every "tick" of cubeapp application loop
54void HandleTwists::on_Tick(uint32_t currentTime, uint32_t deltaTime)
55{
56}
57
58//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
59void HandleTwists::on_Render(std::array<Cubios::Screen, 3>& screens)
60{
61 for(auto it = screens.begin(); it != screens.end(); ++it)
62 {
63 Cubios::GFX_setRenderTarget(it->ID());
64 Cubios::GFX_clear(Colors::black);
65
66 if(it->ID()==this->screen)
67 {
68 iconPos.X = 120+this->animationOffset;
69
70 switch(this->direction)
71 {
72 case Cubios::TOPOLOGY_twist_t::TWIST_LEFT:
73 {
74 this->iconPos.X = 120+this->animationOffset;
75 Cubios::GFX_drawImage(this->left, this->iconPos.X, this->iconPos.Y, 0xFF, Cubios::Gfx::Colors::black,100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
76 }
77 break;
78 case Cubios::TOPOLOGY_twist_t::TWIST_RIGHT:
79 {
80 this->iconPos.X = 120-this->animationOffset;
81 Cubios::GFX_drawImage(this->right, this->iconPos.X, this->iconPos.Y, 0xFF, Cubios::Gfx::Colors::black,100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
82 }
83 break;
84 case Cubios::TOPOLOGY_twist_t:: TWIST_DOUBLE:
85 Cubios::GFX_drawImage(this->dbl,120,120, 0xFF, Cubios::Gfx::Colors::black,100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
86 break;
87 default:
88 break;
89 }
90 }
91
92 Cubios::GFX_render();
93 }
94}
95
96//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
97void HandleTwists::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
98{
99 if(this->animationOffset>0)
100 this->animationOffset-=50;
101}
102
103//This callback is called on programmable timer (if any)
104void HandleTwists::on_Timer(uint8_t timerID)
105{
106}
107
108//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
109void HandleTwists::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
110{
111 this->screen = twist.screen;
112 this->direction = (Cubios::TOPOLOGY_twist_t)twist.direction;
113
114 this->animationOffset = 200;
115}
116
117//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
118void HandleTwists::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
119{
120}
121
122//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
123void HandleTwists::on_ExternalMessage(uint8_t* pkt, u32_t size)
124{
125}
126
127//Screen tap callback
128void HandleTwists::on_Tap(uint32_t count)
129{
130}