first compiled version
Dependencies: mbed-rtos mbed C12832_lcd LM75B
main.cpp@3:0945093f48ec, 2014-03-04 (annotated)
- Committer:
- nleoni
- Date:
- Tue Mar 04 08:48:41 2014 +0000
- Revision:
- 3:0945093f48ec
- Parent:
- 1:83bc9f91d154
- Child:
- 4:6c17983d6192
LCD working with fortune cookie and pot display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nleoni | 3:0945093f48ec | 1 | //Rob I updated the LCD update and read pot thread and they are working |
nleoni | 3:0945093f48ec | 2 | //One key issues was adding timeout for the put and get methods of the queue |
nleoni | 3:0945093f48ec | 3 | //Maybe you can work on the TOD thread and MUTEX (you'll need to add it to the |
nleoni | 3:0945093f48ec | 4 | //LCD thread and I will finish the scan thread, sounds like Plan?? :-) |
nleoni | 3:0945093f48ec | 5 | //In the end I had to add the memory pool combined with the queue as otherwise |
nleoni | 3:0945093f48ec | 6 | //the queues just keep pointers to data and being that the putting and getting of |
nleoni | 3:0945093f48ec | 7 | //the pot values in the queue is asynchronous you need a buffer to keep the values |
nleoni | 3:0945093f48ec | 8 | //and this is provided by the MemoryPool. |
nleoni | 3:0945093f48ec | 9 | |
robertwharrell | 1:83bc9f91d154 | 10 | |
nleoni | 0:7ae4f23f84a3 | 11 | #include "mbed.h" |
nleoni | 0:7ae4f23f84a3 | 12 | #include "rtos.h" |
nleoni | 3:0945093f48ec | 13 | #include "C12832_lcd.h" |
nleoni | 3:0945093f48ec | 14 | #include <string> |
nleoni | 3:0945093f48ec | 15 | |
nleoni | 3:0945093f48ec | 16 | #define BUFFER 17 |
nleoni | 3:0945093f48ec | 17 | #define COOKIEQUEUE 30 |
nleoni | 3:0945093f48ec | 18 | |
nleoni | 3:0945093f48ec | 19 | C12832_LCD lcd; |
nleoni | 3:0945093f48ec | 20 | Serial pc(USBTX, USBRX); // tx, rx |
nleoni | 0:7ae4f23f84a3 | 21 | |
nleoni | 0:7ae4f23f84a3 | 22 | AnalogIn pot1(p19); |
nleoni | 3:0945093f48ec | 23 | MemoryPool<float, 10> potReadingBuffer; |
nleoni | 0:7ae4f23f84a3 | 24 | Queue<float,10> potReadingQueue; |
nleoni | 0:7ae4f23f84a3 | 25 | |
nleoni | 3:0945093f48ec | 26 | MemoryPool<char[BUFFER], COOKIEQUEUE> cookieReadingBuffer; |
nleoni | 3:0945093f48ec | 27 | Queue<char[BUFFER],COOKIEQUEUE> cookieReadingQueue; |
nleoni | 3:0945093f48ec | 28 | |
nleoni | 0:7ae4f23f84a3 | 29 | void lcdUpdate(void const*){ |
nleoni | 0:7ae4f23f84a3 | 30 | while(1){ |
nleoni | 3:0945093f48ec | 31 | osEvent evtPot = potReadingQueue.get(1200); |
nleoni | 3:0945093f48ec | 32 | if (evtPot.status == osEventMessage) { |
nleoni | 3:0945093f48ec | 33 | float *queuePot = (float*)evtPot.value.p; |
nleoni | 3:0945093f48ec | 34 | lcd.locate(0,3); |
nleoni | 3:0945093f48ec | 35 | lcd.printf("Voltage: %.2f V", *queuePot); |
nleoni | 3:0945093f48ec | 36 | potReadingBuffer.free(queuePot); |
nleoni | 0:7ae4f23f84a3 | 37 | } |
nleoni | 3:0945093f48ec | 38 | osEvent evtCookie = cookieReadingQueue.get(1200); |
nleoni | 3:0945093f48ec | 39 | if (evtCookie.status == osEventMessage) { |
nleoni | 3:0945093f48ec | 40 | char (*queueCookie)[BUFFER] = (char (*)[BUFFER])evtCookie.value.p; |
nleoni | 3:0945093f48ec | 41 | lcd.locate(0,15); |
nleoni | 3:0945093f48ec | 42 | string str(*queueCookie); |
nleoni | 3:0945093f48ec | 43 | lcd.printf("F.Cookie: %s", str); |
nleoni | 3:0945093f48ec | 44 | cookieReadingBuffer.free(queueCookie); |
nleoni | 3:0945093f48ec | 45 | } |
nleoni | 3:0945093f48ec | 46 | Thread::wait(1000); |
nleoni | 0:7ae4f23f84a3 | 47 | } |
nleoni | 0:7ae4f23f84a3 | 48 | } |
nleoni | 0:7ae4f23f84a3 | 49 | |
nleoni | 0:7ae4f23f84a3 | 50 | void readPOT(void const*){ |
nleoni | 0:7ae4f23f84a3 | 51 | while(1){ |
nleoni | 3:0945093f48ec | 52 | float *queue = potReadingBuffer.alloc(); |
nleoni | 0:7ae4f23f84a3 | 53 | *queue = pot1; |
nleoni | 3:0945093f48ec | 54 | potReadingQueue.put(queue,1200); |
nleoni | 0:7ae4f23f84a3 | 55 | |
nleoni | 0:7ae4f23f84a3 | 56 | Thread::wait(10000); |
nleoni | 0:7ae4f23f84a3 | 57 | } |
nleoni | 0:7ae4f23f84a3 | 58 | |
nleoni | 0:7ae4f23f84a3 | 59 | } |
nleoni | 0:7ae4f23f84a3 | 60 | |
nleoni | 3:0945093f48ec | 61 | |
nleoni | 3:0945093f48ec | 62 | |
nleoni | 0:7ae4f23f84a3 | 63 | void readTemp(void const*){ |
nleoni | 0:7ae4f23f84a3 | 64 | |
nleoni | 0:7ae4f23f84a3 | 65 | } |
nleoni | 0:7ae4f23f84a3 | 66 | |
nleoni | 3:0945093f48ec | 67 | void readCookie(void const*){ |
nleoni | 3:0945093f48ec | 68 | pc.printf(">Enter your fortune cookie\n>"); |
nleoni | 3:0945093f48ec | 69 | char (*ptrBuffer)[BUFFER] = cookieReadingBuffer.alloc(); |
nleoni | 3:0945093f48ec | 70 | char *ptrChar; |
nleoni | 3:0945093f48ec | 71 | ptrChar=*ptrBuffer; |
nleoni | 3:0945093f48ec | 72 | while(1){ |
nleoni | 3:0945093f48ec | 73 | if(pc.readable()){ |
nleoni | 3:0945093f48ec | 74 | *ptrChar=pc.getc(); |
nleoni | 3:0945093f48ec | 75 | pc.putc(*ptrChar); |
nleoni | 3:0945093f48ec | 76 | if((*ptrChar=='\n') || ((ptrChar-*ptrBuffer)>=(BUFFER-1)) ){ |
nleoni | 3:0945093f48ec | 77 | if((ptrChar-*ptrBuffer)>=(BUFFER-1)) *++ptrChar='\n'; |
nleoni | 3:0945093f48ec | 78 | while((ptrChar-*ptrBuffer)<=(BUFFER-1)){ |
nleoni | 3:0945093f48ec | 79 | *ptrChar++=' '; |
nleoni | 3:0945093f48ec | 80 | } |
nleoni | 3:0945093f48ec | 81 | *ptrChar='\0'; |
nleoni | 3:0945093f48ec | 82 | cookieReadingQueue.put(ptrBuffer,500); |
nleoni | 3:0945093f48ec | 83 | pc.printf(">Enter your fortune cookie\n>"); |
nleoni | 3:0945093f48ec | 84 | ptrChar=*ptrBuffer; |
nleoni | 3:0945093f48ec | 85 | } else { |
nleoni | 3:0945093f48ec | 86 | ptrChar++; |
nleoni | 3:0945093f48ec | 87 | } |
nleoni | 3:0945093f48ec | 88 | } |
nleoni | 3:0945093f48ec | 89 | Thread::wait(10); |
nleoni | 3:0945093f48ec | 90 | } |
nleoni | 0:7ae4f23f84a3 | 91 | } |
nleoni | 0:7ae4f23f84a3 | 92 | |
nleoni | 0:7ae4f23f84a3 | 93 | DigitalOut myled(LED1); |
nleoni | 0:7ae4f23f84a3 | 94 | |
nleoni | 0:7ae4f23f84a3 | 95 | int main() { |
nleoni | 3:0945093f48ec | 96 | lcd.cls(); |
nleoni | 3:0945093f48ec | 97 | |
nleoni | 0:7ae4f23f84a3 | 98 | Thread threadLCD(lcdUpdate); |
nleoni | 0:7ae4f23f84a3 | 99 | Thread threadPOT(readPOT); |
nleoni | 0:7ae4f23f84a3 | 100 | Thread threadTemp(readTemp); |
nleoni | 3:0945093f48ec | 101 | Thread threadCookie(readCookie); |
nleoni | 0:7ae4f23f84a3 | 102 | |
nleoni | 0:7ae4f23f84a3 | 103 | while(1) { |
nleoni | 3:0945093f48ec | 104 | Thread::wait(250); |
nleoni | 3:0945093f48ec | 105 | |
nleoni | 0:7ae4f23f84a3 | 106 | } |
nleoni | 0:7ae4f23f84a3 | 107 | } |