Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RequestQueue.h@4:95fe80130442, 2015-03-27 (annotated)
- Committer:
- avinashr
- Date:
- Fri Mar 27 03:53:57 2015 +0000
- Revision:
- 4:95fe80130442
- Parent:
- 3:c3d716d6c6a7
Elevator code, working on test bench
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| avinashr | 1:4ec28912c9e7 | 1 | #include "mbed.h" |
| avinashr | 1:4ec28912c9e7 | 2 | |
| avinashr | 1:4ec28912c9e7 | 3 | #ifndef REQUESTQUEUE_H |
| avinashr | 1:4ec28912c9e7 | 4 | #define REQUESTQUEUE_H |
| avinashr | 1:4ec28912c9e7 | 5 | |
| avinashr | 2:2cc70773996b | 6 | class RequestQueue { |
| avinashr | 1:4ec28912c9e7 | 7 | |
| avinashr | 2:2cc70773996b | 8 | private : |
| avinashr | 2:2cc70773996b | 9 | int floorRequests[5]; |
| avinashr | 2:2cc70773996b | 10 | public : |
| avinashr | 2:2cc70773996b | 11 | RequestQueue() { |
| avinashr | 2:2cc70773996b | 12 | for(int i=0;i<5;i++) |
| avinashr | 2:2cc70773996b | 13 | floorRequests[i] = 0; |
| avinashr | 2:2cc70773996b | 14 | } |
| avinashr | 1:4ec28912c9e7 | 15 | |
| avinashr | 2:2cc70773996b | 16 | void add(int); |
| avinashr | 2:2cc70773996b | 17 | void remove(int); |
| avinashr | 2:2cc70773996b | 18 | int isRequested (int); |
| avinashr | 3:c3d716d6c6a7 | 19 | int isForwardRequested (int); |
| avinashr | 3:c3d716d6c6a7 | 20 | int isReverseRequested (int); |
| avinashr | 1:4ec28912c9e7 | 21 | }; |
| avinashr | 1:4ec28912c9e7 | 22 | |
| avinashr | 2:2cc70773996b | 23 | void RequestQueue::add (int i){ |
| avinashr | 4:95fe80130442 | 24 | //pc.printf(": %d is requested :",i); |
| avinashr | 3:c3d716d6c6a7 | 25 | floorRequests[i-1] = 1; |
| avinashr | 2:2cc70773996b | 26 | } |
| avinashr | 2:2cc70773996b | 27 | |
| avinashr | 2:2cc70773996b | 28 | void RequestQueue::remove (int i){ |
| avinashr | 3:c3d716d6c6a7 | 29 | floorRequests[i-1] = 0; |
| avinashr | 2:2cc70773996b | 30 | } |
| avinashr | 2:2cc70773996b | 31 | |
| avinashr | 2:2cc70773996b | 32 | int RequestQueue::isRequested (int i){ |
| avinashr | 3:c3d716d6c6a7 | 33 | return floorRequests[i-1]; |
| avinashr | 3:c3d716d6c6a7 | 34 | } |
| avinashr | 3:c3d716d6c6a7 | 35 | |
| avinashr | 3:c3d716d6c6a7 | 36 | int RequestQueue::isForwardRequested (int i){ |
| avinashr | 3:c3d716d6c6a7 | 37 | for(int j = i; j<5; j++){ |
| avinashr | 3:c3d716d6c6a7 | 38 | if(floorRequests[j] == 1) |
| avinashr | 3:c3d716d6c6a7 | 39 | return 1; |
| avinashr | 3:c3d716d6c6a7 | 40 | } |
| avinashr | 3:c3d716d6c6a7 | 41 | return 0; |
| avinashr | 3:c3d716d6c6a7 | 42 | } |
| avinashr | 3:c3d716d6c6a7 | 43 | |
| avinashr | 3:c3d716d6c6a7 | 44 | int RequestQueue::isReverseRequested (int i){ |
| avinashr | 3:c3d716d6c6a7 | 45 | for(int j = 0; j<i-1; j++){ |
| avinashr | 3:c3d716d6c6a7 | 46 | if(floorRequests[j] == 1) |
| avinashr | 3:c3d716d6c6a7 | 47 | return 1; |
| avinashr | 3:c3d716d6c6a7 | 48 | } |
| avinashr | 3:c3d716d6c6a7 | 49 | return 0; |
| avinashr | 2:2cc70773996b | 50 | } |
| avinashr | 2:2cc70773996b | 51 | |
| avinashr | 1:4ec28912c9e7 | 52 | #endif |