first compiled version
Dependencies: mbed-rtos mbed C12832_lcd LM75B
main.cpp@2:43cd60e0e32f, 2014-02-28 (annotated)
- Committer:
- robertwharrell
- Date:
- Fri Feb 28 22:05:13 2014 +0000
- Revision:
- 2:43cd60e0e32f
- Parent:
- 1:83bc9f91d154
- Child:
- 4:6c17983d6192
Added function descriptions from the lab and generic prints to terminal for threads
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robertwharrell | 1:83bc9f91d154 | 1 | //Rob in the house |
robertwharrell | 1:83bc9f91d154 | 2 | |
nleoni | 0:7ae4f23f84a3 | 3 | #include "mbed.h" |
nleoni | 0:7ae4f23f84a3 | 4 | #include "rtos.h" |
nleoni | 0:7ae4f23f84a3 | 5 | |
robertwharrell | 2:43cd60e0e32f | 6 | Serial pc(USBTX, USBRX); //To differentiate from LCD functions |
robertwharrell | 2:43cd60e0e32f | 7 | |
nleoni | 0:7ae4f23f84a3 | 8 | AnalogIn pot1(p19); |
nleoni | 0:7ae4f23f84a3 | 9 | Queue<float,10> potReadingQueue; |
nleoni | 0:7ae4f23f84a3 | 10 | |
robertwharrell | 2:43cd60e0e32f | 11 | |
robertwharrell | 2:43cd60e0e32f | 12 | /****************************************************************** |
robertwharrell | 2:43cd60e0e32f | 13 | * |
robertwharrell | 2:43cd60e0e32f | 14 | *An LCD thread that updates the LCD based on information |
robertwharrell | 2:43cd60e0e32f | 15 | *received from other threads via IPC |
robertwharrell | 2:43cd60e0e32f | 16 | * |
robertwharrell | 2:43cd60e0e32f | 17 | *Uses the top 3 lines of the LCD to reflect the pot, the |
robertwharrell | 2:43cd60e0e32f | 18 | *temperature, and the cookie. This task must use IPC (with |
robertwharrell | 2:43cd60e0e32f | 19 | *timeout) methods to get data from each of the previous threads |
robertwharrell | 2:43cd60e0e32f | 20 | * |
robertwharrell | 2:43cd60e0e32f | 21 | *******************************************************************/ |
nleoni | 0:7ae4f23f84a3 | 22 | void lcdUpdate(void const*){ |
nleoni | 0:7ae4f23f84a3 | 23 | while(1){ |
nleoni | 0:7ae4f23f84a3 | 24 | osEvent evt = potReadingQueue.get(); |
nleoni | 0:7ae4f23f84a3 | 25 | if (evt.status == osEventMail) { |
nleoni | 0:7ae4f23f84a3 | 26 | float *queue = (float*)evt.value.p; |
robertwharrell | 2:43cd60e0e32f | 27 | pc.printf("\nVoltage: %.2f V\n\r" , *queue); |
robertwharrell | 2:43cd60e0e32f | 28 | |
robertwharrell | 2:43cd60e0e32f | 29 | pc.printf("LCD updated"); |
nleoni | 0:7ae4f23f84a3 | 30 | Thread::wait(1000); |
nleoni | 0:7ae4f23f84a3 | 31 | } |
nleoni | 0:7ae4f23f84a3 | 32 | } |
nleoni | 0:7ae4f23f84a3 | 33 | } |
nleoni | 0:7ae4f23f84a3 | 34 | |
robertwharrell | 2:43cd60e0e32f | 35 | /****************************************************************** |
robertwharrell | 2:43cd60e0e32f | 36 | * |
robertwharrell | 2:43cd60e0e32f | 37 | *A POT thread that reads the pot value in a polling loop |
robertwharrell | 2:43cd60e0e32f | 38 | *every 10 seconds and sends value to LCD thread via IPC Queue |
robertwharrell | 2:43cd60e0e32f | 39 | * |
robertwharrell | 2:43cd60e0e32f | 40 | *******************************************************************/ |
nleoni | 0:7ae4f23f84a3 | 41 | void readPOT(void const*){ |
nleoni | 0:7ae4f23f84a3 | 42 | while(1){ |
nleoni | 0:7ae4f23f84a3 | 43 | float *queue; |
nleoni | 0:7ae4f23f84a3 | 44 | *queue = pot1; |
nleoni | 0:7ae4f23f84a3 | 45 | potReadingQueue.put(queue); |
robertwharrell | 2:43cd60e0e32f | 46 | pc.printf("POT read"); |
robertwharrell | 2:43cd60e0e32f | 47 | Thread::wait(10000); |
robertwharrell | 2:43cd60e0e32f | 48 | } |
robertwharrell | 2:43cd60e0e32f | 49 | |
robertwharrell | 2:43cd60e0e32f | 50 | } |
robertwharrell | 2:43cd60e0e32f | 51 | |
robertwharrell | 2:43cd60e0e32f | 52 | /****************************************************************** |
robertwharrell | 2:43cd60e0e32f | 53 | * |
robertwharrell | 2:43cd60e0e32f | 54 | *A TEMP thread that read the temperature every 60 seconds |
robertwharrell | 2:43cd60e0e32f | 55 | *and sends the value to the LCD task via IPC Queue |
robertwharrell | 2:43cd60e0e32f | 56 | * |
robertwharrell | 2:43cd60e0e32f | 57 | *******************************************************************/ |
robertwharrell | 2:43cd60e0e32f | 58 | void readTemp(void const*){ |
robertwharrell | 2:43cd60e0e32f | 59 | while(1){ |
robertwharrell | 2:43cd60e0e32f | 60 | pc.printf("TEMP read"); |
robertwharrell | 2:43cd60e0e32f | 61 | Thread::wait(60000); |
nleoni | 0:7ae4f23f84a3 | 62 | } |
nleoni | 0:7ae4f23f84a3 | 63 | |
nleoni | 0:7ae4f23f84a3 | 64 | } |
nleoni | 0:7ae4f23f84a3 | 65 | |
robertwharrell | 2:43cd60e0e32f | 66 | /****************************************************************** |
robertwharrell | 2:43cd60e0e32f | 67 | * |
robertwharrell | 2:43cd60e0e32f | 68 | *A SCANF thread that reads in a fortune cookie from user |
robertwharrell | 2:43cd60e0e32f | 69 | *and sends it to the LCD task via IPC Memory Pool |
robertwharrell | 2:43cd60e0e32f | 70 | * |
robertwharrell | 2:43cd60e0e32f | 71 | *******************************************************************/ |
robertwharrell | 2:43cd60e0e32f | 72 | void threadCookie(void const*){ |
robertwharrell | 2:43cd60e0e32f | 73 | //Checks often but low priority? |
robertwharrell | 2:43cd60e0e32f | 74 | while(1){ |
robertwharrell | 2:43cd60e0e32f | 75 | Thread::wait(1000); |
robertwharrell | 2:43cd60e0e32f | 76 | } |
nleoni | 0:7ae4f23f84a3 | 77 | } |
nleoni | 0:7ae4f23f84a3 | 78 | |
robertwharrell | 2:43cd60e0e32f | 79 | |
robertwharrell | 2:43cd60e0e32f | 80 | /****************************************************************** |
robertwharrell | 2:43cd60e0e32f | 81 | * |
robertwharrell | 2:43cd60e0e32f | 82 | *A TOD thread that updates the 4th line of the LCD with time |
robertwharrell | 2:43cd60e0e32f | 83 | *of day once a minute. It shares the LCD with the LCD thread |
robertwharrell | 2:43cd60e0e32f | 84 | *using mutual exclusion |
robertwharrell | 2:43cd60e0e32f | 85 | * |
robertwharrell | 2:43cd60e0e32f | 86 | *******************************************************************/ |
robertwharrell | 2:43cd60e0e32f | 87 | void threadTOD(void const*){ |
robertwharrell | 2:43cd60e0e32f | 88 | while(1){ |
robertwharrell | 2:43cd60e0e32f | 89 | pc.printf("TOD updated"); |
robertwharrell | 2:43cd60e0e32f | 90 | Thread::wait(60000); |
robertwharrell | 2:43cd60e0e32f | 91 | } |
nleoni | 0:7ae4f23f84a3 | 92 | } |
nleoni | 0:7ae4f23f84a3 | 93 | |
nleoni | 0:7ae4f23f84a3 | 94 | DigitalOut myled(LED1); |
nleoni | 0:7ae4f23f84a3 | 95 | |
nleoni | 0:7ae4f23f84a3 | 96 | int main() { |
nleoni | 0:7ae4f23f84a3 | 97 | Thread threadLCD(lcdUpdate); |
nleoni | 0:7ae4f23f84a3 | 98 | Thread threadPOT(readPOT); |
nleoni | 0:7ae4f23f84a3 | 99 | Thread threadTemp(readTemp); |
nleoni | 0:7ae4f23f84a3 | 100 | |
nleoni | 0:7ae4f23f84a3 | 101 | while(1) { |
nleoni | 0:7ae4f23f84a3 | 102 | } |
nleoni | 0:7ae4f23f84a3 | 103 | } |