Allows for a 90 frame animated gauge to be display on the uLCD
uLCD_gauges.cpp@3:eee40e4de1c4, 2015-03-13 (annotated)
- Committer:
- Striker121
- Date:
- Fri Mar 13 15:25:56 2015 +0000
- Revision:
- 3:eee40e4de1c4
- Parent:
- 2:38006c26dda5
- Child:
- 4:069b01d563a3
Doxygen comment changes
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 | 2:38006c26dda5 | 3 | |
Striker121 | 2:38006c26dda5 | 4 | /** |
Striker121 | 3:eee40e4de1c4 | 5 | * @file uLCD_gauges.cpp |
Striker121 | 3:eee40e4de1c4 | 6 | * @brief This cpp file defines all the functions for uLCD_gauges.h |
Striker121 | 3:eee40e4de1c4 | 7 | * @author Matthew Arceri and Harsha Nori |
Striker121 | 3:eee40e4de1c4 | 8 | * @date 3/13/2015 |
Striker121 | 3:eee40e4de1c4 | 9 | */ |
Striker121 | 3:eee40e4de1c4 | 10 | |
Striker121 | 3:eee40e4de1c4 | 11 | /** |
Striker121 | 2:38006c26dda5 | 12 | * Constructor for the uLCD_gauges class. Sets up the value mapping assuming the default gauge is used. |
Striker121 | 2:38006c26dda5 | 13 | * @author Matthew Arceri |
Striker121 | 2:38006c26dda5 | 14 | * @param screen The uLCD instance that is going to be used for the gauge |
Striker121 | 2:38006c26dda5 | 15 | * @param min The minimum value the gauge wil be updated with. Used for mapping. |
Striker121 | 2:38006c26dda5 | 16 | * @param max The maximum value the gauge wil be updated with. Used for mapping. |
Striker121 | 2:38006c26dda5 | 17 | * @date 3/13/2015 |
Striker121 | 2:38006c26dda5 | 18 | */ |
Striker121 | 0:9101c0ce36a1 | 19 | uLCD_gauges::uLCD_gauges(uLCD_4DGL& screen, float min, float max){ |
Striker121 | 0:9101c0ce36a1 | 20 | uLCD = &screen; |
Striker121 | 0:9101c0ce36a1 | 21 | minVal = min; |
Striker121 | 0:9101c0ce36a1 | 22 | maxVal = max; |
Striker121 | 0:9101c0ce36a1 | 23 | mapOffset = 1; |
Striker121 | 2:38006c26dda5 | 24 | highFrame = 90; |
Striker121 | 2:38006c26dda5 | 25 | mapSlope = (highFrame - mapOffset) / (maxVal - minVal); |
Striker121 | 1:5666427710f2 | 26 | memHigh = 0; |
Striker121 | 1:5666427710f2 | 27 | memLow = 0; |
Striker121 | 0:9101c0ce36a1 | 28 | } |
Striker121 | 2:38006c26dda5 | 29 | /** |
Striker121 | 2:38006c26dda5 | 30 | * Constructor for the uLCD_gauges class. Sets up the value mapping for custom gauges. |
Striker121 | 2:38006c26dda5 | 31 | * @author Matthew Arceri |
Striker121 | 2:38006c26dda5 | 32 | * @param screen The uLCD instance that is going to be used for the gauge |
Striker121 | 2:38006c26dda5 | 33 | * @param min The minimum value the gauge wil be updated with. Used for mapping. |
Striker121 | 2:38006c26dda5 | 34 | * @param max The maximum value the gauge wil be updated with. Used for mapping. |
Striker121 | 2:38006c26dda5 | 35 | * @param memoryAddressHigh The ending memory address of the animation that will be displayed as a gauge. |
Striker121 | 2:38006c26dda5 | 36 | * @param memoryAddressLow The starting memory address of the animation that will be displayed as a gauge. |
Striker121 | 2:38006c26dda5 | 37 | * @date 3/13/2015 |
Striker121 | 2:38006c26dda5 | 38 | */ |
Striker121 | 2:38006c26dda5 | 39 | uLCD_gauges::uLCD_gauges(uLCD_4DGL& screen, float min, float max, int lowF, int highF, long memoryAddressHigh, long memoryAddressLow){ |
Striker121 | 1:5666427710f2 | 40 | uLCD = &screen; |
Striker121 | 1:5666427710f2 | 41 | minVal = min; |
Striker121 | 1:5666427710f2 | 42 | maxVal = max; |
Striker121 | 2:38006c26dda5 | 43 | highFrame = highF; |
Striker121 | 2:38006c26dda5 | 44 | mapOffset = lowF; |
Striker121 | 2:38006c26dda5 | 45 | mapSlope = (highFrame - mapOffset) / (maxVal - minVal); |
Striker121 | 1:5666427710f2 | 46 | memHigh = memoryAddressHigh; |
Striker121 | 1:5666427710f2 | 47 | memLow = memoryAddressLow; |
Striker121 | 1:5666427710f2 | 48 | } |
Striker121 | 2:38006c26dda5 | 49 | |
Striker121 | 2:38006c26dda5 | 50 | /** |
Striker121 | 2:38006c26dda5 | 51 | * This method repares the uLCD for displaying the gauge. Must be called once after object instancing |
Striker121 | 2:38006c26dda5 | 52 | * @author Matthew Arceri |
Striker121 | 2:38006c26dda5 | 53 | * @date 3/13/15 |
Striker121 | 2:38006c26dda5 | 54 | */ |
Striker121 | 0:9101c0ce36a1 | 55 | void uLCD_gauges::start() { |
Striker121 | 1:5666427710f2 | 56 | uLCD->baudrate(3000000); |
Striker121 | 0:9101c0ce36a1 | 57 | uLCD->cls(); |
Striker121 | 0:9101c0ce36a1 | 58 | uLCD->media_init(); |
Striker121 | 0:9101c0ce36a1 | 59 | uLCD->set_sector_address(0,0); |
Striker121 | 0:9101c0ce36a1 | 60 | } |
Striker121 | 0:9101c0ce36a1 | 61 | |
Striker121 | 2:38006c26dda5 | 62 | /** |
Striker121 | 2:38006c26dda5 | 63 | * This method updates the gauge based on the new input value |
Striker121 | 2:38006c26dda5 | 64 | * @author Harsha Nori |
Striker121 | 2:38006c26dda5 | 65 | * @param value The value to be mapped onto the display |
Striker121 | 2:38006c26dda5 | 66 | * @date 3/13/15 |
Striker121 | 2:38006c26dda5 | 67 | */ |
Striker121 | 0:9101c0ce36a1 | 68 | void uLCD_gauges::update(float value){ |
Striker121 | 0:9101c0ce36a1 | 69 | //Map value in range minVal to maxVal onto 1 to 99 |
Striker121 | 0:9101c0ce36a1 | 70 | int mappedValue = int(mapOffset + mapSlope*(value - minVal)); |
Striker121 | 0:9101c0ce36a1 | 71 | uLCD->display_frame(0,0, mappedValue); |
Striker121 | 0:9101c0ce36a1 | 72 | } |