Exemple #1
0
MainService::MainService(int argc, char* argv[])
{
		setServiceDescription("The daemon for monitoring and handling the g15 macro service");
		setServiceFlags(QtServiceBase::Default); //Stopped but not suspended

		thread_keys = new KeyThread();
		connect(thread_keys, SIGNAL(writeDbg(const QString)), this, SLOT(writeDbg(const QString)));
		connect(this, SIGNAL(sendExit()), thread_keys, SLOT(setExit()));

		thread_x = new XThread();
		connect(thread_x, SIGNAL(writeDbg(const QString)), this, SLOT(writeDbg(const QString)));
		connect(this, SIGNAL(sendExit()), thread_x, SLOT(setExit()));

		connect(thread_keys, SIGNAL(sendRecordingStatus(bool, int, int)), thread_x, SLOT(setRecordingStatus(bool, int, int)));
		connect(thread_keys, SIGNAL(playbackMacro(int, int)), thread_x, SLOT(playbackMacro(int, int)));
}
	//------------------------------------------------------------------
	void DefaultInputSystem::windowClosed( RenderWindow* _window )
	{
		WindowEventListeners::Iterator it = mWindowEventListeners.getIterator();
		while(it.hasMoreElements())
		{
			BaseWindowEventListener* windowEventListener = it.getNext();
			windowEventListener->windowClosed();
		}
		sendExit();
	}
//--------------------------------------------------------------
void ofxMatrixNetworkServer::exit() {
    //for each client lets send them a message letting them know what port they are connected on
	for(int i = 0; i < getLastID(); i++){
		if(isClientConnected(i)){
            sendExit(i);
            disconnectClient(i);
        }
	}
    
    close();
}
Exemple #4
0
NodeTypesPanel::NodeTypesPanel()
{
	layout = new QGridLayout;
	layout->setAlignment(Qt::AlignTop);

	int row = 0;
	caption = new QLabel("<h2>" + i18n("Custom Node Types") + "</h2>");
	layout->addWidget(caption, row, 0);
	++row;

	typelist = new QListWidget;
	layout->addWidget(typelist, row, 0, 4, 1);
	++row;
	typelist->addItems(Controller::create()->getDataStore()->getCustomNodeTypeNames());

	btnAdd = new QPushButton(i18n("Add new Node Type"));
	layout->addWidget(btnAdd, row, 1);
	++row;
	connect(btnAdd, SIGNAL(clicked()), this, SLOT(addType()));

	btnEdit = new QPushButton(i18n("Edit Node Type"));
	layout->addWidget(btnEdit, row, 1);
	++row;
	connect(btnEdit, SIGNAL(clicked()), this, SLOT(editType()));

	btnDelete = new QPushButton(i18n("Delete Node Type"));
	layout->addWidget(btnDelete, row, 1);
	++row;
	connect(btnDelete, SIGNAL(clicked()), this, SLOT(deleteType()));

	btnExit = new QPushButton(i18n("Close"));
	btnExit->setMinimumWidth(100);
	layout->addWidget(btnExit, row, 0, 1, 1, Qt::AlignRight);
	connect(btnExit, SIGNAL(clicked()), this, SLOT(sendExit()));
	setLayout(layout);

	connect(typelist, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons()));
	updateButtons();
}
Exemple #5
0
NodeTypeManager::NodeTypeManager()
{
	layout = new QVBoxLayout;
	layout->setAlignment(Qt::AlignTop);
	nodetypespanel = new NodeTypesPanel;
	layout->addWidget(nodetypespanel);
	connect(nodetypespanel, SIGNAL(exit()), this, SLOT(sendExit()));
	connect(nodetypespanel, SIGNAL(addNodeType()), this, SLOT(showInputWidget()));
	connect(nodetypespanel, SIGNAL(editNodeType(QString)), this, SLOT(showNodeTypeBuilder(QString)));
	connect(nodetypespanel, SIGNAL(deleteNodeType(QString)), this, SLOT(deleteNodeType(QString)));

	inputwidget = new InputWidget;
	inputwidget->setVisible(false);
	layout->addWidget(inputwidget);
	connect(inputwidget, SIGNAL(done()), this, SLOT(addNodeType()));

	nodetypebuilder = new NodeTypeBuilder;
	nodetypebuilder->setVisible(false);
	layout->addWidget(nodetypebuilder);
	connect(nodetypebuilder, SIGNAL(close()), this, SLOT(hideNodeTypeBuilder()));

	setLayout(layout);
}
Exemple #6
0
/**
 * Main robot function that controls the behaviour of the robot.
 * Needs a connected socket to communicate with the simulator or HW
 */
 void robot(int sck, FILE *sckfd)
 {
 	int val1;

 	int curX = 2;
 	int curY = 0;
 	int direction = NORTH;
 	initRobot(sck, 100, curX, curY);
	//initGrid();
 	int nummoves = 0;

	// Challenge A/B
 	int destX = 5, destY = 5;

 	FILE *file;
 	file = fopen("log.txt", "w");

	// Loop until destination is reached
 	while (1) {
		// system("cls");
 		int nextX, nextY, dir, rotation;
 		calculateRoute(curX, curY, destX, destY);
 		d_printGrid(curX, curY);

 		if (!nodes[curX][curY]->next) {
 			fprintf(stderr, "No route found\n");
 			sendExit(sck);
 			return;
 		}

 		nextX = nodes[curX][curY]->next->pos.x;
 		nextY = nodes[curX][curY]->next->pos.y;
 		dir = findDirection(curX, curY, nextX, nextY);

 		rotation = dir - direction;
 		if (rotation > 2)
 			rotation -= 4;
 		if (rotation < -2)
 			rotation += 4;

 		fprintf(stderr, "Next (%d,%d), rotation: %d\n", nextX, nextY, dir);
		if (rotation < 0) { //turn left
			fprintf(file, "Turn left %d\r\n", abs(rotation));
			setCommand(sck, TURN, 1, abs(rotation), 0);
		} else if (rotation > 0) {//turn right
			fprintf(file, "Turn right %d\r\n", abs(rotation));
			setCommand(sck, TURN, 2, rotation, 0);
		}

		fflush(file);

		// wait until robot is ready with turning
		if (rotation != 0) {
			while (1) {
				getCommand(sck, sckfd, READY, 1, &val1, NULL);
				if (val1 == 1)
					break;

			}
			fprintf(file, "Ready!\r\n");
		}
		// Update direction
		direction = dir;

		if (curY == 0 || curY == 6 || curX == 0 || curX == 6)
			nummoves = 1;
		else
			nummoves = 2;

		printf("Cur (%d,%d) Nummoves: %d\n", curX, curY, nummoves);
		printf("Move forward\n");
		fprintf(file, "Move forward %d\r\n", nummoves);
		fflush(file);

		setCommand(sck, MOVE, 1, nummoves, 0);

		if (nummoves == 1) {

			// Wait while not ready
			while (1) {
				getCommand(sck, sckfd, READY, 1, &val1, NULL);
				if (val1 == 1) {
					break;
				}

			}
			curX = nextX;
			curY = nextY;
		} else if (nummoves == 2) {

			// Wait while not ready
			while (1) {
				getCommand(sck, sckfd, READY, 1, &val1, NULL);
				if (val1 == 1) {
					break;
				}

			}

			// Check for mine
			printf("Check for mine\n");
			getCommand(sck, sckfd, MINE, 1, &val1, NULL);

			if (val1 == 1) {
				//removeConnection(x1, y1, x2, y2);
				// Clear mine flag
				setCommand(sck, MINE, 1, 0, 0);
				fprintf(file, "Mine found!\r\n");
				printf("Mine found!\n");
				// Get back!:D
				//return 0;
			} else {
				printf("No mine found!\n");
			}
		}


	}
	fclose(file);
	sendExit(sck);
}
Exemple #7
0
MainService::stop()
{
		//shutdown the threads
		sendExit();
}