Allows for a 90 frame animated gauge to be display on the uLCD
uLCD_gauges.cpp@1:5666427710f2, 2015-03-13 (annotated)
- Committer:
- Striker121
- Date:
- Fri Mar 13 14:05:32 2015 +0000
- Revision:
- 1:5666427710f2
- Parent:
- 0:9101c0ce36a1
- Child:
- 2:38006c26dda5
Added command for custom gauge addresses
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Striker121 | 0:9101c0ce36a1 | 1 | #include "uLCD_gauges.h" |
Striker121 | 0:9101c0ce36a1 | 2 | #include "mbed.h" |
Striker121 | 0:9101c0ce36a1 | 3 | |
Striker121 | 0:9101c0ce36a1 | 4 | uLCD_gauges::uLCD_gauges(uLCD_4DGL& screen, float min, float max){ |
Striker121 | 0:9101c0ce36a1 | 5 | uLCD = &screen; |
Striker121 | 0:9101c0ce36a1 | 6 | minVal = min; |
Striker121 | 0:9101c0ce36a1 | 7 | maxVal = max; |
Striker121 | 0:9101c0ce36a1 | 8 | mapOffset = 1; |
Striker121 | 0:9101c0ce36a1 | 9 | mapSlope = (90 - 1) / (maxVal - minVal); |
Striker121 | 1:5666427710f2 | 10 | memHigh = 0; |
Striker121 | 1:5666427710f2 | 11 | memLow = 0; |
Striker121 | 0:9101c0ce36a1 | 12 | } |
Striker121 | 0:9101c0ce36a1 | 13 | |
Striker121 | 1:5666427710f2 | 14 | uLCD_gauges::uLCD_gauges(uLCD_4DGL& screen, float min, float max, long memoryAddressHigh, long memoryAddressLow){ |
Striker121 | 1:5666427710f2 | 15 | uLCD = &screen; |
Striker121 | 1:5666427710f2 | 16 | minVal = min; |
Striker121 | 1:5666427710f2 | 17 | maxVal = max; |
Striker121 | 1:5666427710f2 | 18 | mapOffset = 1; |
Striker121 | 1:5666427710f2 | 19 | mapSlope = (90 - 1) / (maxVal - minVal); |
Striker121 | 1:5666427710f2 | 20 | memHigh = memoryAddressHigh; |
Striker121 | 1:5666427710f2 | 21 | memLow = memoryAddressLow; |
Striker121 | 1:5666427710f2 | 22 | } |
Striker121 | 0:9101c0ce36a1 | 23 | void uLCD_gauges::start() { |
Striker121 | 1:5666427710f2 | 24 | uLCD->baudrate(3000000); |
Striker121 | 0:9101c0ce36a1 | 25 | uLCD->cls(); |
Striker121 | 0:9101c0ce36a1 | 26 | uLCD->media_init(); |
Striker121 | 0:9101c0ce36a1 | 27 | uLCD->set_sector_address(0,0); |
Striker121 | 0:9101c0ce36a1 | 28 | } |
Striker121 | 0:9101c0ce36a1 | 29 | |
Striker121 | 0:9101c0ce36a1 | 30 | void uLCD_gauges::update(float value){ |
Striker121 | 0:9101c0ce36a1 | 31 | //Map value in range minVal to maxVal onto 1 to 99 |
Striker121 | 0:9101c0ce36a1 | 32 | int mappedValue = int(mapOffset + mapSlope*(value - minVal)); |
Striker121 | 0:9101c0ce36a1 | 33 | uLCD->display_frame(0,0, mappedValue); |
Striker121 | 0:9101c0ce36a1 | 34 | } |