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.
ui.cpp
00001 00002 #include "ui.h" 00003 #include <iostream> 00004 #include "system.h" 00005 00006 UI::UI() : 00007 tUI(printtw,this,osPriorityNormal,2048) { 00008 newdataflags = 0; 00009 for (int i = 0; i < NUMIDS; i++) { 00010 idlist[i] = 0; 00011 buffarr[i] = 0; 00012 } 00013 00014 } 00015 00016 bool UI::regid(char id, unsigned int length) { 00017 00018 //check if the id is already taken 00019 if (id < NUMIDS && !idlist[id]) { 00020 idlist[id] = length; 00021 buffarr[id] = new float[length]; 00022 return true; 00023 } else 00024 return false; 00025 } 00026 00027 bool UI::updateval(char id, float* buffer, unsigned int length) { 00028 00029 //check if the id is registered, and has buffer of correct length 00030 if (id < NUMIDS && idlist[id] == length && buffarr[id] && !(newdataflags & (1<<id))) { 00031 for (int i = 0; i < length; i++) 00032 buffarr[id][i] = buffer[i]; 00033 newdataflags |= (1<<id); 00034 return true; 00035 } else{ 00036 return false; 00037 } 00038 } 00039 00040 bool UI::updateval(char id, float value) { 00041 00042 //check if the id is registered, and the old value has been written 00043 if (id < NUMIDS && idlist[id] == 1 && buffarr[id] && !(newdataflags & (1<<id))) { 00044 buffarr[id][0] = value; 00045 newdataflags |= (1<<id); 00046 return true; 00047 } else 00048 return false; 00049 00050 } 00051 00052 bool UI::unregid(char id) { 00053 if (id < NUMIDS) { 00054 idlist[id] = 0; 00055 if (buffarr[id]) 00056 delete buffarr[id]; 00057 return true; 00058 } else 00059 return false; 00060 } 00061 00062 void UI::printloop() { 00063 00064 #ifdef UION 00065 Thread::wait(3500); 00066 #else 00067 Thread::wait(osWaitForever); 00068 #endif 00069 00070 char* sync = "ABCD"; 00071 std::cout.write(sync, 4); 00072 //std::cout.flush(); 00073 std::cout << std::endl; 00074 //printf("\r\n"); 00075 00076 while (1) { 00077 00078 OLED3 = !OLED3; 00079 00080 //send number of packets 00081 char numtosend = 0; 00082 for (int id = 0; id < NUMIDS; id++) 00083 if (newdataflags & (1<<id)) 00084 numtosend++; 00085 00086 std::cout.put(numtosend); 00087 00088 //send packets 00089 for (char id = 0; id < NUMIDS; id++) { 00090 if (newdataflags & (1<<id)) { 00091 std::cout.put(id); 00092 std::cout.write((char*)buffarr[id], idlist[id] * sizeof(float)); 00093 newdataflags &= ~(1<<id); 00094 } 00095 } 00096 00097 std::cout << std::endl; 00098 //std::cout.flush(); 00099 Thread::wait(200); 00100 } 00101 00102 } 00103
Generated on Tue Jul 12 2022 19:50:03 by
1.7.2