Subversion Repositories testOled

Rev

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