Advertisement
harinin

Untitled

Aug 3rd, 2016
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * File:   events.h
  3.  * Author: maxL
  4.  *
  5.  * Created on July 28, 2016, 12:36 PM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <timers.h>
  10. #include <AD.h>
  11. #include "events.h"
  12. #include "roach.h"
  13. #include "CalibConstants.h"
  14.  
  15. // Check for all events:
  16.  
  17. event_t CheckForEvents(void) {
  18.     event_t thisEvent = NO_EVENT;
  19.  
  20. //    thisEvent = CheckForEnteredLight();
  21. //    if (thisEvent != NO_EVENT) {
  22. //        return thisEvent;
  23. //    }
  24. //
  25. //    thisEvent = CheckForEnteredDark();
  26. //    if (thisEvent != NO_EVENT) {
  27. //        return thisEvent;
  28. //    }
  29.     thisEvent = CheckForOpticEvents();
  30.     if(thisEvent != NO_EVENT){
  31.         return thisEvent;
  32.     }
  33.    
  34.    
  35.     thisEvent = CheckForFrontBumpDown();
  36.     if (thisEvent != NO_EVENT) {
  37.         return thisEvent;
  38.     }
  39.    
  40.     thisEvent = CheckForFLBumpDown();
  41.     if (thisEvent != NO_EVENT) {
  42.         return thisEvent;
  43.     }
  44.    
  45.     thisEvent = CheckForFRBumpDown();
  46.     if (thisEvent != NO_EVENT) {
  47.         return thisEvent;
  48.     }
  49.    
  50.     thisEvent = CheckForBackBumpDown();
  51.     if (thisEvent != NO_EVENT) {
  52.         return thisEvent;
  53.     }
  54.  
  55.     thisEvent = CheckForTimer0Expired();
  56.     if (thisEvent != NO_EVENT) {
  57.         return thisEvent;
  58.     }
  59.     return NO_EVENT;
  60. }
  61.  
  62. event_t CheckForOpticEvents(void)
  63. {
  64.     // all event checkers remember their previous Event:
  65.     static int previousEvent;
  66.  
  67.     // all event checkers update their event:
  68.     int currentEvent = previousEvent;
  69.     // current_status = ???
  70.     if(Roach_LightLevel() > DARK_THRESHOLD){
  71.         if(previousEvent != ENTERED_DARK)
  72.             currentEvent = ENTERED_DARK;
  73.     }else if(Roach_LightLevel() < LIGHT_THRESHOLD){
  74.         if(previousEvent != ENTERED_LIGHT)
  75.             currentEvent = ENTERED_LIGHT;
  76.     }
  77.  
  78.     // if there has been an important change, return an event:
  79.     if (previousEvent != currentEvent) {
  80.         previousEvent = currentEvent;
  81.         //return SOME_EVENT
  82.         return currentEvent;
  83.     }
  84.  
  85.     //and if there has not been an important change,
  86.     return NO_EVENT;
  87. }
  88.  
  89.  
  90.  
  91. event_t CheckForFrontBumpDown(void) {
  92.     // all event checkers remember their previous Event:
  93.     static int previousEvent;
  94.  
  95.     // all event checkers update their event:
  96.     int currentEvent = (Roach_ReadFrontLeftBumper() << 1) + Roach_ReadFrontRightBumper();
  97.  
  98.     // if there has been an important change, return an event:
  99.     if (previousEvent != 0b11 && currentEvent == 0b11) {
  100.         previousEvent = currentEvent;
  101.         return FRONT_BUMP_DOWN;
  102.     }
  103.     previousEvent = currentEvent;
  104.     //and if there has not been an important change,
  105.     return NO_EVENT;
  106. }
  107.  
  108. event_t CheckForFLBumpDown(void) {
  109.     // all event checkers remember their previous Event:
  110.     static int previousEvent;
  111.  
  112.     // all event checkers update their event:
  113.     int currentEvent = Roach_ReadFrontLeftBumper();
  114.  
  115.     // if there has been an important change, return an event:
  116.     if (!previousEvent && currentEvent) {
  117.         previousEvent = currentEvent;
  118.         return FL_BUMP_DOWN;
  119.     }
  120.     previousEvent = currentEvent;
  121.     //and if there has not been an important change,
  122.     return NO_EVENT;
  123. }
  124.  
  125. event_t CheckForFRBumpDown(void) {
  126.     // all event checkers remember their previous Event:
  127.     static int previousEvent;
  128.  
  129.     // all event checkers update their event:
  130.     int currentEvent = Roach_ReadFrontRightBumper();
  131.  
  132.     // if there has been an important change, return an event:
  133.     if (!previousEvent && currentEvent) {
  134.         previousEvent = currentEvent;
  135.         return FR_BUMP_DOWN;
  136.     }
  137.     previousEvent = currentEvent;
  138.     //and if there has not been an important change,
  139.     return NO_EVENT;
  140. }
  141.  
  142. event_t CheckForBackBumpDown(void) {
  143.     // all event checkers remember their previous Event:
  144.     static int previousEvent;
  145.  
  146.     // all event checkers update their event:
  147.     int currentEvent = (Roach_ReadRearRightBumper() << 1) + Roach_ReadRearLeftBumper();
  148.  
  149.     // if there has been an important change, return an event:
  150.     if (!previousEvent && currentEvent) {
  151.         previousEvent = currentEvent;
  152.         return BACK_BUMP_DOWN;
  153.     }
  154.    
  155.     previousEvent = currentEvent;
  156.     //and if there has not been an important change,
  157.     return NO_EVENT;
  158. }
  159.  
  160. event_t CheckForTimer0Expired(void) {
  161.     // all event checkers remember their previous Event:...NAH
  162.     static int previousEvent;
  163.  
  164.     // all event checkers update their event:
  165.     int currentEvent = IsTimerExpired(0);
  166.     // current_status = ???
  167.  
  168.     // if there has been an important change, return an event:
  169.     if (!previousEvent && currentEvent) {
  170.         previousEvent = currentEvent;
  171.         return TIMER_0_EXPIRED;
  172.     }
  173.     previousEvent = currentEvent;
  174.     //and if there has not been an important change,
  175.     return NO_EVENT;
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement