Rev 3 | Rev 5 | 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" |
||
| 10 | #include <cstring> |
||
| 11 | #include "libOLED/stm32_halDisplay.H" |
||
| 12 | #include "libOLED/fontclass.H" |
||
| 13 | #include "libOLED/displayDial.H" |
||
| 14 | #include "libOLED/displayXY.H" |
||
| 15 | #include "libPlx/displayInfo.H" |
||
| 16 | #include "libOLED/ap_math.h" |
||
| 17 | #include "libSmallPrintf/small_printf.h" |
||
| 18 | #include "splash.H" |
||
| 19 | |||
| 20 | namespace |
||
| 21 | { |
||
| 22 | int const WIDTH = 128; |
||
| 23 | int const HEIGHT = 64; |
||
| 24 | int const DISPLAY_RAMWIDTH = 132; |
||
| 25 | |||
| 26 | int x = 500; |
||
| 27 | int y = 20; |
||
| 3 | mjames | 28 | int ph= 0; |
| 2 | mjames | 29 | } |
| 30 | |||
| 31 | uint8_t displayBuffer[2][dataSize(WIDTH, HEIGHT)]; |
||
| 32 | |||
| 33 | stm32_halDisplay_t displays[MAX_DISPLAYS] = |
||
| 34 | { |
||
| 35 | stm32_halDisplay_t(WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer[0], |
||
| 36 | &hspi1, |
||
| 37 | SPI_CD_GPIO_Port, |
||
| 38 | SPI_CD_Pin, |
||
| 39 | SPI_RESET_GPIO_Port, |
||
| 40 | SPI_RESET_Pin, |
||
| 41 | SPI_NSS1_GPIO_Port, |
||
| 42 | SPI_NSS1_Pin), |
||
| 43 | }; |
||
| 44 | // display from 0 to 1000 rpm , and 0 to 100kPa |
||
| 45 | displayXY_t dispXY(displays[0], 500, 6000, 100, 0); |
||
| 46 | |||
| 3 | mjames | 47 | // set up sine tables |
| 48 | ap_math m; |
||
| 49 | |||
| 2 | mjames | 50 | #if defined __cplusplus |
| 51 | extern "C" |
||
| 52 | { |
||
| 53 | #endif |
||
| 54 | |||
| 55 | void |
||
| 56 | cc_init() |
||
| 57 | { |
||
| 58 | for (auto i = 0; i < MAX_DISPLAYS; i++) |
||
| 59 | { |
||
| 60 | display_t &display = displays[i]; |
||
| 61 | if (i == 0) |
||
| 62 | display.reset(); |
||
| 63 | display.init(); |
||
| 64 | display.clearDisplay(BLACK); |
||
| 65 | display.display(); |
||
| 66 | displaySplash(display); |
||
| 67 | display.gotoxy(8, 32); |
||
| 68 | display.printString(large_font, i == 0 ? "1" : "2", 1, BLACK); |
||
| 69 | display.display(); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | int |
||
| 74 | cc_display(int dialIndex) |
||
| 75 | { |
||
| 76 | |||
| 77 | if (dialIndex < 0 && dialIndex > MAX_DISPLAYS) |
||
| 78 | return -1; |
||
| 79 | stm32_halDisplay_t &display = displays[dialIndex]; |
||
| 80 | display.clearDisplay(BLACK); |
||
| 81 | dispXY.drawAxes(); |
||
| 4 | mjames | 82 | x += 50; |
| 3 | mjames | 83 | y = m.ap_sin((ph+x)/2 )/10 + 50; |
| 84 | |||
| 2 | mjames | 85 | if (x > 6000) |
| 86 | { |
||
| 3 | mjames | 87 | ph += 200; |
| 88 | if(ph> 360*m.SINE_SCALING) |
||
| 89 | ph-=360*m.SINE_SCALING; |
||
| 90 | |||
| 2 | mjames | 91 | x = 500; |
| 92 | } |
||
| 93 | display.dim(false); |
||
| 4 | mjames | 94 | char buff[10]; |
| 2 | mjames | 95 | char buff1[10]; |
| 96 | char buff2[10]; |
||
| 3 | mjames | 97 | small_sprintf(buff1, "x=%4d", x); |
| 98 | small_sprintf(buff2, "y=%4d", y); |
||
| 4 | mjames | 99 | small_sprintf(buff, "123\xb0"); |
| 2 | mjames | 100 | |
| 4 | mjames | 101 | dispXY.plotPoint(x, y, buff, buff1, buff2); |
| 2 | mjames | 102 | display.dim(true); |
| 103 | display.display(); |
||
| 104 | |||
| 105 | return 0; |
||
| 106 | } |
||
| 107 | |||
| 108 | #if defined __cplusplus |
||
| 109 | } |
||
| 110 | #endif |