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. Messaging2.cpp
Mission NodeSDK 6.2C++networkProject Included

Messaging2.cpp

Example: Messaging2.cpp

Examples / SDK 6.2 / C++ / network / Messaging Part II / project / src
Messaging2.cpp
CPP
1// This file is generated by WOWCube SDK project wizard
2//
3// Application UUID: 9WEBpryloR
4//
5
6#include <stdint.h>
7#include <string>
8#include <vector>
9#include <string>
10#include <memory>
11
12#include "AppManager.h"
13#include "Messaging2.h"
14
15using namespace Cubios;
16using namespace Cubios::Math;
17using namespace Cubios::Gfx;
18
19//Applicaton initialization callback. Called once when CUB application starts
20void OnInit(Cubios::AppManager& appMgr)
21{
22 Messaging2* theApp = new Messaging2();
23
24 appMgr.SetApplication(theApp,"9WEBpryloR");
25
26 theApp->InitializeResources();
27}
28
29
30Messaging2::Messaging2():dot_x(0),beat(0)
31{
32}
33
34Messaging2::~Messaging2()
35{
36 this->Scene.DisposeAllObjects();
37}
38
39void Messaging2::InitializeResources()
40{
41 //Create a Cubios::Gfx::Sprite object
42 this->Scene.CreateObjectWithID(GfxObjects::idle,new Sprite("idle.png",Transform(120,120,0)));
43 this->Scene[GfxObjects::idle]->Color.Set(0xFFFFFFFF);
44 this->Scene[GfxObjects::idle]->Color.SetA(255);
45
46 this->Scene.CreateObjectWithID(GfxObjects::beat,new Sprite("beat.png",Transform(120,120,0)));
47 this->Scene[GfxObjects::beat]->Color.Set(0xFFFFFFFF);
48 this->Scene[GfxObjects::beat]->Color.SetA(255);
49
50 this->Scene.CreateObjectWithID(GfxObjects::dot,new Sprite("dot.png",Transform(120,120,0)));
51 this->Scene[GfxObjects::dot]->Color.Set(0xFFFFFFFF);
52 this->Scene[GfxObjects::dot]->Color.SetA(255);
53
54 this->Scene.CreateObjectWithID(GfxObjects::background,new Sprite("background.png",Transform(120,120,0)));
55 this->Scene[GfxObjects::background]->Color.Set(0xFFFFFFFF);
56 this->Scene[GfxObjects::background]->Color.SetA(255);
57
58 this->Scene.CreateObjectWithID(GfxObjects::cachette,new Sprite("cachette.png",Transform(120,120,0)));
59 this->Scene[GfxObjects::cachette]->Color.Set(0xFFFFFFFF);
60 this->Scene[GfxObjects::cachette]->Color.SetA(255);
61
62 this->SetTimer(Timers::mainTimer,30);
63}
64
65//This callback is called every "tick" of cubeapp application loop
66void Messaging2::on_Tick(uint32_t currentTime, uint32_t deltaTime)
67{
68 if(this->Module!=0)
69 {
70 if(!Cubios::TOPOLOGY_isAssembled()) this->beat = 0;
71 }
72}
73
74//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
75void Messaging2::on_Render(std::array<Cubios::Screen, 3>& screens)
76{
77 for(auto it = screens.begin(); it != screens.end(); ++it)
78 {
79 //Start adding objects to a screen
80 it->Begin(TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true);
81
82 it->Add(this->Scene[GfxObjects::background]);
83
84 if(beat==0)
85 {
86 it->Add(this->Scene[GfxObjects::idle]);
87 it->Add(this->Scene[GfxObjects::dot])->SetPosition(this->dot_x,122);
88 }
89 else
90 {
91 it->Add(this->Scene[GfxObjects::beat])->SetA(this->beat);
92 it->Add(this->Scene[GfxObjects::idle])->SetA(255-this->beat);
93 it->Add(this->Scene[GfxObjects::dot])->SetPosition(this->dot_x,122)->SetA(255-this->beat);
94 }
95
96 it->Add(this->Scene[GfxObjects::cachette]);
97
98 //Finish adding objects
99 it->End();
100 }
101}
102
103//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
104void Messaging2::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
105{
106}
107
108//This callback is called on programmable timer (if any)
109void Messaging2::on_Timer(uint8_t timerID)
110{
111 if(timerID==Timers::mainTimer)
112 {
113 this->dot_x+=10;
114 if(this->dot_x>240) this->dot_x = 0;
115
116 if(this->Module==0)
117 {
118 if(this->beat == 0)
119 {
120 if(this->dot_x==140)
121 {
122 this->beat = 255;
123
124 //Send the position to other modules
125 this->timerMessage.Reset(true);
126 this->timerMessage.WriteByte(255);
127 this->timerMessage.WriteByte(this->dot_x);
128
129 this->SendNetworkMessage(0, &this->timerMessage);
130 }
131 }
132 else
133 {
134 this->beat-=30;
135 if(this->beat<0) this->beat = 0;
136 }
137 }
138 else
139 {
140 if(this->beat>0)
141 {
142 this->beat-=30;
143 if(this->beat<0) this->beat = 0;
144 }
145 }
146 }
147}
148
149//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
150void Messaging2::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
151{
152}
153
154//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
155void Messaging2::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
156{
157 NetworkMessage nm(pkt,size);
158
159 if(this->Module!=0)
160 {
161 this->beat = (int)nm.ReadByte();
162 this->dot_x = (int)nm.ReadByte();
163 }
164}
165
166//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
167void Messaging2::on_ExternalMessage(uint8_t* pkt, u32_t size)
168{
169}
170
171//Screen pat callback
172void Messaging2::on_Pat(uint32_t count)
173{
174}
175
176//This callback is called before the application quits
177void Messaging2::on_Close()
178{
179}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

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

Related nodes

Messaging2.h
Examples / SDK 6.2 / C++ / network / Messaging Part II / project / src
Messaging Part II
Examples / SDK 6.2 / C++ / network
info.json
Examples / SDK 6.2 / C++ / network / Messaging Part II
wowcubeapp-build.json
Examples / SDK 6.2 / C++ / network / Messaging Part II / project
Previous Node
info.json
Examples / SDK 6.2 / C++ / network / Messaging Part II
Next Node
Messaging2.h
Examples / SDK 6.2 / C++ / network / Messaging Part II / project / src