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 = 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;
- }
- // define each event checker
- event_t CheckForEnteredLight(void) {
- // all event checkers remember their previous Event:
- static int previousEvent;
- // all event checkers update their event:
- int currentEvent = (Roach_LightLevel() < LIGHT_THRESHOLD);
- // current_status = ???
- // if there has been an important change, return an event:
- if (!previousEvent && currentEvent) {
- previousEvent = currentEvent;
- return ENTERED_LIGHT;
- //return SOME_EVENT
- }
- //and if there has not been an important change,
- return NO_EVENT;
- }
- event_t CheckForEnteredDark(void) {
- // all event checkers remember their previous Event:
- static int previousEvent;
- // all event checkers update their event:
- int currentEvent = (Roach_LightLevel() > DARK_THRESHOLD);
- // current_status = ???
- // if there has been an important change, return an event:
- if (!previousEvent && currentEvent) {
- previousEvent = currentEvent;
- return ENTERED_DARK;
- //return SOME_EVENT
- }
- //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 && currentEvent) {
- previousEvent = currentEvent;
- return FRONT_BUMP_DOWN;
- }
- //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;
- }
- //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;
- }
- //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;
- }
- //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;
- }
- //and if there has not been an important change,
- return NO_EVENT;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement