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. main.pwn
Mission NodeSDK 6.3PawnnetworkProject Included

main.pwn

Example: main.pwn

Examples / SDK 6.3 / Pawn / network / Messaging / project / src
main.pwn
C
1// This PAWN script is generated by WOWCube SDK project wizard
2
3#define G2D
4
5#pragma warning disable 203
6#pragma warning disable 213
7#pragma warning disable 229
8
9// Includes
10// -----------------------------
11
12#include "wowcore.inc"
13#include "topology.inc"
14#include "graphics.inc"
15#include "motion_sensor.inc"
16#include "math.inc"
17#include "log.inc"
18
19// Application defines
20// -----------------------------
21#define TEXT_SIZE 14
22
23// Application constants
24// ------------------------------
25new const Colors[.white, .black, .red, .green, .blue] =
26[
27 0xFFFFFFFF,
28 0xFF000000,
29 0xFFFF0000,
30 0xFF00FF00,
31 0xFF0000FF,
32];
33
34const e_Commands:
35{
36 cmd_paintGreen = 0,
37 cmd_paintBlue = 1,
38 cmd_paintRed = 2
39}
40
41// Application variables
42// -----------------------------
43new Application[bool:.received,.counter,.currentColor];
44
45
46// WOWCube application callbacks
47// -----------------------------
48
49//Applicaton initialization callback. Called once when CUB application starts
50public ON_Init(id, size, const pkt[])
51{
52 LOG_i("\n");
53 LOG_i("*** WOWCube SDK Example \"Network Messaging\" ***\n\n");
54
55 LOG_i("Cubeapp is initializing...\n");
56 LOG_i("Cubeapp is started on module %d\n",SELF_ID);
57
58 Application.received = false;
59 Application.counter = 0;
60 Application.currentColor = Colors.black;
61
62 LOG_i("Done.\n");
63}
64
65//Saved application state data load callback. Gets called in response to loadState() function call
66public ON_Load(id, size, const pkt[])
67{
68}
69
70//Main run loop callback. Gets called recurrently by the CUB application as frequent as application code allows.
71public ON_Tick()
72{
73}
74
75//This callback is gets called immediately after ON_Tick(). Use it for calling your rendering code.
76public ON_Render()
77{
78 for(new screenNumber = 0; screenNumber<3; screenNumber++)
79 {
80 GFX_setRenderTarget(screenNumber);
81
82 if(SELF_ID==0)
83 {
84 GFX_clear(Colors.red);
85
86 GFX_drawText([ 120,80 ], TEXT_SIZE, 0, 0, TEXT_ALIGN_CENTER, Colors.white, "PAT");
87 GFX_drawText([ 120,160 ], TEXT_SIZE, 0, 0, TEXT_ALIGN_CENTER, Colors.white, "ME");
88 }
89 else
90 {
91 GFX_clear(Application.currentColor);
92 }
93
94 GFX_render();
95 }
96}
97
98
99//The "physics" callback. Gets called recurrently with 30ms resolution.
100public ON_PhysicsTick()
101{
102}
103
104//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
105public ON_Packet(type, size, const pkt[])
106{
107 if(SELF_ID!=0)
108 {
109 switch (type)
110 {
111 case cmd_paintBlue:
112 {
113 Application.currentColor = Colors.blue;
114 }
115 case cmd_paintGreen:
116 {
117 Application.currentColor = Colors.green;
118 }
119 case cmd_paintRed:
120 {
121 Application.currentColor = Colors.red;
122 }
123
124 }
125 }
126}
127
128//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
129public ON_Twist(twist[TOPOLOGY_TWIST_INFO])
130{
131 if (SELF_ID == 0)
132 {
133 }
134 else
135 {
136 }
137}
138
139//Screen pat callback.
140public ON_Pat(const count, const display, const bool:opposite)
141{
142 if (SELF_ID == 0)
143 {
144 //When device is tapped, module 0 will broadcast commands to all neighbouring modules
145 sendDataToNeighbours();
146 }
147 else
148 {
149 }
150}
151
152//Application quit callback.
153public ON_Quit()
154{
155 //
156 //Save game data here
157 //
158}
159
160// User-defined functions
161// -----------------------------
162
163sendDataToNeighbours()
164{
165 new data[1];
166 new const type[3] = [cmd_paintBlue, cmd_paintGreen, cmd_paintRed];
167
168 broadcastPacket(type[Application.counter], data); // broadcast data over UART
169
170 if(Application.counter<2) Application.counter++; else Application.counter = 0;
171}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

main.pwn
project/src/main.pwn
wowcubeapp-build.json
project/wowcubeapp-build.json
Context Rail

Related nodes

Messaging
Examples / SDK 6.3 / Pawn / network
info.json
Examples / SDK 6.3 / Pawn / network / Messaging
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / network / Messaging / project
Messaging
Examples / SDK 6.3 / C++ / network
Previous Node
info.json
Examples / SDK 6.3 / Pawn / network / Messaging
Next Node
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / network / Messaging / project