/*
* display.cpp
*
* Created on: 30 Nov 2020
* Author: mike
*/
#include "main.h"
#include "display.h"
#include "libIgnTiming/timing.h"
#include <cstring>
#include "libOLED/stm32_halDisplay.H"
#include "libOLED/fontclass.H"
#include "libOLED/displayDial.H"
#include "libOLED/displayXY.H"
#include "libPlx/displayInfo.H"
#include "libOLED/ap_math.h"
#include "libSmallPrintf/small_printf.h"
#include "splash.H"
namespace
{
int const WIDTH = 128;
int const HEIGHT = 64;
int const DISPLAY_RAMWIDTH = 132;
int x = 500;
int y = 20;
int ph = 0;
uint32_t press; // pressure millibar * 100
int32_t temp; // temperature * 10
bool button; // user pressed button
}
uint8_t displayBuffer[MAX_DISPLAYS][dataSize(WIDTH, HEIGHT)];
stm32_halDisplay_t displays[MAX_DISPLAYS] =
{
stm32_halDisplay_t(WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer[0],
&hspi1,
SPI_CD_GPIO_Port,
SPI_CD_Pin,
SPI_RESET_GPIO_Port,
SPI_RESET_Pin,
SPI_NSS1_GPIO_Port,
SPI_NSS1_Pin),
};
// display from 0 to 1000 rpm , and 0 to 1000mB
displayXY_t dispXY(displays[0], 500, 6000, 1000, 0);
// display 1 bottom left 90 degrees
displayLeftQuadrantDial_t displayDial1(displays[0]);
// display2 bottom right 90 degrees;
displayRightQuadrantDial_t displayDial2(displays[0]);
// set up sine tables
ap_math m;
#if defined __cplusplus
extern "C"
{
#endif
void
cc_init()
{
for (auto i = 0; i < MAX_DISPLAYS; i++)
{
display_t &display = displays[i];
if (i == 0)
display.reset();
display.init();
display.clearDisplay(BLACK);
display.display();
displaySplash(display);
display.gotoxy(8, 32);
display.printString(large_font, i == 0 ? "1" : "2", 1, BLACK);
display.display();
}
}
int
cc_display(int dialIndex)
{
if (dialIndex < 0 && dialIndex > MAX_DISPLAYS)
return -1;
stm32_halDisplay_t &display = displays[dialIndex];
display.clearDisplay(BLACK);
displayDial1.draw_scale(0, 100, 4, 2, 25);
displayDial2.draw_scale(0, 1000, 4, 2, 250);
// dispXY.drawAxes();
x += 50;
y = (m.ap_sin(ph + (x / 10)) * 39) / 20 + 500; // wobbling about 1000 mB down to about 490mB
if (x > 6000)
{
ph += 200;
if (ph > 360 * m.SINE_SCALING)
ph -= 360 * m.SINE_SCALING;
x = 500;
}
display.dim(button ? 0 : 255);
char buff[10];
int tim = mapTiming(x, 1000 - y);
small_sprintf(buff, "%2d.%1d\xb0", tim / 10, tim % 10);
// dispXY.plotPoint(x, y, buff, buff1, buff2);
displayDial1.draw_limits();
displayDial2.draw_limits();
displayDial1.set_title("Batt");
displayDial1.set_units("degC");
displayDial2.set_units("press");
displayDial1.draw_value(temp / 10, 1);
displayDial1.draw_needle(temp * 360 / 10000);
displayDial2.draw_value(press / 100, display_t::NO_DECIMAL, 4);
displayDial2.draw_needle(press / 300);
display.display();
return 0;
}
void cc_feed(uint32_t pressVal, int32_t tempVal)
{
press = pressVal;
temp = tempVal;
}
void cc_feed_pushbutton(uint8_t buttonVal)
{
button = buttonVal;
}
#if defined __cplusplus
}
#endif