Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 50 | mjames | 1 | /* |
| 2 | * display.cpp |
||
| 3 | * |
||
| 4 | * Created on: 30 Nov 2020 |
||
| 5 | * Author: mike |
||
| 6 | */ |
||
| 7 | |||
| 8 | #include "main.h" |
||
| 9 | #include "display.h" |
||
| 10 | #include "switches.h" |
||
| 11 | #include "nvram.h" |
||
| 12 | #include <cstring> |
||
| 13 | #include "libOLED/stm32_halDisplay.H" |
||
| 14 | #include "libOLED/fontclass.H" |
||
| 15 | #include "libOLED/displayDial.H" |
||
| 16 | #include "libPlx/displayInfo.H" |
||
| 17 | #include "libOLED/ap_math.h" |
||
| 18 | |||
| 19 | #include "splash.H" |
||
| 20 | |||
| 21 | namespace |
||
| 22 | { |
||
| 23 | int const WIDTH = 128; |
||
| 24 | int const HEIGHT = 64; |
||
| 25 | int const DISPLAY_RAMWIDTH = 132; |
||
| 26 | } |
||
| 27 | |||
| 28 | uint8_t displayBuffer[2][dataSize (WIDTH, HEIGHT)]; |
||
| 29 | |||
| 30 | stm32_halDisplay_t displays[MAX_DISPLAYS] = |
||
| 31 | { stm32_halDisplay_t (WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer[0], |
||
| 32 | &hspi1, |
||
| 33 | SPI_CD_GPIO_Port, |
||
| 34 | SPI_CD_Pin, |
||
| 35 | SPI_RESET_GPIO_Port, |
||
| 36 | SPI_RESET_Pin, |
||
| 37 | SPI_NSS1_GPIO_Port, |
||
| 38 | SPI_NSS1_Pin), stm32_halDisplay_t (WIDTH, HEIGHT, |
||
| 39 | DISPLAY_RAMWIDTH, |
||
| 40 | displayBuffer[1], |
||
| 41 | &hspi1, |
||
| 42 | SPI_CD_GPIO_Port, |
||
| 43 | SPI_CD_Pin, |
||
| 44 | SPI_RESET_GPIO_Port, |
||
| 45 | SPI_RESET_Pin, |
||
| 46 | SPI_NSS2_GPIO_Port, |
||
| 47 | SPI_NSS2_Pin) }; |
||
| 48 | |||
| 49 | displayDial_t dials[MAX_DISPLAYS] = |
||
| 50 | { displayDial_t (displays[0], 64, 60, 60, 90), displayDial_t (displays[1], 64, |
||
| 51 | 60, 60, 90) }; |
||
| 52 | #if defined __cplusplus |
||
| 53 | extern "C" |
||
| 54 | { |
||
| 55 | #endif |
||
| 56 | static void |
||
| 57 | showMinMax (display_t &display, uint8_t dp_pos, int16_t int_min, |
||
| 58 | uint16_t int_max) |
||
| 59 | { |
||
| 60 | display.fontSigDigits (small_font, 0, 0, 0, dp_pos, int_min, WHITE); |
||
| 61 | display.gotoxy (0, 8); |
||
| 62 | |||
| 54 | mjames | 63 | display.printString (small_font, "Min", 3, WHITE); |
| 50 | mjames | 64 | |
| 65 | display.fontSigDigits (small_font, 120, 0, 1, dp_pos, int_max, WHITE); |
||
| 66 | display.gotoxy (110, 8); |
||
| 67 | display.printString (small_font, "Max", 3, WHITE); |
||
| 68 | } |
||
| 69 | |||
| 70 | void |
||
| 71 | cc_init () |
||
| 72 | { |
||
| 73 | for (auto i = 0; i < MAX_DISPLAYS; i++) |
||
| 74 | { |
||
| 75 | display_t &display = displays[i]; |
||
| 76 | if (i == 0) |
||
| 77 | display.reset (); |
||
| 78 | display.init (); |
||
| 79 | display.clearDisplay (); |
||
| 80 | displaySplash (display); |
||
| 81 | display.gotoxy (8, 32); |
||
| 82 | display.printString (large_font, i == 0 ? "1" : "2", 1, BLACK); |
||
| 83 | display.display (); |
||
| 84 | } |
||
| 85 | |||
| 86 | HAL_Delay (1000); |
||
| 87 | |||
| 88 | for (auto i = 0; i < MAX_DISPLAYS; i++) |
||
| 89 | { |
||
| 90 | display_t &display = displays[i]; |
||
| 91 | displayDial_t &dial = dials[i]; |
||
| 92 | display.clearDisplay (); |
||
| 54 | mjames | 93 | display.setPixelMode (WHITE); |
| 50 | mjames | 94 | dial.draw_scale (0, 10, 12, 1, 1); |
| 95 | dial.draw_limits (); |
||
| 96 | display.gotoxy (8, 32); |
||
| 97 | display.printString (large_font, "Display ", 8, WHITE); |
||
| 98 | display.printString (large_font, i == 0 ? "1" : "2", 1, BLACK); |
||
| 99 | showMinMax (display, 2, 123, 456); |
||
| 100 | |||
| 101 | display.display (); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | int |
||
| 106 | cc_display (int dialIndex, int itemIndex, int suppressIndex) |
||
| 107 | |||
| 108 | { |
||
| 109 | if (dialIndex < 0 && dialIndex > MAX_DISPLAYS) |
||
| 110 | return -1; |
||
| 111 | context_t &context = contexts[dialIndex]; |
||
| 112 | displayDial_t &dial = dials[dialIndex]; |
||
| 113 | stm32_halDisplay_t &display = displays[dialIndex]; |
||
| 114 | char buff[10]; |
||
| 115 | int i; |
||
| 116 | int rc; |
||
| 117 | |||
| 118 | // check for item suppression |
||
| 119 | if (itemIndex == suppressIndex) |
||
| 120 | { |
||
| 121 | context.dial1 = -1; |
||
| 122 | context.OldObservation = -1; |
||
| 123 | context.OldObservationIndex = -1; |
||
| 124 | |||
| 125 | display.clearDisplay (); |
||
| 126 | display.display (); |
||
| 127 | return -1; // we suppressed this display |
||
| 128 | } |
||
| 129 | |||
| 130 | // clear startup display off the screen |
||
| 131 | if (context.OldObservation == -1) |
||
| 132 | display.clearDisplay (); |
||
| 133 | |||
| 134 | int DataVal = ConvPLX (Data.Sensor[itemIndex].ReadingH, |
||
| 135 | Data.Sensor[itemIndex].ReadingL); // data reading |
||
| 136 | int Observation = ConvPLX (Data.Sensor[itemIndex].AddrH, |
||
| 137 | Data.Sensor[itemIndex].AddrL); |
||
| 138 | int ObservationIndex = ConvPLX (0, Data.Sensor[itemIndex].Instance); |
||
| 139 | // now to convert the readings and format strings |
||
| 140 | // find out limits |
||
| 141 | char *msg; |
||
| 142 | int len; |
||
| 143 | |||
| 144 | // if the user presses the dial then reset min/max to current value |
||
| 145 | if (push_pos[dialIndex] == 1) |
||
| 146 | { |
||
| 147 | Max[itemIndex] = DataVal; |
||
| 148 | Min[itemIndex] = DataVal; // 12 bit max value |
||
| 149 | } |
||
| 150 | |||
| 151 | if (Observation < PLX_MAX_OBS) |
||
| 152 | { |
||
| 153 | if (Observation != context.OldObservation |
||
| 154 | || ObservationIndex != context.OldObservationIndex) |
||
| 155 | { |
||
| 156 | |||
| 157 | context.dial_timer = DialTimeout; |
||
| 158 | |||
| 159 | context.dial1 = -1; |
||
| 160 | display.clearDisplay (); |
||
| 161 | dial.draw_scale (DisplayInfo[Observation].Low, |
||
| 162 | DisplayInfo[Observation].High, 12, 1, |
||
| 163 | DisplayInfo[Observation].TickScale); |
||
| 164 | |||
| 165 | dial.draw_limits (); |
||
| 166 | |||
| 167 | msg = DisplayInfo[Observation].name; |
||
| 168 | len = 7; |
||
| 169 | int len1 = ObservationIndex > 0 ? len - 1 : len; |
||
| 170 | for (i = 0; i < len1 && msg[i]; i++) |
||
| 171 | { |
||
| 172 | buff[i] = msg[i]; |
||
| 173 | } |
||
| 174 | if (ObservationIndex > 0 && i < len) |
||
| 175 | { |
||
| 176 | buff[i++] = ObservationIndex + '1'; |
||
| 177 | } |
||
| 178 | |||
| 179 | display.gotoxy (64 - i * 4, 48); |
||
| 180 | display.printString (large_font, buff, i, WHITE); |
||
| 181 | |||
| 182 | context.OldObservation = Observation; |
||
| 183 | context.OldObservationIndex = ObservationIndex; |
||
| 184 | |||
| 185 | display.display (); |
||
| 186 | |||
| 187 | } |
||
| 188 | else |
||
| 189 | { |
||
| 190 | // check for timer timeout on consistent timer |
||
| 191 | if (context.dial_timer) |
||
| 192 | { |
||
| 193 | context.dial_timer--; |
||
| 194 | |||
| 195 | if (context.dial_timer == 0) |
||
| 196 | { |
||
| 197 | uint16_t curr_val = dial_pos[dialIndex]; |
||
| 54 | mjames | 198 | if (curr_val >= 0) // do not write -1 as a setting. |
| 199 | { |
||
| 200 | uint32_t addr = (uint32_t) (&dial_nvram[dialIndex]); |
||
| 201 | WriteUint16NVRAM (addr, curr_val); |
||
| 202 | } |
||
| 50 | mjames | 203 | } |
| 204 | } |
||
| 205 | } |
||
| 206 | |||
| 207 | } |
||
| 208 | |||
| 209 | double max_rdg; |
||
| 210 | double min_rdg; |
||
| 211 | double cur_rdg; |
||
| 212 | int int_rdg; |
||
| 213 | int int_max; |
||
| 214 | int int_min; |
||
| 215 | |||
| 216 | max_rdg = ConveriMFDRaw2Data (Observation, DisplayInfo[Observation].Units, |
||
| 217 | Max[itemIndex]); |
||
| 218 | min_rdg = ConveriMFDRaw2Data (Observation, DisplayInfo[Observation].Units, |
||
| 219 | Min[itemIndex]); |
||
| 220 | cur_rdg = ConveriMFDRaw2Data (Observation, DisplayInfo[Observation].Units, |
||
| 221 | DataVal); |
||
| 222 | |||
| 223 | int dp_pos; // where to print the decimal place |
||
| 224 | float scale = 1.0; |
||
| 225 | switch (DisplayInfo[Observation].DP) |
||
| 226 | { |
||
| 227 | default: |
||
| 228 | case 0: |
||
| 229 | scale = 1.0; |
||
| 230 | dp_pos = display_t::NO_DECIMAL; |
||
| 231 | break; |
||
| 232 | case 1: |
||
| 233 | scale = 10.0; |
||
| 234 | dp_pos = 1; |
||
| 235 | break; |
||
| 236 | case 2: |
||
| 237 | scale = 100.0; |
||
| 238 | dp_pos = 2; |
||
| 239 | break; |
||
| 240 | |||
| 241 | } |
||
| 242 | int_rdg = (int) (cur_rdg * scale); |
||
| 243 | int_max = (int) (max_rdg * scale); |
||
| 244 | int_min = (int) (min_rdg * scale); |
||
| 245 | |||
| 246 | cur_rdg -= DisplayInfo[Observation].Low; |
||
| 247 | cur_rdg = ap_math::SINE_STEPS * cur_rdg |
||
| 248 | / (DisplayInfo[Observation].High - DisplayInfo[Observation].Low); |
||
| 249 | |||
| 250 | context.dial0 = (int) cur_rdg; |
||
| 251 | |||
| 252 | display.gotoxy (32, 28); |
||
| 253 | display.fontDigits (large_font, 4, dp_pos, int_rdg, WHITE); |
||
| 254 | |||
| 255 | display.printString (small_font, DisplayInfo[Observation].suffix, |
||
| 256 | strlen (DisplayInfo[Observation].suffix)); |
||
| 257 | display.printString (small_font, " ", |
||
| 258 | 3 - strlen (DisplayInfo[Observation].suffix)); |
||
| 259 | // print value overlaid by needle |
||
| 260 | |||
| 261 | /* old needle un-draw */ |
||
| 262 | if (context.dial1 >= 0) |
||
| 263 | { |
||
| 264 | dial.draw_needle (context.dial1); |
||
| 265 | } |
||
| 266 | dial.draw_needle (context.dial0); |
||
| 267 | context.dial1 = context.dial0; |
||
| 268 | showMinMax (display, dp_pos, int_min, int_max); |
||
| 269 | |||
| 270 | display.display (); |
||
| 271 | |||
| 272 | return itemIndex; |
||
| 273 | } |
||
| 274 | |||
| 275 | } |
||
| 276 |