yet another 18B20 Temperature sensor. variable number of sensors working in parasite mode, serial 16x2 display with diagnostic output and post to a rest web service
Dependencies: EthernetInterface HTTPClient NTPClient mbed-rtos mbed
sparkfun.cpp@1:9e88b2508768, 2013-01-03 (annotated)
- Committer:
- wkinkeldei
- Date:
- Thu Jan 03 18:50:43 2013 +0000
- Revision:
- 1:9e88b2508768
- Parent:
- 0:53f05303850a
added switch sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wkinkeldei | 0:53f05303850a | 1 | #include "sparkfun.h" |
wkinkeldei | 0:53f05303850a | 2 | #include "rtos.h" |
wkinkeldei | 0:53f05303850a | 3 | |
wkinkeldei | 0:53f05303850a | 4 | /* |
wkinkeldei | 0:53f05303850a | 5 | 1234567890ABCDEF |
wkinkeldei | 0:53f05303850a | 6 | [Buero 52°C] |
wkinkeldei | 0:53f05303850a | 7 | [T26> P N x 11:42] |
wkinkeldei | 0:53f05303850a | 8 | ^ ^ ^ ^ ^ ^ |
wkinkeldei | 0:53f05303850a | 9 | | | | | | | |
wkinkeldei | 0:53f05303850a | 10 | | | | | | | |
wkinkeldei | 0:53f05303850a | 11 | | | | | | +-- 27: Uhrzeit "hh:mm" / Datum "Mar03" / Uptime " 42d" |
wkinkeldei | 0:53f05303850a | 12 | | | | | | |
wkinkeldei | 0:53f05303850a | 13 | | | | | +-- 25: Reserve |
wkinkeldei | 0:53f05303850a | 14 | | | | | |
wkinkeldei | 0:53f05303850a | 15 | | | | +-- 23: NTP Status: t=lesen, T=ok, ?=error |
wkinkeldei | 0:53f05303850a | 16 | | | | |
wkinkeldei | 0:53f05303850a | 17 | | | +-- 21: Netz: P)ost O)k E)rror [1-9] = in x Minuten gehts los |
wkinkeldei | 0:53f05303850a | 18 | | | |
wkinkeldei | 0:53f05303850a | 19 | | +-- 19: < senden, > lesen, = fertig, ? fehler |
wkinkeldei | 0:53f05303850a | 20 | | |
wkinkeldei | 0:53f05303850a | 21 | +-- 16: gerade/zuletzt gemessener Sensor |
wkinkeldei | 0:53f05303850a | 22 | |
wkinkeldei | 0:53f05303850a | 23 | */ |
wkinkeldei | 0:53f05303850a | 24 | |
wkinkeldei | 0:53f05303850a | 25 | SparkFun::SparkFun(PinName tx) : Serial(tx, NC) { |
wkinkeldei | 0:53f05303850a | 26 | baud(9600); |
wkinkeldei | 0:53f05303850a | 27 | } |
wkinkeldei | 0:53f05303850a | 28 | |
wkinkeldei | 0:53f05303850a | 29 | void SparkFun::clear(void) { |
wkinkeldei | 0:53f05303850a | 30 | control_sequence(0x01); |
wkinkeldei | 0:53f05303850a | 31 | } |
wkinkeldei | 0:53f05303850a | 32 | |
wkinkeldei | 0:53f05303850a | 33 | void SparkFun::set_cursor_position(int pos) { |
wkinkeldei | 0:53f05303850a | 34 | if (pos >= 16) { |
wkinkeldei | 0:53f05303850a | 35 | pos = 64 + pos - 16; |
wkinkeldei | 0:53f05303850a | 36 | } |
wkinkeldei | 0:53f05303850a | 37 | control_sequence(0x80 + pos); |
wkinkeldei | 0:53f05303850a | 38 | } |
wkinkeldei | 0:53f05303850a | 39 | |
wkinkeldei | 0:53f05303850a | 40 | void SparkFun::control_sequence(char c) { |
wkinkeldei | 0:53f05303850a | 41 | putc(0xfe); |
wkinkeldei | 0:53f05303850a | 42 | putc(c); |
wkinkeldei | 0:53f05303850a | 43 | } |
wkinkeldei | 0:53f05303850a | 44 | |
wkinkeldei | 0:53f05303850a | 45 | void SparkFun::print_init_message(void) { |
wkinkeldei | 0:53f05303850a | 46 | clear(); |
wkinkeldei | 0:53f05303850a | 47 | |
wkinkeldei | 0:53f05303850a | 48 | set_cursor_position(0); |
wkinkeldei | 0:53f05303850a | 49 | puts("TempSensor"); |
wkinkeldei | 0:53f05303850a | 50 | |
wkinkeldei | 0:53f05303850a | 51 | // will get overridden very soon. |
wkinkeldei | 0:53f05303850a | 52 | // set_cursor_position(16); |
wkinkeldei | 0:53f05303850a | 53 | // puts("init"); |
wkinkeldei | 0:53f05303850a | 54 | } |
wkinkeldei | 0:53f05303850a | 55 | |
wkinkeldei | 0:53f05303850a | 56 | void SparkFun::show_sensor_measure(char *name, char *measure) { |
wkinkeldei | 0:53f05303850a | 57 | Thread::wait(50); // time for 48 characters. |
wkinkeldei | 0:53f05303850a | 58 | set_cursor_position(0); |
wkinkeldei | 0:53f05303850a | 59 | printf("%-12s%4s", name, measure); |
wkinkeldei | 0:53f05303850a | 60 | } |
wkinkeldei | 0:53f05303850a | 61 | |
wkinkeldei | 0:53f05303850a | 62 | void SparkFun::clear_current_sensor(void) { |
wkinkeldei | 0:53f05303850a | 63 | Thread::wait(50); // time for 48 characters. |
wkinkeldei | 0:53f05303850a | 64 | set_cursor_position(16); |
wkinkeldei | 0:53f05303850a | 65 | puts(" "); |
wkinkeldei | 0:53f05303850a | 66 | } |
wkinkeldei | 0:53f05303850a | 67 | |
wkinkeldei | 0:53f05303850a | 68 | void SparkFun::show_current_sensor(char kind, int nr, char status) { |
wkinkeldei | 0:53f05303850a | 69 | Thread::wait(50); // time for 48 characters. |
wkinkeldei | 0:53f05303850a | 70 | set_cursor_position(16); |
wkinkeldei | 0:53f05303850a | 71 | printf("%c%02d%c", kind, nr, status); |
wkinkeldei | 0:53f05303850a | 72 | } |
wkinkeldei | 0:53f05303850a | 73 | |
wkinkeldei | 0:53f05303850a | 74 | void SparkFun::show_current_status(char status) { |
wkinkeldei | 0:53f05303850a | 75 | Thread::wait(50); // time for 48 characters. |
wkinkeldei | 0:53f05303850a | 76 | set_cursor_position(19); |
wkinkeldei | 0:53f05303850a | 77 | putc(status); |
wkinkeldei | 0:53f05303850a | 78 | } |
wkinkeldei | 0:53f05303850a | 79 | |
wkinkeldei | 0:53f05303850a | 80 | void SparkFun::show_network_status(char status) { |
wkinkeldei | 0:53f05303850a | 81 | Thread::wait(50); // time for 48 characters. |
wkinkeldei | 0:53f05303850a | 82 | set_cursor_position(21); |
wkinkeldei | 0:53f05303850a | 83 | putc(status); |
wkinkeldei | 0:53f05303850a | 84 | } |
wkinkeldei | 0:53f05303850a | 85 | |
wkinkeldei | 0:53f05303850a | 86 | void SparkFun::show_ntp_status(char status) { |
wkinkeldei | 0:53f05303850a | 87 | Thread::wait(50); // time for 48 characters. |
wkinkeldei | 0:53f05303850a | 88 | set_cursor_position(23); |
wkinkeldei | 0:53f05303850a | 89 | putc(status); |
wkinkeldei | 0:53f05303850a | 90 | } |
wkinkeldei | 0:53f05303850a | 91 | |
wkinkeldei | 0:53f05303850a | 92 | void SparkFun::show_spare_status(char status) { |
wkinkeldei | 0:53f05303850a | 93 | Thread::wait(50); // time for 48 characters. |
wkinkeldei | 0:53f05303850a | 94 | set_cursor_position(25); |
wkinkeldei | 0:53f05303850a | 95 | putc(status); |
wkinkeldei | 0:53f05303850a | 96 | } |
wkinkeldei | 0:53f05303850a | 97 | |
wkinkeldei | 0:53f05303850a | 98 | void SparkFun::show_time_text(char *text) { |
wkinkeldei | 0:53f05303850a | 99 | Thread::wait(50); // time for 48 characters. |
wkinkeldei | 0:53f05303850a | 100 | set_cursor_position(27); |
wkinkeldei | 0:53f05303850a | 101 | printf("%-5s", text); |
wkinkeldei | 0:53f05303850a | 102 | } |