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