WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Examples
  4. StringsAndArrays.cpp
Mission NodeSDK 6.1C++basicsProject Included

StringsAndArrays.cpp

Example: StringsAndArrays.cpp

Examples / SDK 6.1 / C++ / basics / Strings and Arrays / project / src
StringsAndArrays.cpp
CPP
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#include <math.h>
9
10#include "AppManager.h"
11#include "StringsAndArrays.h"
12
13using namespace Cubios::Gfx;
14
15//Applicaton initialization callback. Called once when CUB application starts
16void OnInit(Cubios::AppManager& appMgr)
17{
18 StringsAndArrays* theApp = new StringsAndArrays();
19
20 appMgr.SetApplication(theApp,"AAbbCCddEE");
21
22 theApp->InitializeResources();
23
24}
25
26
27StringsAndArrays::StringsAndArrays():
28 firstFrame(0),i1(0),i2(0),
29 arrWOWCUBE{'W','O','W','C','U','B','E',' '},
30 arrWOWCUBE2{"WOWCUBE","IS","COOL"},
31 arrTWISTY{"T","W","I","S","T","Y"},
32 fParam{0 ,20 ,10 ,-10,-20,-10},
33 prevPos{0,0,0,0,0,0,0,0,0,0,0,0}
34
35{
36}
37
38StringsAndArrays::~StringsAndArrays()
39{
40}
41
42void StringsAndArrays::InitializeResources()
43{
44 LOG_i("\n");
45 LOG_i("*** WOWCube SDK Example \"Strings and Arrays\" ***\n");
46
47 LOG_i("Cubeapp is initializing...");
48 LOG_i("Cubeapp is started on module %d",this->Module);
49
50 //Set up timers
51 this->SetTimer(Timers::myTimer,100);
52 this->SetTimer(Timers::myTimer2,1000);
53
54 //clear buffer
55 this->buff2 = "";
56
57 LOG_i("Done.");
58}
59
60
61//This callback is called every "tick" of cubeapp application loop
62void StringsAndArrays::on_Tick(uint32_t currentTime, uint32_t deltaTime)
63{
64}
65
66//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
67void StringsAndArrays::on_Render(std::array<Cubios::Screen, 3>& screens)
68{
69 for(auto it = screens.begin(); it != screens.end(); ++it)
70 {
71 Cubios::GFX_setRenderTarget(it->ID());
72 Cubios::GFX_clear(Colors::black);
73
74 switch(it->ID())
75 {
76 case 0:
77 Cubios::GFX_drawText(120,120, TEXT_SIZE, 0, Cubios::text_align_t::TEXT_ALIGN_CENTER, Colors::teal, buff2.c_str());
78 break;
79 case 1:
80 if(i2<3)
81 {
82 if(i2>=0) GFX_drawText(120,120-50, TEXT_SIZE+2, 0, Cubios::text_align_t::TEXT_ALIGN_CENTER, MyColors::blue1, this->arrWOWCUBE2[0].c_str());
83 if(i2>=1) GFX_drawText(120,120, TEXT_SIZE+2, 0, Cubios::text_align_t::TEXT_ALIGN_CENTER, MyColors::blue2, this->arrWOWCUBE2[1].c_str());
84 if(i2>=2) GFX_drawText(120,120+50, TEXT_SIZE+2, 0, Cubios::text_align_t::TEXT_ALIGN_CENTER, MyColors::blue3, this->arrWOWCUBE2[2].c_str());
85 }
86 break;
87 case 2:
88 {
89 int x = 0;
90 float offset = 0;
91
92 for(size_t i=0;i<arrTWISTY.size();i++)
93 {
94 offset = sinf(this->fParam[i])*30;
95
96 this->fParam[i]+=0.15f;
97
98 if(firstFrame==0)
99 {
100 firstFrame = 1;
101 }
102 else
103 {
104 if(firstFrame==1)
105 {
106 firstFrame = 2;
107 GFX_drawText(10+x,DISPLAY_HEIGHT/2+prevPos[i][0]+10, TEXT_SIZE, 0, Cubios::text_align_t::TEXT_ALIGN_LEFT_CORNER, MyColors::pink2, this->arrTWISTY[i].c_str());
108 }
109 else
110 {
111 GFX_drawText(10+x,DISPLAY_HEIGHT/2+prevPos[i][1]+20, TEXT_SIZE, 0, Cubios::text_align_t::TEXT_ALIGN_LEFT_CORNER, MyColors::pink3, this->arrTWISTY[i].c_str());
112 GFX_drawText(10+x,DISPLAY_HEIGHT/2+prevPos[i][0]+10, TEXT_SIZE, 0, Cubios::text_align_t::TEXT_ALIGN_LEFT_CORNER, MyColors::pink2, this->arrTWISTY[i].c_str());
113 }
114 }
115
116 prevPos[i][1] = prevPos[i][0];
117 prevPos[i][0] = (int)(offset);
118
119 GFX_drawText(10+x,DISPLAY_HEIGHT/2+prevPos[i][0], TEXT_SIZE, 0, Cubios::text_align_t::TEXT_ALIGN_LEFT_CORNER, MyColors::pink1, this->arrTWISTY[i].c_str());
120 x+=40;
121 }
122 }
123 break;
124 }
125
126 Cubios::GFX_render();
127 }
128}
129
130//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
131void StringsAndArrays::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
132{
133}
134
135//This callback is called on programmable timer (if any)
136void StringsAndArrays::on_Timer(uint8_t timerID)
137{
138 switch(timerID)
139 {
140 case Timers::myTimer:
141 {
142 this->buff2+=this->arrWOWCUBE[i1];
143
144 i1++;
145 if(i1>7)
146 {
147 i1=0;
148 this->buff2 = " ";
149 }
150 }
151 break;
152 case Timers::myTimer2:
153 {
154 this->i2++;
155 if(this->i2>3) this->i2 = 0;
156 }
157 break;
158 default:
159 break;
160 }
161}
162
163//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
164void StringsAndArrays::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
165{
166}
167
168//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
169void StringsAndArrays::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
170{
171}
172
173//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
174void StringsAndArrays::on_ExternalMessage(uint8_t* pkt, u32_t size)
175{
176}
177
178//Screen tap callback
179void StringsAndArrays::on_Tap(uint32_t count)
180{
181}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

StringsAndArrays.cpp
project/src/StringsAndArrays.cpp
StringsAndArrays.h
project/src/StringsAndArrays.h
wowcubeapp-build.json
project/wowcubeapp-build.json
Context Rail

Related nodes

StringsAndArrays.h
Examples / SDK 6.1 / C++ / basics / Strings and Arrays / project / src
Strings and Arrays
Examples / SDK 6.1 / C++ / basics
info.json
Examples / SDK 6.1 / C++ / basics / Strings and Arrays
wowcubeapp-build.json
Examples / SDK 6.1 / C++ / basics / Strings and Arrays / project
Previous Node
info.json
Examples / SDK 6.1 / C++ / basics / Strings and Arrays
Next Node
StringsAndArrays.h
Examples / SDK 6.1 / C++ / basics / Strings and Arrays / project / src