void CMyButton::PreSubclassWindow() { // TODO: Add your specialized code here and/or call the base class CButton::PreSubclassWindow(); ButtonInit(); }
BOOL CMyButton::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Add your specialized code here and/or call the base class BOOL bRect = CButton::PreCreateWindow(cs); ButtonInit(); return bRect; }
int main(void) { /* Watchdog timer disabled */ WDTCTL = WDTPW + WDTHOLD; BspInit(); DioInit(); DioSet(BUTTON0); UartInit(9600, UartCallback); LedInit(); ButtonInit(); ButtonSetup(0, Button0Cbf, 20); LedOn(0); SchedulerInit(100, 1, 2); // 1ms tick, 1 timed task, 2 loop task SetSchedulerTimedTask(LedRedFlash, 0, 500, 0); // schedule timed_task[0] as led_red_flash, set off every 500ms SetSchedulerLoopTask(ButtonLoop, 0); // schedule loop_task[0] as button_loop SetSchedulerLoopTask(UartManage, 1); // schedule loop_task[1] as uart_loop __eint(); SchedulerRun(); while(1) { } }
/*----------------------------------------------------------------------------- * main */ int main(void) { uint8_t ret; int sioHdl; /* set clock prescaler to 2 (set clock to 7.3928 MHz) */ CLKPR = 1 << CLKPCE; CLKPR = 1; /* get module address from EEPROM */ sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS); GetClientListFromEeprom(); PortInit(); TimerInit(); ButtonInit(); PwmInit(); ApplicationInit(); SioInit(); SioRandSeed(sMyAddr); /* sio for bus interface */ sioHdl = SioOpen("USART1", eSioBaud9600, eSioDataBits8, eSioParityNo, eSioStopBits1, eSioModeHalfDuplex); SioSetIdleFunc(sioHdl, IdleSio1); SioSetTransceiverPowerDownFunc(sioHdl, BusTransceiverPowerDown); BusTransceiverPowerDown(true); BusInit(sioHdl); spBusMsg = BusMsgBufGet(); /* warten for full operation voltage */ while (!POWER_GOOD); /* enable ints before RestorePwm() */ ENABLE_INT; TimerStart(); RestorePwm(); /* ext int for power fail: INT0 low level sensitive */ EICRA &= ~((1 << ISC01) | (1 << ISC00)); EIMSK |= (1 << INT0); ApplicationStart(); /* Hauptschleife */ while (1) { Idle(); ret = BusCheck(); ProcessBus(ret); CheckButton(); PwmCheck(); ApplicationCheck(); CheckEvent(); } return 0; }
void CreditsInit() { SDL_Color textColor = { 255, 255, 255 }; ImageLoad("../../Resource/matrix.png", &c_background); TextLoad(&t, "../../Resource/alien.ttf", 30); TextPos(&t, 20, 250); TextColor(&t, &textColor); ButtonInit(&back, "../../Resource/back.png", 700, 500); }
int ButtonWait(void) { int button; ButtonInit(); button = ButtonGet(); switch (button) { case '1': return EXITCODE_OK; case '2': return EXITCODE_CANCEL; case '3': return EXITCODE_EXTRA; case ASCII_CAN: return EXITCODE_TIMEOUT; } return EXITCODE_ERROR; }
// main task to loop void MainLoop(void *pvParameters) { ButtonInit(); for(;;) { if (val&1) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); } else { GPIO_IF_LedOff(MCU_RED_LED_GPIO); } if (val &(1<<1)) { GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO); } else { GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO); } if (val & (1<<2)) { GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); } else { GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); } } }
int main ( void ) { printf("Game!\n"); // Init devices ButtonInit(); LedInit(); Screen screen = ScreenNew(320, 240); Canvas canvas = CanvasNew( &screen ); // Init game Controller ctrl = ControllerNew( &canvas ); onGameInit( &ctrl ); // Main loop static tick_delay = 0; while(ctrl.running) { if ( tick_delay++ == 20000 ) { tick_delay = 0; onTick( &ctrl ); } ButtonPoll(); } onGameExit( &ctrl ); ButtonDestroy(); LedDestroy(); ScreenDestroy( &screen ); return 0; }
void BoardInitPeriph( void ) { /*GpioInit( &Sel1, SEL_1, PIN_OUTPUT, PIN_OPEN_DRAIN, PIN_NO_PULL, 0 ); GpioInit( &Sel2, SEL_2, PIN_OUTPUT, PIN_OPEN_DRAIN, PIN_NO_PULL, 0 ); GpioInit( &Sel3, SEL_3, PIN_OUTPUT, PIN_OPEN_DRAIN, PIN_NO_PULL, 0 ); GpioInit( &Sel4, SEL_4, PIN_OUTPUT, PIN_OPEN_DRAIN, PIN_NO_PULL, 0 );*/ /*GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); GpioInit( &Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); GpioInit( &Led3, LED_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); GpioInit( &Led4, LED_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );*/ /*GpioInit( &Btn1, BTN_1, PIN_INPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); GpioInit( &Btn2, BTN_2, PIN_INPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );*/ // Init temperature, pressure and altitude sensor //MPL3115Init( ); // Init Leds LedInit(); // Init Buttons ButtonInit(); }
CTransButton::CTransButton(CWnd* pParentWnd) : m_nLinkPageID(-1) { ASSERT(pParentWnd!=NULL); m_pParentWnd=pParentWnd; ButtonInit(); }
void CMyButton::PreSubclassWindow() { CButton::PreSubclassWindow(); ButtonInit(); }
BOOL CMyButton::PreCreateWindow(CREATESTRUCT& cs) { BOOL bRet=CButton::PreCreateWindow(cs); ButtonInit(); return bRet; }
/////////////////////////////////////////////////////////////////////////////// //////////////////////////////// MAIN /////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// int main(void) { IntMasterDisable(); //=====SYSTEM PERIPHERAL INITIALIZATION===== // Initialize real time clock mRTCInit(RTC_RATE_HZ); // Millisecond timekeeping variable int time; //Add periodic tasks to be executed by systick mRTCAddTask(heightSample, HEIGHT_SAMPLE_RATE_HZ); // Set up display mDisplayInit(1000000); mDisplayLine(" Waiting... ", 0, 5, 15); // Set up buttons ButtonInit(); // Set up PWM mPWMInit(); mPWMEnable(PWM4, false); // tail rotor, yaw control. mPWMEnable(PWM1, false); // main rotor, height control. //=========CONTROL INITIALIZATION======== //-----altitude PID control------ // Initialize altitude module heightInit(); // =========PID parameters======================== //Phils float H_kp = 1;float H_ki = 1.5;float H_kd = -0.5; short heightPIDOffset = 40; float Y_kp = 0.6;float Y_ki = 0;float Y_kd = 0; short YawPIDOffset = 0;//50; // Windup regulator float H_windup_limit = 10; if (H_ki) H_windup_limit /= H_ki; // height PID controller pid_t heightPID; PIDInit(&heightPID); PIDSet(&heightPID, H_kp, H_ki, H_kd, H_windup_limit); // set PID constants // height PID control variables //35; // PID out offset such that the rotor is at near-takoff speed short height = 0; short heightSetpoint = 0; // in degrees short heightError = 0; short heightPIDOut = 0; //-----yaw PID control------- // Initialise Yaw decoder module yawInit(); // yaw monitor float Y_windup_limit = 20; // Maximum integral contribution to PID output value if (Y_ki) Y_windup_limit /= Y_ki; // devide by Y_ki to find maximum value in terms of error // Yaw PID controller pid_t yawPID; PIDInit(&yawPID); PIDSet(&yawPID, Y_kp, Y_ki, Y_kd, Y_windup_limit); // set PID constants // yaw PID control variables short yaw = 0; short yawSetpoint = 0; short yawError = 0; short yawPIDOut = 0; // // Enable interrupts to the processor. IntMasterEnable(); short takeOffFlag = false; while (!takeOffFlag) { if (ButtonCheck(SELECT)) //if (GPIOPinRead(GPIO_PORTG_BASE, 0x80)) { takeOffFlag = true; } } // Reset setpoints to current position heightSetpoint = heightGet(); yawSetpoint = yawGetAngle(); mPWMEnable(PWM4, true); // tail rotor, yaw control. mPWMEnable(PWM1, true); // main rotor, height control. //spin up routine //spinUp(heightPIDOffset, yawPID); // Reset clock to zero for effective helicopter launch time mRTCSet(0); while (1) { //mDisplayClear(); time = mRTCGetMilliSeconds(); // Update Setpoints updateSetpoints(&yawSetpoint, &heightSetpoint); // ==================PID Control================= if ((time % (RTC_RATE_HZ/PID_RATE_HZ)) /*1000/(float)PID_RATE_HZ*/ == 0) { // // ~~~~~~~~~~~~~~~~~ HEIGHT PID ~~~~~~~~~~~~~~~~ height = heightGet(); heightError = heightSetpoint - height; heightPIDOut = PIDUpdate(&heightPID, heightError, 1.00 / (float)PID_RATE_HZ) + heightPIDOffset; if (heightPIDOut > 79) //heightPIDOut = 79; if (heightPIDOut < 2) heightPIDOut = 2; mPWMSet(PWM1, (unsigned short)heightPIDOut); // // ~~~~~~~~~~~~~~~~~~ YAW PID ~~~~~~~~~~~~~~~~~~~ yaw = yawGetAngle(); yawError = yaw - yawSetpoint; yawPIDOut = PIDUpdate(&yawPID, yawError, 1.00 / (float)PID_RATE_HZ) + YawPIDOffset; if (yawPIDOut > 79) yawPIDOut = 79; if (yawPIDOut < 2) yawPIDOut = 2; mPWMSet(PWM4, (unsigned short)yawPIDOut); // =============================================== } // RTC_RATE_HZ - PID_RATE_HZ if (( (time) % 10) == 0) { mDisplayLine("time:%.6d mS", time, 0, 7); mDisplayLine("Yaw = %.4d' ", (int)yaw, 1, 15); mDisplayLine("YSet = %.4d' ", (int)yawSetpoint, 2, 15); mDisplayLine("YErr = %.4d' ", (int)yawError, 3, 15); mDisplayLine("YOut = %.4d' ", (int)yawPIDOut, 4, 15); mDisplayLine("height = ~%.3d ", (int)height, 5, 15); mDisplayLine("Hset = %.4d ", (int)heightSetpoint, 6, 15); mDisplayLine("Herr = %.4d ", (int)heightError, 7, 15); mDisplayLine("Hout = %.4d ", (int)heightPIDOut, 8, 15); } // should put this as part of the main while loop condition //if (ButtonCheck(SELECT)) //{ // spinDown(); //} } }
/******************************************************************** * Function: static void InitializeSystem(void) * Overview: InitializeSystem is a centralize initialization * routine. All required USB initialization routines * are called from here. * * User application initialization routine should * also be called from here. *******************************************************************/ static void InitializeSystem(void) { ADCON1 |= 0x0F; // Default all pins to digital // initialize LED1_TRIS = 0; // LED1 output LED2_TRIS = 0; // LED2 output IR_TRIS = 1; // IR input SW_TRIS = 1; // SW input IRLED_TRIS= 0; // IRLED input LED1_PORT = 0; LED2_PORT = 0; IRLED_PORT= 0; // timer list // 48MHz/4=12MHz => 0.08333[us/cycle] // 0.08333[us/cycle] * 2 = 0.16666us -> max: *65536 = 10.923ms // 0.08333[us/cycle] * 4 = 0.33333us -> max: *65536 = 21.845ms // 0.08333[us/cycle] * 8 = 0.66666us -> max: *65536 = 43.69ms // 0.08333[us/cycle] * 16 = 1.33333us -> max: *65536 = 87.381ms // 0.08333[us/cycle] * 32 = 2.66666us -> max: *65536 = 174.76ms // 0.08333[us/cycle] * 64 = 5.33333us -> max: *65536 = 349.5ms // 0.08333[us/cycle] *128 = 10.66666us -> max: *65536 = 699ms // 0.08333[us/cycle] *256 = 21.33333us -> max: *65536 = 1398ms // timer0 max=349.5[ms] T0CON = TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_EDGE_RISE & // なんでもいい T0_PS_1_64; // timer1 max=43.69[ms] T1CON = TIMER_INT_ON & T1_16BIT_RW & T1_SOURCE_INT & T1_PS_1_8; // timer2 max=5.33333[us]*256=1.365[ms] 約1ms T2CON = T2_POST_1_4 & T2_PS_1_16; // configure USART // For a device with FOSC of 16 MHz, desired baud rate of 9600, Asynchronous mode, 8-bit BRG: // Desired Baud Rate = FOSC/(64 ([SPBRGH:SPBRG] + 1)) // Solving for SPBRGH:SPBRG: // X = ((FOSC/Desired Baud Rate)/64) – 1 // = ((16000000/9600)/64) – 1 // = [25.042] = 25 // Calculated Baud Rate = 16000000/(64 (25 + 1)) // = 9615 // Error = (Calculated Baud Rate – Desired Baud Rate)/Desired Baud Rate // = (9615 - 9600)/9600 = 0.16% // FOSC == 48 [MHz] // X = ((48 * 1,000,000 / 9600)/64 -1 // = 77.125 // Calculated Baud Rate = 48 * 1,000,000 / (64 * (77+1)) = 9615.38 // Error = (9615 - 9600) / 9600 = 0.16% OpenUSART(USART_TX_INT_OFF & // 送信割込みの禁止 USART_RX_INT_ON & // 受信割込みの許可 USART_ASYNCH_MODE & // 非同期(調歩)モード USART_EIGHT_BIT & // 8ビットモード USART_CONT_RX & // 連続受信モード USART_BRGH_LOW, // 低速ボーレート 77); // 9600 bps RCONbits.IPEN = 0; //割込み優先順位制御:OFF (RCON レジスタのIPENビット = 0) INTCONbits.GIE = 1; // 全割込み許可 INTCONbits.PEIE = 1; // 周辺機能の割込み有効 // initilize other variables InitBuffer(); AddBuffer(signalBuffer, sizeof(signalBuffer)); ButtonInit(SW_BIT); enableReadIR = 1; }