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