Example #1
0
void Mwars::on_pbRectangle_clicked()
{
    if(rectangleIsRunning) {
        QMessageBox::critical(this, "Error", "Rectangle is already running");
        return;
    }

    workerThread = new QThread();            // instantiates ScannerDraw class and the QThread
    scannerDraw = new ScannerDraw(this, 33, 44);   // on heap

    scannerDraw->moveToThread(workerThread);
    connect(workerThread, SIGNAL(started()), scannerDraw, SLOT(drawRectangle()));

    connect(scannerDraw, SIGNAL(finished()), workerThread, SLOT(quit()), Qt::DirectConnection);
    connect(scannerDraw, SIGNAL(finished()), scannerDraw, SLOT(deleteLater()));
    connect(scannerDraw, SIGNAL(finished()), workerThread, SLOT(deleteLater()));

    connect(workerThread, SIGNAL(finished()), this, SLOT(rectangleFinished()));

    connect(ui->pbStopRectangle, SIGNAL(clicked()), this, SLOT(stopRectangle()));

    // need these signals cause can't call sockets across threads
    connect(scannerDraw, SIGNAL(sendScannerMssg (ushort, ushort, ushort)), this, SLOT(sendScannerMssg(ushort, ushort, ushort)));
    connect(scannerDraw, SIGNAL (laserOn()), this, SLOT(laserOn()));
    connect(scannerDraw, SIGNAL (laserOff()), this, SLOT(laserOff()));
    connect(scannerDraw, SIGNAL (scannerOn()), this, SLOT(scannerOn()));
    connect(scannerDraw, SIGNAL (scannerOff()), this, SLOT(scannerOff()));

    workerThread->start();

    rectangleIsRunning = true;
    ui->pbStopRectangle->setEnabled(true);
}
Example #2
0
//--------------------------------------------------------------------------------------
// void Mwars::laserToggle(void)
//		signals:	pbLaserToggle(clicked)
// Enable Scanner button signal comes here
// Note: a toggle
//-------------------------------------------------------------------------------------
void Mwars::on_pbLaserToggle_clicked(void) {
//void Mwars::laserToggle(void) {

   if (laserOnFlag)        // Is ON; turn off scanner
      laserOff();
   else                      // Is OFF, turn on
      laserOn();
}
Example #3
0
int main() {
	sei();
	timerInit();

	ledInit();
	ledOn();
	delay(100);
	ledOff();

	packet.s.nodeId = eeprom_read_byte(I2C_ADDRESS_EEPROM_LOCATION);

	SPI.begin();
	laserInit();
	adcInit();

	detectorInit();
	detectorCalibrate();

	uint8_t radioInitialised = radio.initialize(RF69_868MHZ, packet.s.nodeId, 100);
	radio.encrypt(0);
	if(radioInitialised) {
		ledOn();
		delay(1500);
		sendStatusPacket();
		ledOff();
	} else {
		ledRapidBlink(2);
	}
	
	laserOn();

	while(1) {

		if(laserTripped) {
			ledOn();
			sendStatusPacket();
			delay(10);
			while((0 == (PINB & _BV(PB1)))){
				//WAIT
			}
			sendLaserVisiblePacket();
			detectorArm();
			while(0 == (PINA & _BV(PA3))) {
				//WAIT
			}
		} else {
			ledOff();
		}

		if(laserTripped || 0 == (PINA & _BV(PA3))) {
			sendStatusPacket();
			delay(300);
			while(0 == (PINA & _BV(PA3))) {
				//WAIT
			}
			delay(300);
		}


		if(radio.receiveDone()) {
			switch((char)radio.DATA[0]) {
				case CMD_LASER_ON: laserOn(); break;
				case CMD_LASER_OFF: laserOff(); break;
				case CMD_CALIBRATE: detectorCalibrate(); break;
				case CMD_GET_STATUS: waitAndSendStatus(); break;
			}
		}

		if(isBatteryLow()) {
			laserOff();
			radio.sleep();
			while(1) {
				ledRapidBlink(10);
				delay(2000);
			}
		}
	}
}
Example #4
0
void laserToggle(void) {
	if (laserState)
		laserOff();
	else
		laserOn();
}
//--------------------------------------------------------------------------------------
// void Mwars::alignBoresight(void)
//		signal: pbCalLaserBsight (clicked)
//
//  this just enables the calibration buttons
//--------------------------------------------------------------------------------------
void Mwars::alignBoresight(void) {

    scannerOn();
    centre_scanner();   // this also send the centering message to scanner
    laserOn();
}