Rev 14 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | 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 "libIgnTiming/timing.h" |
||
| 11 | #include <cstring> |
||
| 12 | #include "libOLED/stm32_halDisplay.H" |
||
| 13 | #include "libOLED/fontclass.H" |
||
| 14 | #include "libOLED/displayDial.H" |
||
| 15 | #include "libOLED/displayXY.H" |
||
| 16 | #include "libPlx/displayInfo.H" |
||
| 17 | #include "libOLED/ap_math.h" |
||
| 18 | #include "libSmallPrintf/small_printf.h" |
||
| 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 | |||
| 21 | mjames | 27 | uint32_t atmPress; // actual atmospheric pressure |
| 28 | uint32_t press; // pressure millibar * 100 based on normalised pressure |
||
| 29 | int32_t temp; // temperature * 10 |
||
| 30 | int rpm; // engine RPM |
||
| 2 | mjames | 31 | |
| 21 | mjames | 32 | int timing; // timing value . |
| 2 | mjames | 33 | } |
| 34 | |||
| 35 | uint8_t displayBuffer[MAX_DISPLAYS][dataSize(WIDTH, HEIGHT)]; |
||
| 36 | |||
| 37 | stm32_halDisplay_t displays[MAX_DISPLAYS] = |
||
| 38 | { |
||
| 39 | stm32_halDisplay_t(WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer[0], |
||
| 40 | &hspi1, |
||
| 41 | SPI1_CD_GPIO_Port, |
||
| 42 | SPI1_CD_Pin, |
||
| 43 | SPI1_RESET_GPIO_Port, |
||
| 44 | SPI1_RESET_Pin, |
||
| 45 | SPI1_NSS_GPIO_Port, |
||
| 46 | SPI1_NSS_Pin), |
||
| 47 | }; |
||
| 48 | // display from 0 to 1000 rpm , and 0 to 1000mB |
||
| 49 | displayXY_t dispXY(displays[0], 500, 6000, 1050, 0); |
||
| 50 | |||
| 51 | // set up sine tables |
||
| 52 | ap_math m; |
||
| 53 | |||
| 54 | #if defined __cplusplus |
||
| 55 | extern "C" |
||
| 56 | { |
||
| 57 | #endif |
||
| 58 | |||
| 59 | void |
||
| 60 | cc_init() |
||
| 61 | { |
||
| 62 | for (auto i = 0; i < MAX_DISPLAYS; i++) |
||
| 63 | { |
||
| 64 | display_t &display = displays[i]; |
||
| 65 | if (i == 0) |
||
| 66 | display.reset(); |
||
| 67 | display.init(); |
||
| 68 | display.clearDisplay(BLACK); |
||
| 21 | mjames | 69 | display.gotoxy(8, 32); |
| 70 | display.printString(large_font, "mikeJ", 5, BLACK); |
||
| 2 | mjames | 71 | display.display(); |
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | int |
||
| 13 | mjames | 76 | cc_display(uint8_t dialIndex, uint8_t intensity, uint8_t do_reset) |
| 2 | mjames | 77 | { |
| 78 | |||
| 79 | if (dialIndex < 0 && dialIndex > MAX_DISPLAYS) |
||
| 80 | return -1; |
||
| 81 | stm32_halDisplay_t &display = displays[dialIndex]; |
||
| 14 | mjames | 82 | if (do_reset) |
| 83 | { |
||
| 13 | mjames | 84 | |
| 14 | mjames | 85 | display.reset(); |
| 86 | display.init(); |
||
| 87 | } |
||
| 13 | mjames | 88 | |
| 2 | mjames | 89 | display.clearDisplay(BLACK); |
| 90 | |||
| 91 | display.dim(intensity == 2 ? 255 : 0); |
||
| 92 | |||
| 93 | if (intensity > 0) |
||
| 94 | { |
||
| 95 | |||
| 96 | dispXY.drawAxes(); |
||
| 11 | mjames | 97 | |
| 21 | mjames | 98 | char buff1[20]; // manifold / atmospheric pressure |
| 99 | char buff2[20]; // temp / rpm string |
||
| 100 | char buff[10]; // timing code |
||
| 2 | mjames | 101 | |
| 102 | small_sprintf(buff, "%2d.%01d", timing / 10, timing % 10); |
||
| 103 | |||
| 21 | mjames | 104 | small_sprintf(buff1, "M%4ld A%4ld.%1ld", press / 100, atmPress / 100,(atmPress/10)%10); |
| 2 | mjames | 105 | |
| 21 | mjames | 106 | small_sprintf(buff2, "%2ld.%ldC %4drpm", temp / 100, (temp /10) % 10, rpm); |
| 2 | mjames | 107 | |
| 21 | mjames | 108 | dispXY.plotPoint(rpm, press / 100, buff, buff1, buff2 ); |
| 14 | mjames | 109 | } |
| 2 | mjames | 110 | display.display(); |
| 111 | |||
| 112 | return 0; |
||
| 113 | } |
||
| 114 | |||
| 21 | mjames | 115 | void cc_feed_env(uint32_t atmPressVal, uint32_t pressVal, int32_t tempVal) |
| 2 | mjames | 116 | { |
| 21 | mjames | 117 | atmPress = atmPressVal; |
| 2 | mjames | 118 | press = pressVal; |
| 119 | temp = tempVal; |
||
| 120 | } |
||
| 121 | |||
| 122 | void cc_feed_timing(int timing_) |
||
| 123 | { |
||
| 124 | timing = timing_; |
||
| 125 | } |
||
| 126 | |||
| 127 | void cc_feed_rpm(int rpm_) |
||
| 128 | { |
||
| 129 | rpm = rpm_; |
||
| 130 | } |
||
| 131 | #if defined __cplusplus |
||
| 132 | } |
||
| 133 | #endif |