Example #1
0
void SMPS::initialize()
{
    value_ = 0;
    IoutSet_ = 0;
    setValue(0);
    powerOff(CHARGING_COMPLETE);
}
Example #2
0
Strategy::statusType Storage::doStrategy()
{
    Strategy::statusType status;
    switch(state) {
        case Charge:
            status = theveninCharge.doStrategy();
            break;
        case Discharge:
            status = theveninDischarge.doStrategy();
            break;
        case Balance:
            status = balancer.doStrategy();
            if(status != RUNNING) {
                powerOff();
                return status;
            }
            break;
    }

    if(status == COMPLETE && doBalance_) {
        status = RUNNING;
        state = Balance;
        //turn one measurement
        balancer.powerOn();
    }

    return status;
}
Example #3
0
/*
        system termination: reset / system power off
        reset   0       power off
                -1      reboot
                0xaa55  halt boot and power off
*/
EXPORT	void	sysExit(W reset)
{
	DisCacheMMU();

        /* after this point, delay such as waitUsec() spends more time than the number indicates // */

	/* LED off */
	cpuLED(0x00);

        /* all interrupts disabled */
	out_w(IT0_IDS0, ~0);		/* CPU: all interrupts disabled */
	out_w(IT0_IDS1, ~0);
	out_w(IT0_IDS2, ~0);
	out_w(IT3_IPI0_CLR, 0x0000003f);
	out_w(IT3_IDS0, ~0);		/* DSP: all interrupts disabled */
	out_w(IT3_IDS1, ~0);
	out_w(IT3_IDS2, ~0);
	out_w(IT0_IPI3_CLR, 0x0000003f);
	out_w(IT0_FID, 0x00000001);	/* FIQ disabled */
	out_w(IT0_LIIR, 0x0000000f);	/* internal interrupt disabled */

        /* power on controller initialization */
	pmicInit();

        /* USB power off */
	usbPower(FALSE);

	if (reset >= 0) powerOff();

        /* reset start */
	resetStart();
}
Example #4
0
float Grove_Joint::BatteryManager(void)
{  
  static bool ledFlip = false;
  static long clock = millis();
  
  BatteryLevel = BatteryLevel * 0.6 + getBatteryLevel() * 0.4;  
  
  if(BatteryLevel <= LowPowerValue) 
  {    
    if(millis()-clock >= 100)
    {
      clock = millis();
      ledFlip ^= 1;
    }
    batteryLedOn(ledFlip);       
  }
  else
  {
    batteryLedOn(OFF);
  }
  if(BatteryLevel <= DangerPowerValue)
  {
    batteryLedOn(ON);
    powerOff();    
  }
  return BatteryLevel;
}
Example #5
0
// 1 frame delay
void setupScaledScreens1() {
    powerOff(backlights[consoleScreen]);
    REG_DISPCNT_SUB &= ~(3<<16); // Disable sub display (for 1 frame. Gotta hide the ugliness...)

    // By next vblank, the scaled image will be ready.
    doAtVBlank(setupScaledScreens2);
}
Example #6
0
void CEC_TV::powerToggle()
{
    if(_powerStatus == CEC_POWER_STATUS_ON)
        powerOff();
    else
        powerOn();
}
void QBluetoothLocalDevicePrivate::setHostMode(QBluetoothLocalDevice::HostMode mode)
{
    if (!isValid())
        return;

    QBluetoothLocalDevice::HostMode currentHostMode = hostMode();
    if (currentHostMode == mode){
        return;
    }
    //If the device is in PowerOff state and the profile is changed then the power has to be turned on
    if (currentHostMode == QBluetoothLocalDevice::HostPoweredOff) {
        qBBBluetoothDebug() << "Powering on";
        powerOn();
    }

    if (mode == QBluetoothLocalDevice::HostPoweredOff) {
        powerOff();
    }
    else if (mode == QBluetoothLocalDevice::HostDiscoverable) { //General discoverable and connectable.
        setAccess(1);
    }
    else if (mode == QBluetoothLocalDevice::HostConnectable) { //Connectable but not discoverable.
        setAccess(3);
    }
    else if (mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) { //Limited discoverable and connectable.
        setAccess(2);
    }
}
Example #8
0
void SMPS::initialize()
{
    value_ = 0;
    IoutSet_ = 0;
    setValue(0);
    on_ = true;
    powerOff();
}
Example #9
0
void SwitchableItem::use(const Point<int> &position,
											 SDL_Keycode key) {
	if (key == SDLK_DOWN) {
		if (mPowered == false) {
			powerOn();
		} else {
			powerOff();
		}
		mTurnedPower = true;
	}
}
Example #10
0
void QBluetoothLocalDevicePrivate::setHostMode(QBluetoothLocalDevice::HostMode mode)
{
    if (!m_settings) {
        TRAPD(err, m_settings = CBTEngSettings::NewL(this));
        if (err) {
            Q_Q(QBluetoothLocalDevice);
            emit q->error(QBluetoothLocalDevice::UnknownError);
            return;
        }
    }

    TInt error = KErrNone;
    switch (mode) {
        case QBluetoothLocalDevice::HostPoweredOff:
            powerOff();
            break;
        case QBluetoothLocalDevice::HostConnectable: {
            TBTPowerStateValue powerState;
            error = m_settings->GetPowerState(powerState);
            if (error == KErrNone) {
                if (powerState == EBTPowerOff) {
                    error = m_settings->SetPowerState(EBTPowerOn);
                }
                TBTVisibilityMode visibilityMode;
                error = m_settings->GetVisibilityMode(visibilityMode);
                if (visibilityMode != EBTVisibilityModeHidden) {
                    error = m_settings->SetVisibilityMode(EBTVisibilityModeHidden);
                }
            }
            break;
        }
        case QBluetoothLocalDevice::HostDiscoverable: {
            TBTPowerStateValue powerState;
            error = m_settings->GetPowerState(powerState);
            if (error == KErrNone) {
                if (powerState == EBTPowerOff) {
                    error = m_settings->SetPowerState(EBTPowerOn);
                }
                TBTVisibilityMode visibilityMode;
                error = m_settings->GetVisibilityMode(visibilityMode);
                if (visibilityMode != EBTVisibilityModeGeneral) {
                    error = m_settings->SetVisibilityMode(EBTVisibilityModeGeneral);
                }
            }
            break;
        }
    }
    if (error != KErrNone) {
        Q_Q(QBluetoothLocalDevice);
        emit q->error(QBluetoothLocalDevice::UnknownError);
    }
}
Example #11
0
void GPRSbee::powerOff_On() {
  
  if(isOn()) {
  
    powerOff();
    
    delay(1000);
    
    powerOn();
    
  }
  
}
Example #12
0
void Distkeep()
{
int DistFrom = 30; // in Cm

int Deadband = 2;
int Distmin = 35;
// In Inches
float COUNTS_PER_INCH = 90.55;

nMotorEncoder[R_Motor] = 0;
nMotorEncoder[L_Motor] = 0;
servo[IRS_1] = 160;
servo[Block_Chuck] = 000;
ClearTimer(T1);
while (SensorValue[IR] != 6 && nMotorEncoder[ L_Motor] / COUNTS_PER_INCH < Distmin && nMotorEncoder[L_Motor] / COUNTS_PER_INCH < Distmin && time100[T1] < 50 )
{

	if ((USreadDist(SONAR_1) < DistFrom - Deadband) && (nMotorEncoder[ L_Motor] / COUNTS_PER_INCH > 18))
	{
		motor[L_Motor] = 25;
		motor[R_Motor] = 50;
  }
  else if ((USreadDist(SONAR_1) > DistFrom + Deadband) && (nMotorEncoder[ L_Motor] / COUNTS_PER_INCH > 18))
  {
  	motor[L_Motor] = 50;
  	motor[R_Motor] = 25;

  }
  else
  {
  	motor[L_Motor] = 50;
		motor[R_Motor] = 50;
	}
	if (time100[T1] > 50 || nMotorEncoder[L_Motor] / COUNTS_PER_INCH > 40)

	{
		motor[L_Motor] = 0;
		motor[R_Motor] = 0;
		powerOff();
		noOp();
		alive();
		StopAllTasks();
		wait10Msec(55);
	}
}
Example #13
0
void setupUnscaledScreens() {
    int screensToSet[2];

    REG_DISPCNT &= ~(3<<16);
    REG_DISPCNT |= 1<<16; // Enable main display

    if (!consoleInitialized) {
        consoleDemoInit(); // Or, consoleInit(menuConsole, ...)
        setPrintConsole(menuConsole);
        BG_PALETTE_SUB[8*16 - 1] = RGB15(17,17,17); // Grey (replaces a color established in consoleDemoInit)
        consoleInitialized = true;
    }
    if (consoleScreen == 0)
        lcdMainOnBottom();
    else
        lcdMainOnTop();

    screensToSet[!consoleScreen] = true;

    if (!(fpsOutput || timeOutput || consoleDebugOutput || isMenuOn() || isFileChooserOn())) {
        screensToSet[consoleScreen] = false;
        REG_DISPCNT_SUB &= ~(3<<16); // Disable sub display
    }
    else {
        screensToSet[consoleScreen] = true;
        REG_DISPCNT_SUB &= ~(3<<16);
        REG_DISPCNT_SUB |= 1<<16; // Enable sub display
    }

    for (int i=0; i<2; i++) {
        if (screensToSet[i]) {
            if (i == consoleScreen)
                doAtVBlank(enableConsoleBacklight);
            else
                powerOn(backlights[i]);
        }
        else
            powerOff(backlights[i]);
    }
}
void QBluetoothLocalDevicePrivate::setHostMode(QBluetoothLocalDevice::HostMode mode)
{
    //if (m_currentMode==mode){
    //    return;
    //}
    //If the device is in PowerOff state and the profile is changed then the power has to be turned on
    //if (m_currentMode == QBluetoothLocalDevice::HostPoweredOff) {
    //    powerOn();

    //}

    if (mode == QBluetoothLocalDevice::HostPoweredOff) {
        powerOff();
    }
    else if (mode == QBluetoothLocalDevice::HostDiscoverable) { //General discoverable and connectable.
        setAccess(1);
    }
    else if (mode == QBluetoothLocalDevice::HostConnectable) { //Connectable but not discoverable.
        setAccess(3);
    }
    else if (mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) { //Limited discoverable and connectable.
        setAccess(2);
    }
}
Example #15
0
int main(void)
{
	int8_t encCnt = 0;
	uint8_t cmd = CMD_END;

	static uint8_t dispPrev = MODE_STANDBY;

	rcInit();
	sndInit();
	matrixInit();
	sei();

	_delay_ms(100);
	powerOff();

	while(1) {
		encCnt = getEncoder();
		cmd = getCmdBuf();

		/* If no command from buttons, try remote control */
		if (cmd == CMD_END)
			cmd = getRcBuf();

		/* Don't handle commands in standby mode except some */
		if (dispMode == MODE_STANDBY) {
			encCnt = 0;
			if (cmd != CMD_RC_STBY && cmd != CMD_BTN_1 && cmd != CMD_BTN_1_2_LONG)
				cmd = CMD_END;
		}
		/* Don't handle buttons in learn mode except some */
		if (dispMode == MODE_LEARN) {
			if (encCnt || cmd != CMD_END)
				displayTime = TIMEOUT_LEARN;
			if (cmd != CMD_BTN_1_LONG && cmd != CMD_BTN_3)
				cmd = CMD_END;
		}

		/* Handle command */
		switch (cmd) {
		case CMD_RC_STBY:
		case CMD_BTN_1:
			if (dispMode == MODE_STANDBY)
				powerOn();
			else
				powerOff();
			break;
		case CMD_RC_MUTE:
		case CMD_BTN_2:
			if (dispMode == MODE_TIME_EDIT) {
				rtcNextEditParam();
				displayTime = TIMEOUT_TIME_EDIT;
			} else {
				if (aproc.mute) {
					sndSetMute(0);
					dispMode = MODE_SND_VOLUME;
				} else {
					sndSetMute(1);
					dispMode = MODE_MUTE;
				}
				displayTime = TIMEOUT_AUDIO;
			}
			break;
		case CMD_RC_MENU:
		case CMD_BTN_3:
			if (dispMode == MODE_LEARN) {
				nextRcCmd();
			} else {
				sndNextParam(&dispMode);
				displayTime = TIMEOUT_AUDIO;
			}
			break;
		case CMD_RC_RED:
		case CMD_RC_GREEN:
		case CMD_RC_YELLOW:
		case CMD_RC_BLUE:
			sndSetInput(cmd - CMD_RC_RED);
			dispMode = MODE_SND_GAIN0 + (cmd - CMD_RC_RED);
			displayTime = TIMEOUT_AUDIO;
			break;
		case CMD_BTN_1_LONG:
			switch (dispMode) {
			case MODE_STANDBY:
			case MODE_LEARN:
				powerOff();
				break;
			default:
				dispMode = MODE_BRIGHTNESS;
				displayTime = TIMEOUT_BR;
				break;
			}
			break;
		case CMD_BTN_2_LONG:
			switch (dispMode) {
			case MODE_TIME_EDIT:
				dispMode = MODE_TIME;
				rtc.etm = RTC_NOEDIT;
				break;
			default:
				dispMode = MODE_TIME_EDIT;
				rtc.etm = RTC_HOUR;
				displayTime = TIMEOUT_TIME_EDIT;
				break;
			}
			break;
		case CMD_RC_NEXT:
		case CMD_BTN_3_LONG:
			if (dispMode >= MODE_SND_GAIN0 && dispMode < MODE_SND_END)
				aproc.input++;
			sndSetInput(aproc.input);
			dispMode = MODE_SND_GAIN0 + aproc.input;
			displayTime = TIMEOUT_AUDIO;
			break;
		case CMD_BTN_1_2_LONG:
			if (dispMode == MODE_STANDBY)
				dispMode = MODE_LEARN;
			switchTestMode(CMD_RC_STBY);
			displayTime = TIMEOUT_LEARN;
			break;
		}

		/* Emulate RC VOL_UP/VOL_DOWN as encoder actions */
		if (cmd == CMD_RC_VOL_UP)
			encCnt++;
		if (cmd == CMD_RC_VOL_DOWN)
			encCnt--;

		/* Handle encoder */
		if (encCnt) {
			switch (dispMode) {
			case MODE_STANDBY:
			case MODE_LEARN:
				break;
			case MODE_TIME_EDIT:
				displayTime = TIMEOUT_TIME_EDIT;
				rtcChangeTime(encCnt);
				break;
			case MODE_BRIGHTNESS:
				changeBrWork(encCnt);
				displayTime = TIMEOUT_BR;
				break;
			case MODE_MUTE:
			case MODE_LOUDNESS:
			case MODE_TIME:
				dispMode = MODE_SND_VOLUME;
			default:
				sndSetMute(0);
				sndChangeParam(dispMode, encCnt);
				displayTime = TIMEOUT_AUDIO;
				break;
			}
		}

		/* Exid to default mode if timer expired */
		if (displayTime == 0) {
			if (dispMode == MODE_LEARN || dispMode == MODE_STANDBY) {
				dispMode = MODE_STANDBY;
			} else {
				rtc.etm = RTC_NOEDIT;
				if (aproc.mute)
					dispMode = MODE_MUTE;
				else
					dispMode = MODE_TIME;
			}
		}

		/* Show things */
		switch (dispMode) {
		case MODE_STANDBY:
			showStby();
			break;
		case MODE_MUTE:
			showMute();
			break;
		case MODE_LOUDNESS:
			showLoudness();
			break;
		case MODE_LEARN:
			showLearn();
			break;
		case MODE_TIME:
		case MODE_TIME_EDIT:
			showTime();
			break;
		case MODE_BRIGHTNESS:
			showBrWork();
			break;
		default:
			showSndParam(dispMode, ICON_NATIVE);
			break;
		}

		if (dispMode == dispPrev)
			updateScreen(EFFECT_NONE, dispMode);
		else
			updateScreen(EFFECT_SPLASH, dispMode);

		dispPrev = dispMode;
	}

	return 0;
}
Example #16
0
void Discharger::initialize()
{
    setValue(0);
    powerOff(DISCHARGING_COMPLETE);
}
Example #17
0
int main(void)
{
	//some setup code
	storePin(1337); //only once needed
	initPincode();
	//initizialize power controle pins
	initPowerControle();
	//initizialize rotary.
	initRotary();
	//initialize shifter.
	initShifter();
	//initialize display code.
	initDisplay();
	//initialize serial comm
	init_uart();
	//initialize the servo code.
	initServo();
	//initialize time code
	initTime();
	//main loop.
	DDRB  |= (1<<PB4)|(1<<PB5);
	PORTB |= (1<<PB5)|(1<<PB4);
	while(1)
	{
		//get the input from user for pincode
		getInputPinCode();
		//if there is new data we check to see the commands.
		if(serial_available)
		{
			serial_available = 0;
			runSerialInputCommands(inputStr);
		}
		//check the servo state, disable it when it's active
		//for longer then a second.7
		if(isServoActive) //check to see if the state of the servo is active.
		{
			if(time-previousServo > timeScale)//see if a second has passed
			{
				if(finalServoPos != getCurrentServoState())
				{
					setServoPos(finalServoPos);
				}
				else
				{
					disableServo();
				}
			}
		}
		
		//send number if logged in and ticks changed and rotary has turned.
		//to prevent spam
		if(rotary_has_turned && ticks != previous_ticks && isLoggedIn)
		{
			previous_ticks = ticks;
			rotary_has_turned = 0;
			sendNumber(pin);
		}
		
		if(timeinSeconds >= 360)
		{
			powerOff();
		}
		else
		{
			powerOn();
		}
		
		//if pin is correctly set set green led, else red on.
		if(pin == actual_pin)
		{
			open();
			PORTB |= (1<<PB5);
			PORTB &= ~(1<<PB4);
		}
		else
		{
			if(!timeinSeconds%2)
				close();
			PORTB |= (1<<PB4);
			PORTB &= ~(1<<PB5);
		}
	}
	
	return 1;
}
Example #18
0
Balancer::Balancer()
{
    powerOff();
}
Example #19
0
 void strategyPowerOff() {
     void (*powerOff)() = pgm::read(&strategy_->powerOff);
     powerOff();
 }
Example #20
0
void MainWindow::initializeQMLComponent()
{
    QDeclarativeContext *context = m_view->rootContext();

#if defined(Q_WS_MAEMO_5) || defined(QT_NO_OPENGL)
    // Set UI to low performance mode for Maemo5 and Symbian^1. This mainly
    // disables antialiasing on some performance costly elements.
    context->setContextProperty("lowPerf", true);
#else
    context->setContextProperty("lowPerf", false);
#endif

#ifdef Q_OS_SYMBIAN
    context->setContextProperty("sampleFolder", "file:");
#else
    context->setContextProperty("sampleFolder", QString("file:/") +
                                QDir::currentPath());
#endif

#ifdef Q_WS_MAEMO_6
    // Hide the exit button in Harmattan
    context->setContextProperty("exitButtonVisible", false);
#else
    context->setContextProperty("exitButtonVisible", true);
#endif

    m_view->setSource(QUrl("qrc:/qml/Main.qml"));

    // Create Qt settings object to load / store app settings
    m_settings = new QSettings("Nokia", "DJTurntable");

    // Create Qt objects to handle Turntable and Drum machine
    m_turntable = new Turntable(m_settings, this);
    m_drumMachine = new DrumMachine(m_settings, this);
    m_turntable->addAudioSource(m_drumMachine);

    // Find out the interesting Qt objects of the QML elements
    QObject *turntableQML = dynamic_cast<QObject*>(m_view->rootObject());
    QObject *sampleSelectorQML =
            m_view->rootObject()->findChild<QObject*>("sampleSelector");
    QObject *drumMachineQML =
            m_view->rootObject()->findChild<QObject*>("drumMachine");

    // If there are errors in QML code and the elements does not exist,
    // they won't be found Qt side either, check existance of the elements.
    if (!turntableQML || !sampleSelectorQML || !drumMachineQML) {
        QMessageBox::warning(NULL, "Warning",
                             "Failed to resolve QML elements in main.cpp");
        return;
    }

    // Turntable connections
    connect(turntableQML, SIGNAL(start()),
            m_turntable, SLOT(start()));
    connect(turntableQML, SIGNAL(stop()),
            m_turntable, SLOT(stop()));
    connect(turntableQML, SIGNAL(diskAimSpeed(QVariant)),
            m_turntable, SLOT(setDiscAimSpeed(QVariant)));
    connect(turntableQML, SIGNAL(diskSpeed(QVariant)),
            m_turntable, SLOT(setDiscSpeed(QVariant)));
    connect(turntableQML, SIGNAL(cutOff(QVariant)),
            m_turntable, SLOT(setCutOff(QVariant)));
    connect(turntableQML, SIGNAL(resonance(QVariant)),
            m_turntable, SLOT(setResonance(QVariant)));
    connect(turntableQML, SIGNAL(seekToPosition(QVariant)),
            m_turntable, SLOT(seekToPosition(QVariant)));
    connect(m_turntable, SIGNAL(audioPosition(QVariant)),
            turntableQML, SLOT(audioPosition(QVariant)));
    connect(m_turntable, SIGNAL(powerOff()),
            turntableQML, SLOT(powerOff()));

    // SampleSelector connections
    connect(sampleSelectorQML, SIGNAL(sampleSelected(QVariant)),
            m_turntable, SLOT(setSample(QVariant)));
    connect(sampleSelectorQML, SIGNAL(defaultSample()),
            m_turntable, SLOT(openDefaultSample()));
    connect(m_turntable, SIGNAL(sampleOpened(QVariant)),
            sampleSelectorQML, SLOT(setCurrentSample(QVariant)));
    connect(m_turntable, SIGNAL(error(QVariant, QVariant)),
            sampleSelectorQML, SLOT(showError(QVariant, QVariant)));

    // DrumMachine connections
    connect(drumMachineQML, SIGNAL(startBeat()),
            m_drumMachine, SLOT(startBeat()));
    connect(drumMachineQML, SIGNAL(stopBeat()),
            m_drumMachine, SLOT(stopBeat()));
    connect(drumMachineQML, SIGNAL(setBeat(QVariant)),
            m_drumMachine, SLOT(setBeat(QVariant)));
    connect(drumMachineQML,
            SIGNAL(drumButtonToggled(QVariant, QVariant, QVariant)),
            m_drumMachine,
            SLOT(drumButtonToggled(QVariant, QVariant, QVariant)));
    connect(drumMachineQML, SIGNAL(drumMachineSpeed(QVariant)),
            m_drumMachine, SLOT(setBeatSpeed(QVariant)));
    connect(m_drumMachine,
            SIGNAL(drumButtonState(QVariant, QVariant, QVariant)),
            drumMachineQML,
            SLOT(setDrumButton(QVariant, QVariant, QVariant)));
    connect(m_drumMachine, SIGNAL(tickChanged(QVariant)),
            drumMachineQML, SLOT(highlightTick(QVariant)));

    // Framework connections
    connect((QObject*)m_view->engine(), SIGNAL(quit()), qApp, SLOT(quit()));

#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
#ifndef QT_NO_OPENGL
    // Create Qt accelerometer objects
    m_accelerometer = new QAccelerometer(this);
    m_accelerometerFilter = new AccelerometerFilter;
    // Does not take the ownership of the filter
    m_accelerometer->addFilter(m_accelerometerFilter);

    m_accelerometer->setDataRate(50);

    // Create Qt objects for accessing profile information
    m_deviceInfo = new QSystemDeviceInfo(this);
    m_turntable->profile(m_deviceInfo->currentProfile());

    connect(m_accelerometerFilter, SIGNAL(rotationChanged(QVariant)),
            turntableQML, SLOT(inclination(QVariant)));
    connect(m_deviceInfo,
            SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)),
            m_turntable,
            SLOT(profile(QSystemDeviceInfo::Profile)));

    // Begin the measuring of the accelerometer sensor
    m_accelerometer->start();
#endif
#endif

    m_turntable->openLastSample();
    m_drumMachine->setBeat(0);
}
// =======================
// Main program begins
// =========================
task main()
{
	disableDiagnosticsDisplay();

	alive();
	StartTask(selector);
	StartTask(gyro);
	StartTask(sonar_sensor);
	initializeRobot();

	waitForStart();

	constHeading = 0;
	relHeading = 0;

	if(calibrate != 2)    // then the GYRO hasn't been calibrated yet
	{
		gyroCalTime = 3;    // set the default 3 second time value to be used
		calibrate = 1;      // and get the calibration underway
		while(calibrate != 2)  // wait here until the calibration is complete
		{
			EndTimeSlice();
		}
	}
	relHeading = 0;       // force our GYRO heading values both to zero
	constHeading = 0;

	// CompassStartValue = CompassValue;
	// CompassAlive = false;

	PlaySound(soundFastUpwardTones);  // warn everyone we're about to move
	wait1Msec(time_selector*1000);    // apply user selected delay time
	PlaySound(soundBeepBeep);         // this time we're really about to go
	eraseDisplay();

	switch(MissionNumber)
	{
	case 1:
		GyroTime_moveV2(32000,60,true,true,false);
		break;
	case 2:
		GyroTime_moveV2(4000,55,true,true,false);
		break;
	case 3:
		GyroTime45_V2(2000,55,true,true,false,true);
		Gyro_TurnV2(90,50,false);
		break;

	case 4:
		Gyro_TurnV2(90,-50,false);
		wait1Msec(200);
		Gyro_TurnV2(90,50,false);
		wait1Msec(200);
		Gyro_TurnV2(90,-50,false);
		wait1Msec(200);
		Gyro_TurnV2(90,50,false);
		wait1Msec(200);
		Gyro_TurnV2(90,-50,false);
		wait1Msec(200);
		Gyro_TurnV2(90,50,false);
		wait1Msec(200);
		Gyro_TurnV2(90,-50,false);
		wait1Msec(200);
		break;

	case 5:

		GyroTime_moveV2(1500,30,true,true,false);
		Gyro_TurnV2(45,20,false);
		GyroTime_moveV2(1500,30,true,true,false);
		break;

	case 6:

		GyroTime45_V2(2500,55,true,true,false,true);
		Gyro3MT_V2 (/*degrees*/600, /*power*/50, false,/*left or right motor moving*/MOVERIGHT);

		break;

	case 7:

		GyroTime_moveV2(20000,30,true,true,false);

		break;

	case 8:

		while(true)
		{
			nxtDisplayBigTextLine(2, "S: %2d", SensorValue[SONAR]);
		}

		break;

	case 9:

		GyroSonar_moveV2(20000, SIDE, 50, 0, 60,true, true, false);

		break;

		case 10:
		//						time	sensors	 DFW_X DFW_Y speed
		GyroSonar_moveV2(0, SIDE_BACK, sonarLive, 130, 60,true, true, false);
		Gyro_TurnV2(-45,20,false);
		GyroTime_moveV2(1000,30,true,true,false);

		break;

		case 11:

		GyroSonar_moveV2(0, BACK, 0, 100, 60,true, true, false);

		break;
	}

	PlaySound(soundBeepBeep);
	wait1Msec(30000);
	StopAllTasks();
	powerOff();
}
Example #22
0
void CEC_TV::OnReceive(int source, int dest, unsigned char* buffer, int count){
    //#ifdef DEBUG_CODES
        debugReceivedMsg(source, dest, buffer, count);
    //#endif //#DEBUG_CODES

    if (count /*&& (dest == _logicalAddress || dest == CECDEVICE_BROADCAST)*/){
        switch(buffer[0]){
            case CEC_OPCODE_IMAGE_VIEW_ON:
            case CEC_OPCODE_TEXT_VIEW_ON:
                powerOn();
                break;
            case CEC_OPCODE_STANDBY:
                powerOff();
                break;
            case CEC_OPCODE_GET_CEC_VERSION:
                TransmitMsg(source, 2, CEC_OPCODE_CEC_VERSION, 0x04);//hdmi 1.3a
            case CEC_OPCODE_CEC_VERSION:
                devices[source].cec_ver = (cec_version)buffer[1];
                break;
            case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
                TransmitMsg(source, 4, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS, 0, 0, CDT_TV);
                break;
            case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
                TransmitMsg(source, 2, CEC_OPCODE_REPORT_POWER_STATUS, _powerStatus);
                break;
            case CEC_OPCODE_ACTIVE_SOURCE:
                /*if (_powerStatus == CEC_POWER_STATUS_ON)
                {
                    _activeSrcBroadcast = 0;
                    DbgPrint("changing to input %d\r\n", buffer[1]>>4 & 0xf);
                    //changeKoganInput(&irsend, buffer[1]>>4 & 0xf);
                    //irrecv.enableIRIn(); // Re-enable receiver
                    changeInputI2c(buffer[1]>>4 & 0xf);

                }*/
                active_src1 = buffer[1];
                active_src2 = buffer[2];
                DbgPrint("Got active src of %02X.%02X\n", active_src1, active_src2);
                DbgPrint("Asking for OSD: %d\n", TransmitMsg(source, 1,CEC_OPCODE_GIVE_OSD_NAME));
                DbgPrint("Asking for audio mode: %d\n", RequestAudio(byte_combine_2(active_src1, active_src2)));
                TransmitMsg(source, 2, CEC_OPCODE_MENU_REQUEST, CEC_MENU_REQUEST_TYPE_QUERY);
                break;
            case CEC_OPCODE_ROUTING_INFORMATION:
                active_src1 = buffer[1];
                active_src2 = buffer[2];
                RequestAudio(byte_combine_2(active_src1, active_src2));
                break;
            case CEC_OPCODE_ROUTING_CHANGE:
                active_src1 = buffer[3];
                active_src2 = buffer[4];
                RequestAudio(byte_combine_2(active_src1, active_src2));
                break;
            case CEC_OPCODE_INACTIVE_SOURCE:
                /*if (_powerStatus == CEC_POWER_STATUS_ON)
                    broadcastForActiveSource(true);//this probably shows up with nothing as other sources assume they're not active, but we check to be sure.
                    DbgPrint("TODO 139, cectv\r\n");*/
                break;
            case CEC_OPCODE_MENU_STATUS:
                if (buffer[1] == CEC_MENU_STATE_ACTIVATED)
                    _sendUCTo = source;
                else
                    _sendUCTo = 0;
                break;
            case CEC_OPCODE_REPORT_POWER_STATUS:
                #ifdef DEBUG_CODES
                    DbgPrint("device at logical %d is ", source);
                    switch (buffer[1]){
                        case CEC_POWER_STATUS_ON:
                            Serial.print("On");
                            break;
                        case CEC_POWER_STATUS_STANDBY:
                            Serial.print("on Standby");
                            break;
                        case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
                            Serial.print("Turning On");
                            break;
                        case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
                            Serial.print("Turning Off");
                            break;
                        default:
                            DbgPrint("UNKNOWN STATUS (%d)", buffer[1]);
                            break;
                    }
                    Serial.print("\r\n");
                #endif
                devices[source].power_status = (cec_power_status)buffer[1];
                break;
            case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
                DbgPrint("Device at logical %X is at %02X%02X device type %02X\r\n", source, buffer[1],buffer[2], buffer[3]);
                devices[source].phy_addr = byte_combine_2(buffer[1], buffer[2]);
                break;
            case CEC_OPCODE_SET_OSD_NAME:
                {
                    short osdLen = count -1;
                    if (osdLen){
                        char* osdName = new char[osdLen];
                        memcpy(osdName, buffer+1, osdLen);
                        osdName[osdLen] = 0;
                        #ifdef DEBUG_CODES
                        DbgPrint("Device at logical %X is known as \"%s\"\r\n", source, osdName);
                        #endif
                        if (devices[source].osd_name)
                            delete devices[source].osd_name;
                        devices[source].osd_name = osdName;
                    }
                    break;
                }
            case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE://this tells us that the receiver is on/off
                subSwitch.send(buffer[1] ? SWITCH_CODE_0_ON : SWITCH_CODE_0_OFF, 24);
                DbgPrint("AUdio mode set: %x\r\n", buffer[1]);
                break;
            case CEC_OPCODE_DEVICE_VENDOR_ID:
                {
                    cec_vendor_id vendorid = (cec_vendor_id) byte_combine_3(buffer[1], buffer[2], buffer[3]);
                    DbgPrint("Device at logical %X is a %s (%06lX)\n", source, vendor_tostring(vendorid), vendorid);
                    devices[source].vendor_id = vendorid;
                    break;
                }
            //no response messages:
            case  CEC_OPCODE_FEATURE_ABORT:
            case  CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS://receiver giving volume status
                break;
            default:
                if (dest != CECDEVICE_BROADCAST){//dont wanna do for bcast
                    Serial.print("ABORT!\r\n");
                    TransmitMsg(source, 2,  CEC_OPCODE_FEATURE_ABORT, CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
                }
                break;
        }
    }
}
	/**
	 * Deconstructor of StepperMotor. Tries to turn to power off.
	 **/
	StepperMotor::~StepperMotor(void){
		try{
			powerOff();
		} catch(std::runtime_error& err){}
	}
Example #24
0
void ManufactureTestButtonPress(void)
{
	startTimeout(&biosUnused, BIOS_UNUSED_MS);
	while(1)
	{
		uint8_t red = LED_OFF;
		uint8_t green = LED_OFF;
		uint8_t blue = LED_OFF;		
		
		WatchdogPet();
		
		if (buttonActivated(B_START) & buttonActivated(B_SELECT))
		{
			delay_ms(500);
			reset_do_soft_reset();
		}
		
		if(checkTimeout(&biosUnused))
		{
			cancelTimeout(&biosUnused);
			setLEDValue(0, 0, 0);
			powerOff(global_header.powerOffSoftware);
		}

		if( buttonActivated(B_UP) ||
			buttonActivated(B_DOWN) ||
			buttonActivated(B_LEFT) ||
			buttonActivated(B_RIGHT) ||
			buttonActivated(B_A) ||
			buttonActivated(B_B) ||
			buttonActivated(B_X) ||
			buttonActivated(B_Y) ||
			buttonActivated(B_START) ||
			buttonActivated(B_SELECT) ||
			buttonActivated(B_LB) ||
			buttonActivated(B_RB) ||
			buttonActivated(B_LT) ||
			buttonActivated(B_RT) ||
			buttonActivated(B_JL) ||
			buttonActivated(B_JR)
		)
		{
			green = LED_DIM;
		}
		
		for(uint8_t idx = 0 ; idx<NUM_JOYSTICKS; idx++) 
		{
			uint16_xy raw;
			raw.x = sampleAnalogChannel(joysticks[idx].adc_channel_x);
			raw.y = sampleAnalogChannel(joysticks[idx].adc_channel_y);
			
			int16_xy out;
			SimpleJoystickAdj( center[idx], &deadzone, &raw, &out );
			
			//Write raw and adjusted X,Y values to USB serial port
			PrintXY(raw.x,raw.y);
			sendUSBString("->", false);
			PrintXY(out.x,out.y);
			sendUSBLine("");
			
			if( out.y<0 )
			{
				//up is yellow
				red = LED_DIM;
				green = LED_DIM;
			}
			else if( out.y>0 )
			{
				//down is blue
				blue = LED_DIM;
			}
			else if( out.x>0 )
			{
				//right is Red
				red = LED_DIM;
			}
			else if( out.x<0 )
			{
				//left is green
				green = LED_DIM;
			}
		}
		
		setLEDValue(red, green, blue);
				
	} // end while(1)
}