Example: StringsAndArrays.cpp
1// This file is generated by WOWCube SDK project wizard23#include <stdint.h>4#include <string>5#include <vector>6#include <string>7#include <memory>8#include <math.h>910#include "AppManager.h"11#include "StringsAndArrays.h"1213using namespace Cubios::Gfx;1415//Applicaton initialization callback. Called once when CUB application starts16void OnInit(Cubios::AppManager& appMgr)17{18 StringsAndArrays* theApp = new StringsAndArrays();1920 appMgr.SetApplication(theApp,"AAbbCCddEE");2122 theApp->InitializeResources();2324}252627StringsAndArrays::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}3435{36}3738StringsAndArrays::~StringsAndArrays()39{40}4142void StringsAndArrays::InitializeResources()43{44 LOG_i("\n");45 LOG_i("*** WOWCube SDK Example \"Strings and Arrays\" ***\n");4647 LOG_i("Cubeapp is initializing...");48 LOG_i("Cubeapp is started on module %d",this->Module);4950 //Set up timers51 this->SetTimer(Timers::myTimer,100);52 this->SetTimer(Timers::myTimer2,1000);5354 //clear buffer55 this->buff2 = "";5657 LOG_i("Done.");58}596061//This callback is called every "tick" of cubeapp application loop62void StringsAndArrays::on_Tick(uint32_t currentTime, uint32_t deltaTime)63{64}6566//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);7374 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;9192 for(size_t i=0;i<arrTWISTY.size();i++)93 {94 offset = sinf(this->fParam[i])*30;9596 this->fParam[i]+=0.15f;9798 if(firstFrame==0)99 {100 firstFrame = 1;101 }102 else103 {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 else110 {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 }115116 prevPos[i][1] = prevPos[i][0];117 prevPos[i][0] = (int)(offset);118119 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 }125126 Cubios::GFX_render();127 }128}129130//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}134135//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];143144 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}162163//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed164void StringsAndArrays::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)165{166}167168//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module169void StringsAndArrays::on_Message(uint32_t type, uint8_t* pkt, u32_t size)170{171}172173//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source174void StringsAndArrays::on_ExternalMessage(uint8_t* pkt, u32_t size)175{176}177178//Screen tap callback179void StringsAndArrays::on_Tap(uint32_t count)180{181}