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.
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
Libs/Temperature/Temperature.cpp@30:91af74a299e1, 2014-11-13 (annotated)
- Committer:
- pspatel321
- Date:
- Thu Nov 13 10:53:10 2014 +0000
- Revision:
- 30:91af74a299e1
Parth's edits for the week.; DC-DC completed and fixed, IMD updated, LatchMonitor and Temperature added. Serial dashboard updated. File structure changed Everything tested. Compiles and runs.; Still need to write CAN in/out interface.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pspatel321 | 30:91af74a299e1 | 1 | #include "Temperature.h" |
| pspatel321 | 30:91af74a299e1 | 2 | |
| pspatel321 | 30:91af74a299e1 | 3 | float NXFT15XH103_TABLE_IN[] = { 0.050512723, 0.056425741, 0.06305631, 0.07054559, 0.079189687, 0.088921283, 0.100071994, 0, 0.127018769, 0.143322197, 0.161706765, 0.182539034, 0.205908044, 0.232186732, 0.261393013, 0.293785311, 0.329354168, 0.368048534, 0.409646378, 0.453820525, 0.5, 0.547490837, 0.595469256, 0.642984648, 0.689103062, 0.732941648, 0.77373518, 0.810924767, 0.844154225, 0.873281379, 0.898354357, 0.919578592, 0.937262775, 0.951781202 }; |
| pspatel321 | 30:91af74a299e1 | 4 | float NXFT15XH103_TABLE_OUT[] = { 125, 120, 115, 110, 105, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15, -20, -25, -30, -35, -40 }; |
| pspatel321 | 30:91af74a299e1 | 5 | |
| pspatel321 | 30:91af74a299e1 | 6 | LOOKUP_TABLE_T NXFT15XH103_TABLE = { |
| pspatel321 | 30:91af74a299e1 | 7 | NXFT15XH103_TABLE_IN, |
| pspatel321 | 30:91af74a299e1 | 8 | NXFT15XH103_TABLE_OUT, |
| pspatel321 | 30:91af74a299e1 | 9 | sizeof(NXFT15XH103_TABLE)/sizeof(float) |
| pspatel321 | 30:91af74a299e1 | 10 | }; |
| pspatel321 | 30:91af74a299e1 | 11 | |
| pspatel321 | 30:91af74a299e1 | 12 | Temperature::Temperature(LOOKUP_TABLE_T *_table, PinName _pin) : pin(_pin) { |
| pspatel321 | 30:91af74a299e1 | 13 | table = _table; |
| pspatel321 | 30:91af74a299e1 | 14 | } |
| pspatel321 | 30:91af74a299e1 | 15 | float Temperature::convert(float reading) { |
| pspatel321 | 30:91af74a299e1 | 16 | float in = reading; |
| pspatel321 | 30:91af74a299e1 | 17 | if (in < table->input[0]) return INFINITY; // Out of range of the table |
| pspatel321 | 30:91af74a299e1 | 18 | if (in > table->input[table->numEntries-1]) return -INFINITY; // Out of range of the table |
| pspatel321 | 30:91af74a299e1 | 19 | int lowerIndex = 0; |
| pspatel321 | 30:91af74a299e1 | 20 | int upperIndex = table->numEntries-1; |
| pspatel321 | 30:91af74a299e1 | 21 | for (int i = 0; i < table->numEntries; i++) { // Converge on the entries that surround the input |
| pspatel321 | 30:91af74a299e1 | 22 | if (in >= table->input[lowerIndex]) { lowerIndex = i; } |
| pspatel321 | 30:91af74a299e1 | 23 | if (in <= table->input[upperIndex]) { upperIndex = table->numEntries-1 - i; } |
| pspatel321 | 30:91af74a299e1 | 24 | } |
| pspatel321 | 30:91af74a299e1 | 25 | // Interpolate and return |
| pspatel321 | 30:91af74a299e1 | 26 | return table->output[lowerIndex] + (table->output[upperIndex] - table->output[lowerIndex]) * ((in - table->input[lowerIndex]) / (table->input[upperIndex] - table->input[lowerIndex])); |
| pspatel321 | 30:91af74a299e1 | 27 | } |
| pspatel321 | 30:91af74a299e1 | 28 | float Temperature::readRaw() { |
| pspatel321 | 30:91af74a299e1 | 29 | return pin.read(); |
| pspatel321 | 30:91af74a299e1 | 30 | } |
| pspatel321 | 30:91af74a299e1 | 31 | float Temperature::read() { |
| pspatel321 | 30:91af74a299e1 | 32 | return convert(pin.read()); |
| pspatel321 | 30:91af74a299e1 | 33 | } |
