int MainIdleProc(void) { // should not let POS go into sleep mode when running simulator int iRet; if (POWER_BATTERY == OsCheckPowerSupply()) { if (glSysParam.stEdcInfo.ucIdleShutdown) { PowerOff(); } else { // Modified by Kim_LinHB 2014-7-8 Gui_ClearScr(); Gui_ShowMsgBox(_T("POWER SAVING"), gl_stTitleAttr, NULL, _T("PRESS ANY KEY\nTO RECOVER"), gl_stCenterAttr, GUI_BUTTON_NONE, 0, NULL); do { iRet = SysSleep("00"); } while((iRet==-3) && (kbhit()!=0)); // 很奇怪的现象:除非在上次SysSleep返回之后调用DelayMs(3000),否则即使间隔1分钟,调用SysSleep仍会直接返回-3。 // 因此我在这里加了判断,如果返回-3而且没有按键则继续重复SysSleep // 在外部已经保证了进入MainIdleProc的间隔>=1分钟 // it needs to delay 3 seconds after return from SysSleep, otherwise SysSleep will return -3 even the period of calling SysSleep is over 1 min, // so here is a special processing, if return -3 from SysSleep and no key was pressed then continue calling SysSleep. DelayMs(100); kbflush(); Gui_ClearScr(); // Added by Kim_LinHB 2014-08-13 v1.01.0003 } return 0; } return -1; }
void board::usbVcomHwConfigInit() { if (!bInitialized) { bInitialized = true; Set_USBClock(); Set_USBPullUp(); PowerOff(); for (unsigned int i = 500000; i--;) { continue; } Set_USBInterrupt(false); // Wait a bit to let the Host disconnect the device for (unsigned int i = 500000; i--;) { continue; } // USB_Cable_Config(ENABLE); // for (unsigned int i = 500000; i--;) { continue; } Set_USBInterrupt(true); USB_Init(); for (unsigned int i = 500000; i--;) { continue; } for (unsigned int i = 500000; i--;) { continue; } } }
// Function to complusively shut down the system with a given mode. static void QuitHard(hal::ShutdownMode aMode) { switch (aMode) { case hal::eHalShutdownMode_PowerOff: PowerOff(); break; case hal::eHalShutdownMode_Reboot: Reboot(); break; case hal::eHalShutdownMode_Restart: // Don't let signal handlers affect forced shutdown. kill(0, SIGKILL); // If we can't SIGKILL our process group, something is badly // wrong. Trying to deliver a catch-able signal to ourselves can // invoke signal handlers and might cause problems. So try // _exit() and hope we go away. _exit(1); break; default: MOZ_NOT_REACHED(); break; } MOZ_NOT_REACHED(); }
void main(int argc, char** argv, int entrypoint) { (void) argc; (void) argv; PXI_Reset(); I2C_init(); // Wait for ARM11 PXI_WaitRemote(PXI_READY); PXI_DoCMD(PXI_SCREENINIT, NULL, 0); I2C_writeReg(I2C_DEV_MCU, 0x22, 0x2A); #ifdef SCRIPT_RUNNER // Run the script runner if (ScriptRunner(entrypoint) == GODMODE_EXIT_REBOOT) #else // Run the main program if (GodMode(entrypoint) == GODMODE_EXIT_REBOOT) #endif Reboot(); PowerOff(); }
/******************************************************************************* * Function Name : Mass_Storage_Start * Description : Starts the mass storage demo. * Input : None * Output : None * Return : None *******************************************************************************/ void Mass_Storage_Start (void) { /* Disble the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); /* Clear the LCD screen */ LCD_Clear(White); LCD_SetDisplayWindow(160, 223, 128, 128); LCD_DrawBMP(0x00647C00); /* Disable LCD Window mode */ LCD_WindowModeDisable(); /* Set the Back Color */ LCD_SetBackColor(Blue); /* Set the Text Color */ LCD_SetTextColor(White); if(MSD_Init() != 0x00) { LCD_DisplayStringLine(Line8, " No MSD Card Present"); LCD_DisplayStringLine(Line9, " To exit Press SEL "); /* Loop until SEL key pressed */ while(ReadKey() != SEL) { } } else { Get_Medium_Characteristics(); /* Display the " Plug the USB " message */ LCD_DisplayStringLine(Line8, " Plug the USB Cable "); LCD_DisplayStringLine(Line9, "Exit: Push JoyStick"); /* Intialize the USB cell */ USB_Init(); LCD_ClearLine(Line9); /* Display the "To stop Press SEL" message */ LCD_DisplayStringLine(Line8, " To stop Press SEL "); /* Loop until SEL key pressed */ while(ReadKey() != SEL) { } PowerOff(); } LCD_Clear(White); DisplayMenu(); IntExtOnOffConfig(ENABLE); /* Flush SPI1 Data Register */ SPI_I2S_ReceiveData(SPI1); }
static void MainMenuAppOnCommand(App * app, AppCommand const cmd) { switch (cmd.cmd) { case APP_CMD_POWER_OFF: PowerOff(); break; default: assert(false); } }
void ColourEngine::SetPower(power_t power, uint fade) { if (current_power != power) { if (power == ON) { PowerOn(fade); } else { PowerOff(fade); } current_power = power; } }
int main() { ClearScreenFull(true, true); InitFS(); u32 menu_exit = ProcessMenu(menu, SUBMENU_START); DeinitFS(); (menu_exit == MENU_EXIT_REBOOT) ? Reboot() : PowerOff(); return 0; }
int main() { u32 menu_exit = MENU_EXIT_REBOOT; if (InitializeD9() <= 1) { menu_exit = ProcessMenu(menu, SUBMENU_START); } DeinitFS(); (menu_exit == MENU_EXIT_REBOOT) ? Reboot() : PowerOff(); return 0; }
int PowerCommand(int argc, char const ** argv) { if (argc != 2) return -1; char const * subcommand = argv[1]; if (strcmp("off", subcommand) == 0) { PowerOff(); return 0; } else if (strcmp("good", subcommand) == 0) { printf("%s\r\n", PowerIsGood() ? "GOOD" : "BAD"); return 0; } else { return -2; } }
void USB_Reset(void) { #if defined(Bootloader) && !defined(PullDown) && !defined(Maple) /* disable USB */ PowerOff(); /* USB reset by pulling USBDP shortly low. A pullup resistor is needed, most * boards have it. */ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_WriteBit(GPIOA, GPIO_Pin_12, Bit_RESET); delay_ms(15); #endif }
void System::DoEMCON(int index) { int e = GetEMCONPower(index); if (power_level * 100 > e || emcon != index) { if (e == 0) { PowerOff(); } else { if (emcon != index) PowerOn(); SetPowerLevel(e); } } emcon = index; }
void Hardware_::Init() { BOARD_INIT(); // Resetting because of a brownout power goes down. // Stay down buddy if (MCUSR == 4) PowerOff(); // now in bootloader Backlight_Init(); Timer_Init(); Accelerometer_Init(); ADC_Init(); USBInit(); Touch_Init(); sei(); // Attach stdout to usb serial StdOutInit(); }
// Called from userspace to do something, like set the LEDs IOReturn WirelessHIDDevice::setReport(IOMemoryDescriptor *report, IOHIDReportType reportType, IOOptionBits options) { char data[2]; if (report->readBytes(0, data, 2) < 2) return kIOReturnUnsupported; switch (data[0]) { case 0x01: // LED if ((data[1] != report->getLength()) || (data[1] != 0x03)) return kIOReturnUnsupported; report->readBytes(2, data, 1); SetLEDs(data[0]); return kIOReturnSuccess; case 0x02: // Power PowerOff(); return kIOReturnSuccess; default: return super::setReport(report, reportType, options); } }
void PowerOff() { AssertMainThread(); PROXY_IF_SANDBOXED(PowerOff()); }
/******************************************************************************* * Function Name : Mass_Storage_Start * Description : Starts the mass storage demo. * Input : None * Output : None * Return : None *******************************************************************************/ void Mass_Storage_Start (void) { NVIC_InitTypeDef NVIC_InitStructure; /* Disble the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); while(ReadKey() != NOKEY) { } RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD screen */ LCD_Clear(White); LCD_SetDisplayWindow(160, 223, 128, 128); LCD_NORDisplay(USB_ICON); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Disable LCD Window mode */ LCD_WindowModeDisable(); /* Set the Back Color */ LCD_SetBackColor(Blue); /* Set the Text Color */ LCD_SetTextColor(White); /* Display the " Plug the USB " message */ LCD_DisplayStringLine(Line8, " Plug the USB Cable "); LCD_DisplayStringLine(Line9, "Exit: Push JoyStick"); /* Enable and GPIOD clock */ USB_Disconnect_Config(); /* MAL configuration */ MAL_Config(); Set_USBClock(); NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USB_Init(); while (bDeviceState != CONFIGURED) { if(ReadKey() != NOKEY) { PowerOff(); LCD_Clear(White); DisplayMenu(); IntExtOnOffConfig(ENABLE); return; } } LCD_ClearLine(Line9); /* Display the "To stop Press SEL" message */ LCD_DisplayStringLine(Line8, " To stop Press SEL "); /* Loop until SEL key pressed */ while(ReadKey() != SEL) { } PowerOff(); LCD_Clear(White); DisplayMenu(); IntExtOnOffConfig(ENABLE); }
void Board_main(void) { uint8_t i; uint16_t flash_flag = 0; uint16_t copy_file_flag = 0; /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { #if 0 /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); #else FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Enable); /* Flash 2 wait state */ /*FLASH_SetLatency(FLASH_Latency_2);*/ FLASH_SetLatency(FLASH_Latency_0); /*abin@ */ #endif /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); #if 0 /* PLLCLK = 8MHz * 9 = 72 MHz */ /*abin:note*/ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_8); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } #else RCC_PLLCmd(DISABLE); /* Select HSE as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x04) { } #endif } /* Enable GPIOA, GPIOB, and AFIO clocks */ RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO, ENABLE); /* Enable DMA1 ,DMA2 clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1|RCC_AHBPeriph_DMA2, ENABLE); /* Enable ADC1 ADC2,and GPIOC clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 |RCC_APB2Periph_ADC2| RCC_APB2Periph_GPIOC, ENABLE); /* Enable PWR and BKP clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Enable write access to Backup domain */ PWR_BackupAccessCmd(ENABLE); /* Clear Tamper pin Event(TE) pending flag */ BKP_ClearFlag(); #if ABIN_DEBUG USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Output a message on Hyperterminal using printf function */ //sys_printf("\n\r abin 8M is ok moify flash latency :USART Init end \n\r"); #endif /*------------------- Resources Initialization -----------------------------*/ /* GPIO Configuration */ GPIO_Config(); //sys_printf("\n\r abin mul2 :GPIO_Config \n\r"); #if ABIN_CPU_UPGRADE2HIGHSPEED_OPTION USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); if(USB_Plugin_State == 1) { //sys_printf("\n\r abin switch to high speed !!\n\r"); UpgradeToHighSpeed(); } #endif /* Interrupt Configuration */ InterruptConfig(); /* Configure the systick */ SysTick_Configuration(); /*------------------- Drivers Initialization -------------------------------*/ /* Initialize the Low Power application */ LowPower_Init(); /* Enable WKUP pin */ PWR_WakeUpPinCmd(ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); RTC_Init(); /* If HSE is not detected at program startup */ if(HSEStartUpStatus == ERROR) { /* Generate NMI exception */ SCB->ICSR |= SCB_ICSR_NMIPENDSET; } USB_Disconnect_Config(); GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);/*???abin@20100714*/ WakupPin_Init(); //sys_printf("\n\r abin before CheckPowerOnReason\n\r"); CheckPowerOnReason(); //sys_printf("\n\r abin after CheckPowerOnReason\n\r"); Board_ADC_Init(); /*init the flag*/ flash_flag = *(uint16_t *)FLASH_READY_ADDRESS; if( flash_flag != FLAG_FLASH_READY) { //sys_printf("\n\r abin ready to erase flash \n\r"); FLASH_Unlock(); FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); //Erase the 32 page 32K for(i = 0;i< DATA_PAGES;i++) { //sys_printf("\n\r abin ready to erase aa"); FLASH_ErasePage(DATA_LOGGER_ADDRESS_START + i * 1024);/*数据在Page1...page32存放*/ } FLASH_ErasePage(FLASH_READY_ADDRESS); /*abin@20100715 没添加保护*/ FLASH_ProgramHalfWord(FLASH_READY_ADDRESS , FLAG_FLASH_READY); FLASH_ErasePage(REOCRD_COUNT_ADDRESS); FLASH_ProgramHalfWord(REOCRD_COUNT_ADDRESS , 0x0000); FLASH_Lock(); //sys_printf("\n\r abin mul2 :erase flash end!!!\n\r"); } //sys_printf("\n\r abin ready to erase flash end \n\r"); USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); if(USB_Plugin_State == 0) { record_count = *(uint16_t *)REOCRD_COUNT_ADDRESS; if(record_count >= 15428) { //Write the full flag //Do nothing.... while(1) { //sys_printf("\n\r sample end !!!!!!!!!!!!!!!!!!!!!\n\r"); Led_One_By_One(4); /*应该进入standy 模式 abin@20100715*/ } } else { //sys_printf("\n\r abin ready to add sample count \n\r"); FLASH_Unlock(); FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); FLASH_ProgramHalfWord(DATA_LOGGER_ADDRESS_START + record_count * 2, GetTemperature()); //Erase first FLASH_ErasePage(REOCRD_COUNT_ADDRESS); //Update the count record_count = record_count + 1; FLASH_ProgramHalfWord(REOCRD_COUNT_ADDRESS , record_count); FLASH_Lock(); //sys_printf("\n\r abin add sample count :end\n\r"); } //sys_printf("\n\r %000\n\r"); GPIO_SetBits(GPIOA, GPIO_Pin_1); #if 0 Delay(25); #else Delay(5); #endif //sys_printf("\n\r %111\n\r"); } else { Enable_SDcard(); /* if there is usb connect, copy the data to sdcard. and start the mass storage */ copy_file_flag = *(uint16_t *)COPY_FILE_ADDRESS; if(copy_file_flag == FLAG_FILE_COPYED) { Write_Copy_File_Flag(FLAG_FILE_NO_COPYED); USB_Disconnect_Config(); GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN); Delay(10); GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN); /* Enable and GPIOD clock */ Mass_Storage_Start (); while( bDeviceState != CONFIGURED) { Led_Both(1); } USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); while( USB_Plugin_State == 1)/* U-DISK success ,then CPU Loop in here*/ { USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14); Led_One_By_One(1); //sys_printf("\n\r abin :mul2 u disk !!!\n\r"); } PowerOff(); Write_Copy_File_Flag(FLAG_FILE_NO_COPYED); } else { Write_Copy_File_Flag(FLAG_FILE_COPYED); Led_Green_Flink(3); NAND_FAT(); CreateDataLoggerFile(); Write_Copy_File_Flag(FLAG_FILE_COPYED); //sys_printf("\n\r abin :mul2 NAND_FAT!!!\n\r"); } //sys_printf("\n\r abin :mul2 Disable_SDcard!!!\n\r"); Disable_SDcard(); BKP_WriteBackupRegister(BKP_POWER_ON, FLAG_POWER_OFF); PWR_EnterSTANDBYMode(); /* Generate a system reset */ //NVIC_SystemReset(); } //sys_printf("\n\r @111 \n\r"); /* Set the RTC Alarm after 60s */ RTC_SetAlarm(RTC_GetCounter()+ 3); //sys_printf("\n\r @222:RTC_GetCounter()=0x%x \n\r",RTC_GetCounter()); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); //sys_printf("\n\r @333\n\r"); PWR_EnterSTANDBYMode(); }
BOOL Irman::Open( ) { if (ready()) return TRUE; if (!m_sComPort.GetLength()) { return false; } const TCHAR * error = _T( "Error opening device" ); CSerialMFC::EPort e = CSerialMFC::CheckPort(m_sComPort); if (e != CSerialMFC::EPortAvailable) { CString msg; msg << m_sComPort << " " << m_serial.EPortError(e); MBMessageBox("serial i/o error", msg); return false; } LONG o = m_serial.Open(m_sComPort, m_wndMsgHndlr, m_wmsg); if (o != ERROR_SUCCESS) { CString msg; msg << "unable to open " << m_sComPort << " error [" << o << "] " << MBFormatError(o); MBMessageBox("serial i/o error", msg); return false; } o = m_serial.Setup(CSerial::EBaud9600,CSerial::EData8, CSerial::EParNone,CSerial::EStop1); if (o != ERROR_SUCCESS) { CString msg; msg << "unable to Setup " << m_sComPort << " error [" << o << "] " << MBFormatError(o); MBMessageBox("serial i/o error", msg); return false; } o = m_serial.SetupHandshaking(CSerial::EHandshakeOff); if (o != ERROR_SUCCESS) { CString msg; msg << "unable to Setup HandshakeOff " << m_sComPort << " error [" << o << "] " << MBFormatError(o); MBMessageBox("serial i/o error", msg); return false; } o = m_serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking); if (o != ERROR_SUCCESS) { CString msg; msg << "unable to Setup TimeoutNonblocking" << m_sComPort << " error [" << o << "] " << MBFormatError(o); MBMessageBox("serial i/o error", msg); return false; } if (PowerOff( ) == FALSE) return FALSE; Sleep( 200 ); if (PowerOn( ) == FALSE) return FALSE; Sleep( 100 ); // Time for the output to settle Flush( ); // Remove power up garbage m_serial.Write("I"); // These strings must be ASCII, not Unicode Sleep( 2 ); // Need to have >500us between the 'I' & the 'R' m_serial.Write("R"); m_OKreceived = 0; // Need to check that we receive "OK" back from Irman return RemoteReceiver::Open(); }
/** The state machine of the rotor control engine ... * * This is the transition diagram after the command kRotateCW has been issued: * * kRotateCW -> kIdle * | * | ==> PowerOn() * \/ * kReleaseBrake * | * kStop -> | -------- >>> -------+ * | ==> ReleaseBrake() | * | | * \/ | * kRotorRampup | * | | * kStop -> | -------- >>> -------|--+ * | ==> RotateCW() | | * | | | * \/ | | * kTurningCW | | * | | | * * <-------------------+ | * kStop -> | | * | ==> RotorOff() | * | | * \/ | * kLockBrake | * | | * * <----------------------+ * | * | ==> LockBrake() * | * \/ * kRotorRampdown * | * | ==> PowerOff() * | * \/ * kIdle * * It will be handled in a similar way for the command kRotateCCW. * * As the trasitions will take some time, it is not unlikely, that the kStop * event is issued before the state kTurningCW is reached. In that case the * rotor relays etc. must be switched off in a proper order. */ void RotatorExec(void) { switch ( gRotatorCommand ) { case kStop: SetBusy(1); switch ( gRotatorState ) { case kReleaseBrake: // ??? case kTurningCW: case kTurningCCW: RotatorOff(); gRotatorBusyCounter = 5; gRotatorState = kLockBrake; break; case kRotorRampup: // ??? case kLockBrake: BrakeLock(); gRotatorBusyCounter = 5; gRotatorState = kRotorRampdown; break; case kRotorRampdown: PowerOff(); gRotatorState = kIdle; gRotatorBusyCounter = 10; break; case kIdle: gRotatorCommand = kNone; SetBusy(0); break; } break; case kTurnCW: SetBusy(1); switch ( gRotatorState ) { case kIdle: PowerOn(); gRotatorState = kReleaseBrake; gRotatorBusyCounter = 10; break; case kReleaseBrake: BrakeRelease(); gRotatorState = kRotorRampup; gRotatorBusyCounter = 5; break; case kRotorRampup: gRotatorState = kTurningCW; RotatorCW(); gRotatorBusyCounter = 5; break; case kTurningCW: gRotatorState = kTurningCW; gRotatorCommand = kNone; break; } break; case kTurnCCW: SetBusy(1); switch ( gRotatorState ) { case kIdle: PowerOn(); gRotatorState = kReleaseBrake; gRotatorBusyCounter = 10; break; case kReleaseBrake: BrakeRelease(); gRotatorState = kRotorRampup; gRotatorBusyCounter = 5; break; case kRotorRampup: gRotatorState = kTurningCCW; RotatorCCW(); gRotatorBusyCounter = 5; break; case kTurningCCW: gRotatorState = kTurningCCW; gRotatorCommand = kNone; break; } break; case kFastStop: RotatorOff(); BrakeLock(); PowerOff(); // reset state machine and command variable gRotatorState = kIdle; gRotatorCommand = kNone; // both PRESET LEDs off LED_PORT &= ~(LED_LEFT | LED_RIGHT); SetBusy(0); // clear preset data gPresetHeading = gCurrentHeading; gPresetCounter = 0; gPresetCommand = kPresetNone; break; default: break; } }
//--------------------------------------------------------- //--------------------------------------------------------- void CNPC_Roller::StartTask( const Task_t *pTask ) { switch( pTask->iTask ) { case TASK_ROLLER_ON: PowerOn(); TaskComplete(); break; case TASK_ROLLER_OFF: PowerOff(); TaskComplete(); break; case TASK_ROLLER_WAIT_FOR_PHYSICS: // Stop rolling. m_flWaitFinished = gpGlobals->curtime; m_RollerController.m_vecAngular = vec3_origin; PowerOff(); break; case TASK_ROLLER_FIND_PATROL_NODE: m_pHintNode = CAI_Hint::FindHint( this, HINT_ROLLER_PATROL_POINT, 0, 1024 ); if(!m_pHintNode) { TaskFail("Couldn't find roller patrol node"); } else { TaskComplete(); } break; case TASK_ROLLER_UNSTICK: Unstick(); if( m_vecUnstickDirection == vec3_origin ) { TaskComplete(); } else { VPhysicsGetObject()->Wake(); PowerOn(); // Cut back on the fail count, but not all the way. // Only a successful opportunity move sets this to 0. m_iFail /= 2; m_flWaitFinished = gpGlobals->curtime + 2; } break; case TASK_WALK_PATH: case TASK_RUN_PATH: // Make sure the controller isn't turned off. m_iFail = 0; // Successfully starting to move. VPhysicsGetObject()->Wake(); PowerOn(); break; case TASK_ROLLER_ISSUE_CODE: m_iCodeProgress = 0; m_flWaitFinished = gpGlobals->curtime; break; default: BaseClass::StartTask( pTask ); break; } }
u32 ProcessEntry(MenuEntry* entry) { bool emunand = entry->param & N_EMUNAND; bool nand_force = entry->param & N_FORCENAND; bool warning = entry->param & N_NANDWRITE; u32 pad_state; u32 res = 0; // unlock sequence for dangerous features /*if (warning) { u32 unlockSequenceEmu[] = { BUTTON_LEFT, BUTTON_RIGHT, BUTTON_DOWN, BUTTON_UP, BUTTON_A }; u32 unlockSequenceSys[] = { BUTTON_LEFT, BUTTON_UP, BUTTON_RIGHT, BUTTON_UP, BUTTON_A }; u32 unlockLvlMax = ((emunand) ? sizeof(unlockSequenceEmu) : sizeof(unlockSequenceSys)) / sizeof(u32); u32* unlockSequence = (emunand) ? unlockSequenceEmu : unlockSequenceSys; u32 unlockLvl = 0; #ifdef USE_THEME LoadThemeGfx((emunand) ? GFX_DANGER_E : GFX_DANGER_S, false); #endif DebugClear(); Debug("You selected \"%s\".", entry->name); Debug("This feature writes to the %s.", (emunand) ? "EmuNAND" : "SysNAND"); Debug("Doing this is potentially dangerous!"); Debug(""); Debug("If you wish to proceed, enter:"); Debug((emunand) ? "<Left>, <Right>, <Down>, <Up>, <A>" : "<Left>, <Up>, <Right>, <Up>, <A>"); Debug(""); Debug("(B to return, START to reboot)"); while (true) { ShowProgress(unlockLvl, unlockLvlMax); if (unlockLvl == unlockLvlMax) break; pad_state = InputWait(); if (!(pad_state & BUTTON_ANY)) continue; else if (pad_state & unlockSequence[unlockLvl]) unlockLvl++; else if (pad_state & (BUTTON_B | BUTTON_START)) break; else if (unlockLvl == 0 || !(pad_state & unlockSequence[unlockLvl-1])) unlockLvl = 0; } ShowProgress(0, 0); if (unlockLvl < unlockLvlMax) return pad_state; } */ // execute this entries function #ifdef USE_THEME LoadThemeGfx(GFX_PROGRESS, false); #endif DebugClear(); res = (SetNand(emunand, nand_force) == 0) ? (*(entry->function))(entry->param) : 1; Debug("%s: %s!", entry->name, (res == 0) ? "succeeded" : "failed"); Debug(""); Debug("Press B to return, START to reboot."); #ifdef USE_THEME LoadThemeGfx((res == 0) ? GFX_DONE : GFX_FAILED, false); #endif /* while(!((pad_state = InputWait()) & (BUTTON_B | BUTTON_START))) { if (pad_state & BUTTON_X) Screenshot(NULL); #ifdef LOG_FILE else if (pad_state & BUTTON_UP) { pad_state = ScrollOutput(); break; } #endif } */ PowerOff(); // returns the last known pad_state return pad_state; }
VOID ResetIntoNormalMode ( VOID ) { DBG (INFO_MESSAGE, "ResetIntoAtMode"); PowerOff (); PowerOnInNormalMode (); }