/*************************************************************************************************** *FunctionName:Led_GPIOInit *Description:初始化系统指示灯的IO *Input:None *Output:None *Author:xsx *Data:2015年8月26日14:34:45 ***************************************************************************************************/ void Led_GPIOInit(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(Led_Rcc, ENABLE); /*使能LED灯使用的GPIO时钟*/ GPIO_InitStructure.GPIO_Pin = Led_Pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(Led_GpioGroup, &GPIO_InitStructure); SetLedState(ON); }
/* Sets rpt mode when a new wiiremote is connected */ void CWiiRemote::SetupWiiRemote() { //Lights up the apropriate led and setups the rapport mode, so buttons and IR work SetRptMode(); SetLedState(); for (int i = 0; i < WIIREMOTE_SAMPLES; i++) { m_SamplesX[i] = 0; m_SamplesY[i] = 0; } if (cwiid_set_mesg_callback(m_wiiremoteHandle, MessageCallback)) { CPacketLOG log(LOGERROR, "Unable to set message callback to the WiiRemote"); log.Send(m_Socket, m_MyAddr); } }
void CheckSwitch() { #ifndef LOWCODE_NOSWITCHCHECK int x,i; if (!SwitchPort ) { // we are at a start of a pulse for (x=0; x < 10; x++) { } while (!SwitchPort) { x++; // wait for the pulse to finish } if (IsDelay == 0) { pulseCount++; PulseCountHelper++; // write value to EEPROM address EEWriteLong((UCHAR)EEPROMSTARTADDRESS, pulseCount); printf("\r\ncount: "); PrintLong(pulseCount); SetLedState(); if (PulseCountHelper >= MAXCOUNT_PULSES_BEFORE_DELAY) { PulseCountHelper = 0; FlashLed = 1; IsDelay = 1; //TMR2IE=1; // Enable timer 2 interrupts //PEIE=1; // Enable peripheral interrupts for (i = 0 ; i < PULSE_COUNT_DELAY_SEC; i++) { SecDelay(); } FlashLed = 0; IsDelay = 0; } } } #endif }
uint32_t CheckGate(void) { uint32_t result; SetLedState(LED_ENABLE); result = GateIsOpen();/*IsGateOpen(), CheckGateStatus()*/ if(result == GATE_OPEN) { Display("Skier Finished"); MyDelay(TIMEOUT_USER_READ_INFO); } else { AllowNextSkier(); } return result; }
uint32_t CheckReady(void) { uint32_t result; /*sise FIFO*/ if ((FifoGetSize() >= MAX_SKIERS_ON_BUF/*main_db_buffer) */)&& (FifoGetSize() <= MAX_FIFO_SIZE)/*reserv, max_fifo rec*/) { /*skier finish successful*/ Display("Error SD Card!"); SendFinStatus(FIN_NO_READY); if (SkierOnWay() != 0) { /*if skiers on way*/ result = NO_ERROR; } else { /*if not skiers on way*/ result = ERROR; } } else if(FifoGetSize() > MAX_FIFO_SIZE) { /*skier finish no successful*/ Display("Error SD Card!"); SendFinStatus(FIN_NO_READY); result = ERROR; } else if(SkierOnWay() >= MAX_SKIERS_ON_WAY/*MAX_COUNT, TRACK_OVERFLOW*/) { /*max skier on way*/ Display("Max skier on way"); SendFinStatus(FIN_NO_READY); MyDelay(TIMEOUT_USER_READ_INFO); result = NO_ERROR; } else if(SkierOnWay() == 0) { Display("Finish Ready"); SendFinStatus(FIN_READY); SetLedState(LED_DISABLE); result = ERROR; } else { /*finish ready*/ SendFinStatus(FIN_READY); Display("Finish Ready"); result = NO_ERROR; } //if(ReadRebootStartFlag() == REBOOT/*IS*/) if(IsRebootStartFlag() == REBOOT) { result = REBOOT; } /*if admin , read skier time from SD card and send bluetooth*/ if(BLE_getFlagAdminOnly() != 0) { ReadSkierResultAndSendBLE(); } if(ChekTimerForTimeSync() == SYNC_REQUIRES) { SetRebootFlag(); } return result; }
void main() { UCHAR ch; UCHAR tmpch; PulseCountDelaysSec = 65 * PULSE_COUNT_DELAY_SEC; // 1300 aprox 20 sec MaxCountPulse = MAXCOUNT_PULSES_BEFORE_DELAY; PulseCountHelper = 0; IsDelay = 0; FlashLed = 0; init(); printf("\r\nStart...\r\nWaiting for Switch To go High state (5v)\r\n "); while (!SwitchPort) { // wait for the switch to be high } printf("Switch is High\r\n"); pulseCount = EEReadLong(EEPROMSTARTADDRESS); pulseCount = EEReadLong(EEPROMSTARTADDRESS); printf("\r\nStart: current count from eeprom is: "); PrintLong(pulseCount); //ClearEEprom(); //pulseCount = 0; LedPort = 0; Led2Port = 0; int i=0, x; SetLedState(); while (1) { if (pulseCount < MAXCOUNT2+5) { CheckSwitch(); } // check if there is data in the usart ch = peekch(); if (ch != 0) { if (ch == 'R') // read count { printf("\r\ncount: "); PrintLong(pulseCount); } if (ch == 'Z') // zero count { pulseCount = 0; SetLedState(); EEWriteLong(EEPROMSTARTADDRESS, pulseCount); printf("\r\nCount Zeroed"); } if (ch == 'V') // show version { printf(VERSIONSTRING); //printf("\r\nLow Max count set to: "); //PrintLong(MAXCOUNT1); //printf("\r\nHigh Max count set to: "); //PrintLong(MAXCOUNT2); } if (ch == 'S') // read serial number { EEReadData(EEPROMSERIALSTARTADDRESS, Serial, 5); printf("\r\nSerial: %s", Serial); } if (ch == 'D') // set serial number { // need to get 5 chars from serial printf("\r\nEnter Serial Number (5 char): "); for (i=0; i < 5; i++) { Serial[i] = getch(); putch(Serial[i]); } Serial[5] = 0; EEWriteData(EEPROMSERIALSTARTADDRESS, Serial, 5); printf("\r\nSerial set to: %s", Serial); } //if (ch == 'Q') //{ // pulseCount = MAXCOUNT1; // SetLedState(); // EEWriteLong(EEPROMSTARTADDRESS, pulseCount); // printf("\r\nCount Set To Max :"); // PrintLong(pulseCount); //} //if ((ch== 'P') && (pulseCount < MAXCOUNT2+5)) //{ // pulseCount++; // // write value to EEPROM address // EEWriteLong((UCHAR)EEPROMSTARTADDRESS, pulseCount); // printf("\r\ncurrent count is: "); // PrintLong(pulseCount); // SetLedState(); //} } //printf("qs"); } }
void interrupt intsrv(void) { if (TMR2IF) { // this count aprox 200mSec TMR2IF = 0; /* if (LedPortstm == 0) { LedPort = 1; LedPortstm = 1; } else { LedPort = 0; LedPortstm = 0; } */ // are we in delay if (IsDelay == 1) { if (FlashLed == 1) { LedPort = 1; Led2Port = 1; } else { LedPort = 0; //Led2Port = 0; } TimeCounterSec++; // did delay passed if (TimeCounterSec >= PulseCountDelaysSec) { TMR2IE=0; // disable timer 2 interrupts PEIE=0; // Enable peripheral interrupts TimeCounterSec = 0; IsDelay = 0; LedPort = 0; Led2Port = 0; SetLedState(); } FlashingLedCounthelper++; if (FlashingLedCounthelper>=65) { FlashingLedCounthelper = 0; if (FlashLed == 0 ) { FlashLed = 1; } else { FlashLed = 0; } } } } }