Rev 2 | Rev 4 | 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 | char buff[10]; |
||
| 81 | display.clearDisplay(BLACK); |
||
| 82 | dispXY.drawAxes(); |
||
| 3 | mjames | 83 | x += 100; |
| 84 | y = m.ap_sin((ph+x)/2 )/10 + 50; |
||
| 85 | |||
| 2 | mjames | 86 | if (x > 6000) |
| 87 | { |
||
| 3 | mjames | 88 | ph += 200; |
| 89 | if(ph> 360*m.SINE_SCALING) |
||
| 90 | ph-=360*m.SINE_SCALING; |
||
| 91 | |||
| 2 | mjames | 92 | x = 500; |
| 93 | } |
||
| 94 | display.dim(false); |
||
| 95 | char buff1[10]; |
||
| 96 | char buff2[10]; |
||
| 3 | mjames | 97 | small_sprintf(buff1, "x=%4d", x); |
| 98 | small_sprintf(buff2, "y=%4d", y); |
||
| 2 | mjames | 99 | |
| 3 | mjames | 100 | dispXY.plotPoint(x, y, "frogs", buff1, buff2); |
| 2 | mjames | 101 | display.dim(true); |
| 102 | display.display(); |
||
| 103 | |||
| 104 | return 0; |
||
| 105 | } |
||
| 106 | |||
| 107 | #if defined __cplusplus |
||
| 108 | } |
||
| 109 | #endif |