Subversion Repositories EDIS_Ignition

Rev

Rev 3 | Go to most recent revision | Details | 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 "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
        int rpm;        // user pressed button
34
 
35
        int timing; // timing value .
36
}
37
 
38
uint8_t displayBuffer[MAX_DISPLAYS][dataSize(WIDTH, HEIGHT)];
39
 
40
stm32_halDisplay_t displays[MAX_DISPLAYS] =
41
        {
42
                stm32_halDisplay_t(WIDTH, HEIGHT, DISPLAY_RAMWIDTH, displayBuffer[0],
43
                                                   &hspi1,
44
                                                   SPI1_CD_GPIO_Port,
45
                                                   SPI1_CD_Pin,
46
                                                   SPI1_RESET_GPIO_Port,
47
                                                   SPI1_RESET_Pin,
48
                                                   SPI1_NSS_GPIO_Port,
49
                                                   SPI1_NSS_Pin),
50
};
51
// display from 0 to 1000 rpm , and 0 to 1000mB
52
displayXY_t dispXY(displays[0], 500, 6000, 1050, 0);
53
 
54
// set up sine tables
55
ap_math m;
56
 
57
#if defined __cplusplus
58
extern "C"
59
{
60
#endif
61
 
62
        void
63
        cc_init()
64
        {
65
                for (auto i = 0; i < MAX_DISPLAYS; i++)
66
                {
67
                        display_t &display = displays[i];
68
                        if (i == 0)
69
                                display.reset();
70
                        display.init();
71
                        display.clearDisplay(BLACK);
72
                        display.display();
73
                        displaySplash(display);
74
                        display.gotoxy(8, 32);
75
                        display.printString(large_font, i == 0 ? "1" : "2", 1, BLACK);
76
                        display.display();
77
                }
78
        }
79
 
80
        int
81
        cc_display(uint8_t dialIndex, uint8_t intensity)
82
        {
83
 
84
                if (dialIndex < 0 && dialIndex > MAX_DISPLAYS)
85
                        return -1;
86
                stm32_halDisplay_t &display = displays[dialIndex];
87
                display.clearDisplay(BLACK);
88
 
89
                display.dim(intensity == 2 ? 255 : 0);
90
 
91
                if (intensity > 0)
92
                {
93
 
94
                        dispXY.drawAxes();
95
 
96
                        char buff1[10];
97
                        char buff2[10];
98
                        char buff[10];
99
 
100
                        small_sprintf(buff, "%2d.%01d", timing / 10, timing % 10);
101
 
102
                        small_sprintf(buff1, "%4ld.%02ld mb", press / 100, press % 100);
103
 
104
                        small_sprintf(buff2, "%4d rpm", rpm);
105
 
106
                        dispXY.plotPoint(rpm, press/100, buff, buff1, buff2);
107
                }
108
                display.display();
109
 
110
                return 0;
111
        }
112
 
113
        void cc_feed_env(uint32_t pressVal, int32_t tempVal)
114
        {
115
                press = pressVal;
116
                temp = tempVal;
117
        }
118
 
119
        void cc_feed_timing(int timing_)
120
        {
121
                timing = timing_;
122
        }
123
 
124
        void cc_feed_rpm(int rpm_)
125
        {
126
                rpm = rpm_;
127
        }
128
#if defined __cplusplus
129
}
130
#endif