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