// ----------------------------- event processer boolean HIDbase::processEvents() { doButtons(); paintLCD(); return dTime || dLevel_1 || dLevel_2; }
/***************************************************** * Timer 5 is used to provide the main system clock * It generates an interrupt every millisecond * * This ISR is where most of the actual work gets done. * with the sensors running and the straights profiler * active, this interrupt takes about 220us of which * 120us is processing the sensors *****************************************************/ void _ISR SYSTIM_INTERRUPT(void) { int pidOut; unsigned char rxBytes; /* reset the interrupt flag */ SYSTIM_IF = 0; //LED_ON; tickCount++; millisecondCount--; commCount++; if(!GDO0) { rxBytes = CC2500_receive_packet(); if(rxBytes>PACKET_LEN) { CC2500_idle_mode(); CC2500_clear_rx_fifo(); CC2500_clear_tx_fifo(); CC2500_receive_mode(); commEnabled = FALSE; } else commEnabled = TRUE; if(newPacket) { deassamble_packet(); getFellowCoveredSqrs(); my.obzClear = OBZ_clear(); if(inOBZ(fellow.location)) { LED_ON; } else { LED_OFF; } dataUpdated = TRUE; newPacket = FALSE; noCommCount = 0; } else noCommCount++; } if((commCount>=6)&&commEnabled) { assamble_packet(); if(!GDO0) { CC2500_transmit_packet(); commCount = 0; } } else if(commCount==4) { CC2500_idle_mode(); __delay_us(1); CC2500_clear_rx_fifo(); __delay_us(1); CC2500_clear_tx_fifo(); __delay_us(1); CC2500_receive_mode(); } if(!(tickCount&1)) readCubeSensors(); if(tickCount>300000L) { motorsOff(); sensorsOff(); stopSystemTimer(); LED_ON; } doButtons(); readLineSensors(); readCounters(); doProfiler(); pidOut = doPID( &left_PID_param); if( pidOut < -MOTORS_MAX_DC ) pidOut = -MOTORS_MAX_DC; else if( pidOut > MOTORS_MAX_DC ) pidOut = MOTORS_MAX_DC; motorsLeftSetDutyCycle(pidOut); pidOut = doPID( &right_PID_param); if( pidOut < -MOTORS_MAX_DC ) pidOut = -MOTORS_MAX_DC; else if( pidOut > MOTORS_MAX_DC ) pidOut = MOTORS_MAX_DC; motorsRightSetDutyCycle(pidOut); //LED_OFF; }