Rev 5 | 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 | |||
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 | |
3 | mjames | 49 | // set up sine tables |
50 | ap_math m; |
||
51 | |||
2 | mjames | 52 | #if defined __cplusplus |
53 | extern "C" |
||
54 | { |
||
55 | #endif |
||
56 | |||
57 | void |
||
58 | cc_init() |
||
59 | { |
||
60 | for (auto i = 0; i < MAX_DISPLAYS; i++) |
||
61 | { |
||
62 | display_t &display = displays[i]; |
||
63 | if (i == 0) |
||
64 | display.reset(); |
||
65 | display.init(); |
||
66 | display.clearDisplay(BLACK); |
||
67 | display.display(); |
||
68 | displaySplash(display); |
||
69 | display.gotoxy(8, 32); |
||
70 | display.printString(large_font, i == 0 ? "1" : "2", 1, BLACK); |
||
71 | display.display(); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | int |
||
76 | cc_display(int dialIndex) |
||
77 | { |
||
78 | |||
79 | if (dialIndex < 0 && dialIndex > MAX_DISPLAYS) |
||
80 | return -1; |
||
81 | stm32_halDisplay_t &display = displays[dialIndex]; |
||
82 | display.clearDisplay(BLACK); |
||
83 | dispXY.drawAxes(); |
||
4 | mjames | 84 | x += 50; |
6 | mjames | 85 | y = (m.ap_sin(ph + (x / 10)) * 39) / 20 + 500; // wobbling about 1000 mB down to about 490mB |
3 | mjames | 86 | |
2 | mjames | 87 | if (x > 6000) |
88 | { |
||
3 | mjames | 89 | ph += 200; |
5 | mjames | 90 | if (ph > 360 * m.SINE_SCALING) |
91 | ph -= 360 * m.SINE_SCALING; |
||
92 | |||
2 | mjames | 93 | x = 500; |
94 | } |
||
95 | display.dim(false); |
||
4 | mjames | 96 | char buff[10]; |
2 | mjames | 97 | char buff1[10]; |
98 | char buff2[10]; |
||
3 | mjames | 99 | small_sprintf(buff1, "x=%4d", x); |
100 | small_sprintf(buff2, "y=%4d", y); |
||
6 | mjames | 101 | int tim = timing(x, 1000 - y); |
102 | small_sprintf(buff, "%2d.%1d\xb0", tim / 10, tim % 10); |
||
2 | mjames | 103 | |
4 | mjames | 104 | dispXY.plotPoint(x, y, buff, buff1, buff2); |
2 | mjames | 105 | display.dim(true); |
106 | display.display(); |
||
107 | |||
108 | return 0; |
||
109 | } |
||
110 | |||
111 | #if defined __cplusplus |
||
112 | } |
||
113 | #endif |