Subversion Repositories testOled

Rev

Rev 10 | 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 "libIgnTiming/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.         uint32_t press; // pressure millibar * 100
  32.         int32_t temp;   // temperature * 10
  33.         bool button;    // user pressed button
  34. }
  35.  
  36. uint8_t displayBuffer[MAX_DISPLAYS][dataSize(WIDTH, HEIGHT)];
  37.  
  38. stm32_halDisplay_t displays[MAX_DISPLAYS] =
  39.         {
  40.                 stm32_halDisplay_t(WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer[0],
  41.                                                    &hspi1,
  42.                                                    SPI_CD_GPIO_Port,
  43.                                                    SPI_CD_Pin,
  44.                                                    SPI_RESET_GPIO_Port,
  45.                                                    SPI_RESET_Pin,
  46.                                                    SPI_NSS1_GPIO_Port,
  47.                                                    SPI_NSS1_Pin),
  48. };
  49. // display from 0 to 1000 rpm , and 0 to 1000mB
  50. displayXY_t dispXY(displays[0], 500, 6000, 1000, 0);
  51.  
  52. // display 1 bottom left 90 degrees
  53. displayLeftQuadrantDial_t displayDial1(displays[0]);
  54.  
  55. // display2 bottom right 90 degrees;
  56. displayRightQuadrantDial_t displayDial2(displays[0]);
  57.  
  58. // set up sine tables
  59. ap_math m;
  60.  
  61. #if defined __cplusplus
  62. extern "C"
  63. {
  64. #endif
  65.  
  66.         void
  67.         cc_init()
  68.         {
  69.                 for (auto i = 0; i < MAX_DISPLAYS; i++)
  70.                 {
  71.                         display_t &display = displays[i];
  72.                         if (i == 0)
  73.                                 display.reset();
  74.                         display.init();
  75.                         display.clearDisplay(BLACK);
  76.                         display.display();
  77.                         displaySplash(display);
  78.                         display.gotoxy(8, 32);
  79.                         display.printString(large_font, i == 0 ? "1" : "2", 1, BLACK);
  80.                         display.display();
  81.                 }
  82.         }
  83.  
  84.         int
  85.         cc_display(int dialIndex)
  86.         {
  87.  
  88.                 if (dialIndex < 0 && dialIndex > MAX_DISPLAYS)
  89.                         return -1;
  90.                 stm32_halDisplay_t &display = displays[dialIndex];
  91.                 display.clearDisplay(BLACK);
  92.  
  93.                 displayDial1.draw_scale(0, 100, 4, 2, 25);
  94.                 displayDial2.draw_scale(0, 1000, 4, 2, 250);
  95.  
  96.                 //      dispXY.drawAxes();
  97.                 x += 50;
  98.                 y = (m.ap_sin(ph + (x / 10)) * 39) / 20 + 500; // wobbling about 1000 mB down to about 490mB
  99.  
  100.                 if (x > 6000)
  101.                 {
  102.                         ph += 200;
  103.                         if (ph > 360 * m.SINE_SCALING)
  104.                                 ph -= 360 * m.SINE_SCALING;
  105.  
  106.                         x = 500;
  107.                 }
  108.                 display.dim(button ? 0 : 255);
  109.                 char buff[10];
  110.                 int tim = mapTiming(x, 1000 - y);
  111.                 small_sprintf(buff, "%2d.%1d\xb0", tim / 10, tim % 10);
  112.  
  113.                 //      dispXY.plotPoint(x, y, buff, buff1, buff2);
  114.  
  115.                 displayDial1.draw_limits();
  116.                 displayDial2.draw_limits();
  117.  
  118.                 displayDial1.set_title("Batt");
  119.                 displayDial1.set_units("degC");
  120.                 displayDial2.set_units("press");
  121.  
  122.                 displayDial1.draw_value(temp / 10, 1);
  123.                 displayDial1.draw_needle(temp * 360 / 10000);
  124.                 displayDial2.draw_value(press / 100, display_t::NO_DECIMAL, 4);
  125.                 displayDial2.draw_needle(press / 300);
  126.  
  127.                 display.display();
  128.  
  129.                 return 0;
  130.         }
  131.  
  132.         void cc_feed(uint32_t pressVal, int32_t tempVal)
  133.         {
  134.                 press = pressVal;
  135.                 temp = tempVal;
  136.         }
  137.  
  138.         void cc_feed_pushbutton(uint8_t buttonVal)
  139.         {
  140.                 button = buttonVal;
  141.         }
  142. #if defined __cplusplus
  143. }
  144. #endif
  145.