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