Page MenuHomec4science

main.cpp
No OneTemporary

File Metadata

Created
Fri, May 3, 12:03

main.cpp

#include <stdio.h>
#include "../cellulounity.h"
#include <unistd.h>
#include <pthread.h>
#include <QDebug>
void onKidnappedChanged() {
qDebug() << "callback: kidnapped changed";
}
void* testCellulo(void* arg) {
// LED colors
int r, g, b; r = g = b = 0;
// creating and destroying robots
while(true)
{
// starting the library
initialize();
// waiting for connection
while(true) {
if(robotsRemaining() <= 1) {
qDebug() << "robots remaining: " << robotsRemaining();
sleep(1);
}
else break;
}
// creating robot
long robot = newRobot();
fprintf(stderr, "Got robot %x\n", robot);
// will react on kidnapping
setKidnappedCallback(robot, &onKidnappedChanged);
// printing data
qDebug() << getX(robot) << getY(robot) << getTheta(robot) << (getKidnapped(robot) ? "true" : "false");
// updating LED color
setVisualEffect(robot, 0, r, g, b, 255);
r += 50;
r %= 255;
// waiting and reinitizlizing library
// will connect to the same robot on next iteration if there are no other users of the library
sleep(1);
destroyRobot(robot);
initialize();
}
return NULL;
}
int main() {
pthread_t thread;
pthread_create(&thread, NULL, testCellulo, NULL);
pthread_join(thread, NULL);
return 0;
}

Event Timeline