Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: events.h
- * Author: maxL
- *
- * Created on July 28, 2016, 12:36 PM
- */
- #include <stdio.h>
- #include <timers.h>
- #include <AD.h>
- #include "events.h"
- #include "roach.h"
- #include "CalibConstants.h"
- // Check for all events:
- event_t CheckForEvents(void) {
- event_t thisEvent = NO_EVENT;
- // thisEvent = CheckForEnteredLight();
- // if (thisEvent != NO_EVENT) {
- // return thisEvent;
- // }
- //
- // thisEvent = CheckForEnteredDark();
- // if (thisEvent != NO_EVENT) {
- // return thisEvent;
- // }
- thisEvent = CheckForOpticEvents();
- if(thisEvent != NO_EVENT){
- return thisEvent;
- }
- thisEvent = CheckForFrontBumpDown();
- if (thisEvent != NO_EVENT) {
- return thisEvent;
- }
- thisEvent = CheckForFLBumpDown();
- if (thisEvent != NO_EVENT) {
- return thisEvent;
- }
- thisEvent = CheckForFRBumpDown();
- if (thisEvent != NO_EVENT) {
- return thisEvent;
- }
- thisEvent = CheckForBackBumpDown();
- if (thisEvent != NO_EVENT) {
- return thisEvent;
- }
- thisEvent = CheckForTimer0Expired();
- if (thisEvent != NO_EVENT) {
- return thisEvent;
- }
- return NO_EVENT;
- }
- event_t CheckForOpticEvents(void)
- {
- // all event checkers remember their previous Event:
- static int previousEvent;
- // all event checkers update their event:
- int currentEvent = previousEvent;
- // current_status = ???
- if(Roach_LightLevel() > DARK_THRESHOLD){
- if(previousEvent != ENTERED_DARK)
- currentEvent = ENTERED_DARK;
- }else if(Roach_LightLevel() < LIGHT_THRESHOLD){
- if(previousEvent != ENTERED_LIGHT)
- currentEvent = ENTERED_LIGHT;
- }
- // if there has been an important change, return an event:
- if (previousEvent != currentEvent) {
- previousEvent = currentEvent;
- //return SOME_EVENT
- return currentEvent;
- }
- //and if there has not been an important change,
- return NO_EVENT;
- }
- event_t CheckForFrontBumpDown(void) {
- // all event checkers remember their previous Event:
- static int previousEvent;
- // all event checkers update their event:
- int currentEvent = (Roach_ReadFrontLeftBumper() << 1) + Roach_ReadFrontRightBumper();
- // if there has been an important change, return an event:
- if (previousEvent != 0b11 && currentEvent == 0b11) {
- previousEvent = currentEvent;
- return FRONT_BUMP_DOWN;
- }
- previousEvent = currentEvent;
- //and if there has not been an important change,
- return NO_EVENT;
- }
- event_t CheckForFLBumpDown(void) {
- // all event checkers remember their previous Event:
- static int previousEvent;
- // all event checkers update their event:
- int currentEvent = Roach_ReadFrontLeftBumper();
- // if there has been an important change, return an event:
- if (!previousEvent && currentEvent) {
- previousEvent = currentEvent;
- return FL_BUMP_DOWN;
- }
- previousEvent = currentEvent;
- //and if there has not been an important change,
- return NO_EVENT;
- }
- event_t CheckForFRBumpDown(void) {
- // all event checkers remember their previous Event:
- static int previousEvent;
- // all event checkers update their event:
- int currentEvent = Roach_ReadFrontRightBumper();
- // if there has been an important change, return an event:
- if (!previousEvent && currentEvent) {
- previousEvent = currentEvent;
- return FR_BUMP_DOWN;
- }
- previousEvent = currentEvent;
- //and if there has not been an important change,
- return NO_EVENT;
- }
- event_t CheckForBackBumpDown(void) {
- // all event checkers remember their previous Event:
- static int previousEvent;
- // all event checkers update their event:
- int currentEvent = (Roach_ReadRearRightBumper() << 1) + Roach_ReadRearLeftBumper();
- // if there has been an important change, return an event:
- if (!previousEvent && currentEvent) {
- previousEvent = currentEvent;
- return BACK_BUMP_DOWN;
- }
- previousEvent = currentEvent;
- //and if there has not been an important change,
- return NO_EVENT;
- }
- event_t CheckForTimer0Expired(void) {
- // all event checkers remember their previous Event:...NAH
- static int previousEvent;
- // all event checkers update their event:
- int currentEvent = IsTimerExpired(0);
- // current_status = ???
- // if there has been an important change, return an event:
- if (!previousEvent && currentEvent) {
- previousEvent = currentEvent;
- return TIMER_0_EXPIRED;
- }
- previousEvent = currentEvent;
- //and if there has not been an important change,
- return NO_EVENT;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement