Subversion Repositories testOled

Rev

Rev 4 | Rev 6 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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 "timing.h"
  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;
  29.         int ph = 0;
  30.  
  31.  
  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. };
  47. // display from 0 to 1000 rpm , and 0 to 1000mB
  48. displayXY_t dispXY(displays[0], 500, 6000, 1000, 0);
  49.  
  50. // set up sine tables
  51. ap_math m;
  52.  
  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();
  85.                 x += 50;
  86.                 y = m.ap_sin(ph + (x / 20))  + 1000-256;  // wobbling about 1000 mB down to about 490mB
  87.  
  88.                 if (x > 6000)
  89.                 {
  90.                         ph += 200;
  91.                         if (ph > 360 * m.SINE_SCALING)
  92.                                 ph -= 360 * m.SINE_SCALING;
  93.  
  94.                         x = 500;
  95.                 }
  96.                 display.dim(false);
  97.                 char buff[10];
  98.                 char buff1[10];
  99.                 char buff2[10];
  100.                 small_sprintf(buff1, "x=%4d", x);
  101.                 small_sprintf(buff2, "y=%4d", y);
  102.                 int tim = timing(x,1000-y);
  103.                 small_sprintf(buff, "%2d.%1d\xb0",tim/10, tim%10 );
  104.  
  105.                 dispXY.plotPoint(x, y, buff, buff1, buff2);
  106.                 display.dim(true);
  107.                 display.display();
  108.  
  109.                 return 0;
  110.         }
  111.  
  112. #if defined __cplusplus
  113. }
  114. #endif
  115.