Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Fri Apr 27 16:37:26 2012 +0000
Revision:
7:f9c59a3e4155
Parent:
6:324946320c6d
Child:
8:ffc7d8af2d5a
Serial problem fixed, working on UI

Who changed what in which revision?

UserRevisionLine numberNew 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 2:cffa347bb943 7 tUI(printtw,this,osPriorityNormal,1024) {
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 2:cffa347bb943 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 2:cffa347bb943 35 } else
narshu 2:cffa347bb943 36 return false;
narshu 2:cffa347bb943 37 }
narshu 2:cffa347bb943 38
narshu 2:cffa347bb943 39 bool UI::updateval(char id, float value) {
narshu 2:cffa347bb943 40
narshu 2:cffa347bb943 41 //check if the id is registered, and the old value has been written
narshu 2:cffa347bb943 42 if (id < NUMIDS && idlist[id] == 1 && buffarr[id] && !(newdataflags & (1<<id))) {
narshu 2:cffa347bb943 43 buffarr[id][0] = value;
narshu 2:cffa347bb943 44 newdataflags |= (1<<id);
narshu 2:cffa347bb943 45 return true;
narshu 2:cffa347bb943 46 } else
narshu 2:cffa347bb943 47 return false;
narshu 2:cffa347bb943 48
narshu 2:cffa347bb943 49 }
narshu 2:cffa347bb943 50
narshu 2:cffa347bb943 51 bool UI::unregid(char id) {
narshu 2:cffa347bb943 52 if (id < NUMIDS) {
narshu 2:cffa347bb943 53 idlist[id] = 0;
narshu 2:cffa347bb943 54 if (buffarr[id])
narshu 2:cffa347bb943 55 delete buffarr[id];
narshu 2:cffa347bb943 56 return true;
narshu 2:cffa347bb943 57 } else
narshu 2:cffa347bb943 58 return false;
narshu 2:cffa347bb943 59 }
narshu 2:cffa347bb943 60
narshu 2:cffa347bb943 61 void UI::printloop() {
narshu 2:cffa347bb943 62
narshu 7:f9c59a3e4155 63 OLED4 = !OLED4;
narshu 7:f9c59a3e4155 64 Thread::wait(1500);
narshu 7:f9c59a3e4155 65
narshu 2:cffa347bb943 66 char* sync = "ABCD";
narshu 6:324946320c6d 67 std::cout.write(sync, 4);
narshu 7:f9c59a3e4155 68 std::cout.flush();
narshu 7:f9c59a3e4155 69 //std::cout << std::endl;
narshu 7:f9c59a3e4155 70 //printf("\r\n");
narshu 7:f9c59a3e4155 71
narshu 7:f9c59a3e4155 72 OLED4 = !OLED4;
narshu 2:cffa347bb943 73
narshu 2:cffa347bb943 74 while (1) {
narshu 2:cffa347bb943 75
narshu 6:324946320c6d 76 //send packets
narshu 6:324946320c6d 77 for (int id = 0; id < NUMIDS; id++) {
narshu 6:324946320c6d 78 if (newdataflags & (1<<id)) {
narshu 6:324946320c6d 79 std::cout.put(id);
narshu 6:324946320c6d 80 std::cout.write((char*)buffarr[id], 4*idlist[id]);
narshu 6:324946320c6d 81 newdataflags &= ~(1<<id);
narshu 2:cffa347bb943 82 }
narshu 2:cffa347bb943 83 }
narshu 2:cffa347bb943 84
narshu 7:f9c59a3e4155 85 //std::cout.flush();
narshu 2:cffa347bb943 86 Thread::wait(200);
narshu 2:cffa347bb943 87 }
narshu 2:cffa347bb943 88
narshu 2:cffa347bb943 89 }
narshu 2:cffa347bb943 90