Rev 10 | 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" |
||
11 | mjames | 10 | #include "libIgnTiming/timing.h" |
2 | mjames | 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 | |||
27 | int x = 500; |
||
28 | int y = 20; |
||
5 | mjames | 29 | int ph = 0; |
30 | |||
11 | mjames | 31 | uint32_t press; // pressure millibar * 100 |
32 | int32_t temp; // temperature * 10 |
||
33 | bool button; // user pressed button |
||
2 | mjames | 34 | } |
35 | |||
11 | mjames | 36 | uint8_t displayBuffer[MAX_DISPLAYS][dataSize(WIDTH, HEIGHT)]; |
2 | mjames | 37 | |
38 | stm32_halDisplay_t displays[MAX_DISPLAYS] = |
||
39 | { |
||
40 | stm32_halDisplay_t(WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer[0], |
||
41 | &hspi1, |
||
42 | SPI_CD_GPIO_Port, |
||
43 | SPI_CD_Pin, |
||
44 | SPI_RESET_GPIO_Port, |
||
45 | SPI_RESET_Pin, |
||
46 | SPI_NSS1_GPIO_Port, |
||
47 | SPI_NSS1_Pin), |
||
48 | }; |
||
6 | mjames | 49 | // display from 0 to 1000 rpm , and 0 to 1000mB |
5 | mjames | 50 | displayXY_t dispXY(displays[0], 500, 6000, 1000, 0); |
2 | mjames | 51 | |
8 | mjames | 52 | // display 1 bottom left 90 degrees |
53 | displayLeftQuadrantDial_t displayDial1(displays[0]); |
||
54 | |||
55 | // display2 bottom right 90 degrees; |
||
56 | displayRightQuadrantDial_t displayDial2(displays[0]); |
||
57 | |||
3 | mjames | 58 | // set up sine tables |
59 | ap_math m; |
||
60 | |||
2 | mjames | 61 | #if defined __cplusplus |
62 | extern "C" |
||
63 | { |
||
64 | #endif |
||
65 | |||
66 | void |
||
67 | cc_init() |
||
68 | { |
||
69 | for (auto i = 0; i < MAX_DISPLAYS; i++) |
||
70 | { |
||
71 | display_t &display = displays[i]; |
||
72 | if (i == 0) |
||
73 | display.reset(); |
||
74 | display.init(); |
||
75 | display.clearDisplay(BLACK); |
||
76 | display.display(); |
||
77 | displaySplash(display); |
||
78 | display.gotoxy(8, 32); |
||
79 | display.printString(large_font, i == 0 ? "1" : "2", 1, BLACK); |
||
80 | display.display(); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | int |
||
85 | cc_display(int dialIndex) |
||
86 | { |
||
87 | |||
88 | if (dialIndex < 0 && dialIndex > MAX_DISPLAYS) |
||
89 | return -1; |
||
90 | stm32_halDisplay_t &display = displays[dialIndex]; |
||
91 | display.clearDisplay(BLACK); |
||
8 | mjames | 92 | |
93 | displayDial1.draw_scale(0, 100, 4, 2, 25); |
||
11 | mjames | 94 | displayDial2.draw_scale(0, 1000, 4, 2, 250); |
8 | mjames | 95 | |
96 | // dispXY.drawAxes(); |
||
4 | mjames | 97 | x += 50; |
6 | mjames | 98 | y = (m.ap_sin(ph + (x / 10)) * 39) / 20 + 500; // wobbling about 1000 mB down to about 490mB |
3 | mjames | 99 | |
2 | mjames | 100 | if (x > 6000) |
101 | { |
||
3 | mjames | 102 | ph += 200; |
5 | mjames | 103 | if (ph > 360 * m.SINE_SCALING) |
104 | ph -= 360 * m.SINE_SCALING; |
||
105 | |||
2 | mjames | 106 | x = 500; |
107 | } |
||
11 | mjames | 108 | display.dim(button ? 0 : 255); |
4 | mjames | 109 | char buff[10]; |
11 | mjames | 110 | int tim = mapTiming(x, 1000 - y); |
6 | mjames | 111 | small_sprintf(buff, "%2d.%1d\xb0", tim / 10, tim % 10); |
2 | mjames | 112 | |
10 | mjames | 113 | // dispXY.plotPoint(x, y, buff, buff1, buff2); |
8 | mjames | 114 | |
10 | mjames | 115 | displayDial1.draw_limits(); |
8 | mjames | 116 | displayDial2.draw_limits(); |
117 | |||
11 | mjames | 118 | displayDial1.set_title("Batt"); |
10 | mjames | 119 | displayDial1.set_units("degC"); |
11 | mjames | 120 | displayDial2.set_units("press"); |
10 | mjames | 121 | |
11 | mjames | 122 | displayDial1.draw_value(temp / 10, 1); |
10 | mjames | 123 | displayDial1.draw_needle(temp * 360 / 10000); |
11 | mjames | 124 | displayDial2.draw_value(press / 100, display_t::NO_DECIMAL, 4); |
125 | displayDial2.draw_needle(press / 300); |
||
8 | mjames | 126 | |
2 | mjames | 127 | display.display(); |
128 | |||
129 | return 0; |
||
130 | } |
||
131 | |||
10 | mjames | 132 | void cc_feed(uint32_t pressVal, int32_t tempVal) |
133 | { |
||
134 | press = pressVal; |
||
135 | temp = tempVal; |
||
136 | } |
||
11 | mjames | 137 | |
138 | void cc_feed_pushbutton(uint8_t buttonVal) |
||
139 | { |
||
140 | button = buttonVal; |
||
141 | } |
||
2 | mjames | 142 | #if defined __cplusplus |
143 | } |
||
144 | #endif |