Eurobot2012_Primary
Dependencies: mbed Eurobot_2012_Primary
Eurobot_shared/ui/ui.cpp@11:ea2112ae3c4a, 2012-04-28 (annotated)
- Committer:
- narshu
- Date:
- Sat Apr 28 18:21:16 2012 +0000
- Revision:
- 11:ea2112ae3c4a
- Parent:
- 9:377560539b74
- Child:
- 14:24f994dc2770
half done chagnes n stuff
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
narshu | 2:cffa347bb943 | 1 | |
narshu | 2:cffa347bb943 | 2 | #include "ui.h" |
narshu | 2:cffa347bb943 | 3 | #include <iostream> |
narshu | 7:f9c59a3e4155 | 4 | #include "system.h" |
narshu | 2:cffa347bb943 | 5 | |
narshu | 2:cffa347bb943 | 6 | UI::UI() : |
narshu | 8:ffc7d8af2d5a | 7 | tUI(printtw,this,osPriorityNormal,2048) { |
narshu | 2:cffa347bb943 | 8 | newdataflags = 0; |
narshu | 2:cffa347bb943 | 9 | for (int i = 0; i < NUMIDS; i++) { |
narshu | 2:cffa347bb943 | 10 | idlist[i] = 0; |
narshu | 2:cffa347bb943 | 11 | buffarr[i] = 0; |
narshu | 2:cffa347bb943 | 12 | } |
narshu | 2:cffa347bb943 | 13 | |
narshu | 2:cffa347bb943 | 14 | } |
narshu | 2:cffa347bb943 | 15 | |
narshu | 2:cffa347bb943 | 16 | bool UI::regid(char id, unsigned int length) { |
narshu | 2:cffa347bb943 | 17 | |
narshu | 2:cffa347bb943 | 18 | //check if the id is already taken |
narshu | 2:cffa347bb943 | 19 | if (id < NUMIDS && !idlist[id]) { |
narshu | 2:cffa347bb943 | 20 | idlist[id] = length; |
narshu | 2:cffa347bb943 | 21 | buffarr[id] = new float[length]; |
narshu | 2:cffa347bb943 | 22 | return true; |
narshu | 2:cffa347bb943 | 23 | } else |
narshu | 2:cffa347bb943 | 24 | return false; |
narshu | 2:cffa347bb943 | 25 | } |
narshu | 2:cffa347bb943 | 26 | |
narshu | 2:cffa347bb943 | 27 | bool UI::updateval(char id, float* buffer, unsigned int length) { |
narshu | 8:ffc7d8af2d5a | 28 | |
narshu | 2:cffa347bb943 | 29 | //check if the id is registered, and has buffer of correct length |
narshu | 2:cffa347bb943 | 30 | if (id < NUMIDS && idlist[id] == length && buffarr[id] && !(newdataflags & (1<<id))) { |
narshu | 2:cffa347bb943 | 31 | for (int i = 0; i < length; i++) |
narshu | 2:cffa347bb943 | 32 | buffarr[id][i] = buffer[i]; |
narshu | 2:cffa347bb943 | 33 | newdataflags |= (1<<id); |
narshu | 2:cffa347bb943 | 34 | return true; |
narshu | 8:ffc7d8af2d5a | 35 | } else{ |
narshu | 2:cffa347bb943 | 36 | return false; |
narshu | 8:ffc7d8af2d5a | 37 | } |
narshu | 2:cffa347bb943 | 38 | } |
narshu | 2:cffa347bb943 | 39 | |
narshu | 2:cffa347bb943 | 40 | bool UI::updateval(char id, float value) { |
narshu | 2:cffa347bb943 | 41 | |
narshu | 2:cffa347bb943 | 42 | //check if the id is registered, and the old value has been written |
narshu | 2:cffa347bb943 | 43 | if (id < NUMIDS && idlist[id] == 1 && buffarr[id] && !(newdataflags & (1<<id))) { |
narshu | 2:cffa347bb943 | 44 | buffarr[id][0] = value; |
narshu | 2:cffa347bb943 | 45 | newdataflags |= (1<<id); |
narshu | 2:cffa347bb943 | 46 | return true; |
narshu | 2:cffa347bb943 | 47 | } else |
narshu | 2:cffa347bb943 | 48 | return false; |
narshu | 2:cffa347bb943 | 49 | |
narshu | 2:cffa347bb943 | 50 | } |
narshu | 2:cffa347bb943 | 51 | |
narshu | 2:cffa347bb943 | 52 | bool UI::unregid(char id) { |
narshu | 2:cffa347bb943 | 53 | if (id < NUMIDS) { |
narshu | 2:cffa347bb943 | 54 | idlist[id] = 0; |
narshu | 2:cffa347bb943 | 55 | if (buffarr[id]) |
narshu | 2:cffa347bb943 | 56 | delete buffarr[id]; |
narshu | 2:cffa347bb943 | 57 | return true; |
narshu | 2:cffa347bb943 | 58 | } else |
narshu | 2:cffa347bb943 | 59 | return false; |
narshu | 2:cffa347bb943 | 60 | } |
narshu | 2:cffa347bb943 | 61 | |
narshu | 2:cffa347bb943 | 62 | void UI::printloop() { |
narshu | 2:cffa347bb943 | 63 | |
narshu | 11:ea2112ae3c4a | 64 | //Thread::wait(1500); |
narshu | 11:ea2112ae3c4a | 65 | Thread::wait(osWaitForever); |
narshu | 7:f9c59a3e4155 | 66 | |
narshu | 2:cffa347bb943 | 67 | char* sync = "ABCD"; |
narshu | 6:324946320c6d | 68 | std::cout.write(sync, 4); |
narshu | 8:ffc7d8af2d5a | 69 | //std::cout.flush(); |
narshu | 8:ffc7d8af2d5a | 70 | std::cout << std::endl; |
narshu | 7:f9c59a3e4155 | 71 | //printf("\r\n"); |
narshu | 2:cffa347bb943 | 72 | |
narshu | 2:cffa347bb943 | 73 | while (1) { |
narshu | 8:ffc7d8af2d5a | 74 | |
narshu | 8:ffc7d8af2d5a | 75 | OLED3 = !OLED3; |
narshu | 8:ffc7d8af2d5a | 76 | |
narshu | 8:ffc7d8af2d5a | 77 | //send number of packets |
narshu | 8:ffc7d8af2d5a | 78 | char numtosend = 0; |
narshu | 8:ffc7d8af2d5a | 79 | for (int id = 0; id < NUMIDS; id++) |
narshu | 8:ffc7d8af2d5a | 80 | if (newdataflags & (1<<id)) |
narshu | 8:ffc7d8af2d5a | 81 | numtosend++; |
narshu | 8:ffc7d8af2d5a | 82 | |
narshu | 8:ffc7d8af2d5a | 83 | std::cout.put(numtosend); |
narshu | 2:cffa347bb943 | 84 | |
narshu | 6:324946320c6d | 85 | //send packets |
narshu | 8:ffc7d8af2d5a | 86 | for (char id = 0; id < NUMIDS; id++) { |
narshu | 6:324946320c6d | 87 | if (newdataflags & (1<<id)) { |
narshu | 6:324946320c6d | 88 | std::cout.put(id); |
narshu | 8:ffc7d8af2d5a | 89 | std::cout.write((char*)buffarr[id], idlist[id] * sizeof(float)); |
narshu | 6:324946320c6d | 90 | newdataflags &= ~(1<<id); |
narshu | 2:cffa347bb943 | 91 | } |
narshu | 2:cffa347bb943 | 92 | } |
narshu | 8:ffc7d8af2d5a | 93 | |
narshu | 8:ffc7d8af2d5a | 94 | std::cout << std::endl; |
narshu | 7:f9c59a3e4155 | 95 | //std::cout.flush(); |
narshu | 2:cffa347bb943 | 96 | Thread::wait(200); |
narshu | 2:cffa347bb943 | 97 | } |
narshu | 2:cffa347bb943 | 98 | |
narshu | 2:cffa347bb943 | 99 | } |
narshu | 2:cffa347bb943 | 100 |