Subversion Repositories DashDisplay

Rev

Rev 79 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 79 Rev 80
Line 3... Line 3...
3
 *
3
 *
4
 *  Created on: 30 Nov 2020
4
 *  Created on: 30 Nov 2020
5
 *      Author: mike
5
 *      Author: mike
6
 */
6
 */
7
 
7
 
-
 
8
#include <stdio.h>
8
#include "main.h"
9
#include "main.h"
9
#include "display.h"
10
#include "display.h"
10
#include "switches.h"
11
#include "switches.h"
11
#include "nvram.h"
12
#include "nvram.h"
12
#include <cstring>
13
#include <cstring>
Line 23... Line 24...
23
namespace
24
namespace
24
{
25
{
25
        int const WIDTH = 128;
26
        int const WIDTH = 128;
26
        int const HEIGHT = 64;
27
        int const HEIGHT = 64;
27
        int const DISPLAY_RAMWIDTH = 132;
28
        int const DISPLAY_RAMWIDTH = 132;
28
 
-
 
29
}
29
}
30
 
30
 
31
uint8_t displayBuffer[2][dataSize(WIDTH, HEIGHT)];
31
uint8_t displayBuffer[2][dataSize(WIDTH, HEIGHT)];
32
 
32
 
33
stm32_halDisplay_t displays[MAX_DISPLAYS] =
33
stm32_halDisplay_t displays[MAX_DISPLAYS] =
Line 103... Line 103...
103
                        display_t &display = displays[i];
103
                        display_t &display = displays[i];
104
                        display.clearDisplay(BLACK);
104
                        display.clearDisplay(BLACK);
105
                        display.setPixelMode(WHITE);
105
                        display.setPixelMode(WHITE);
106
                        display.display();
106
                        display.display();
107
                        context_t &context = contexts[i];
107
                        context_t &context = contexts[i];
108
                        context.dial_timer = 500; // enough time to see at least one frame of PLX before NVRAM check
108
                        resetDialTimer(i);
109
                        context.dial1 = -1;
109
                        context.dial1 = -1;
110
                        context.OldObservation = nullObs;
110
                        context.OldObservation = nullObs;
111
 
111
 
112
                        context.knobPos = -1; // indicate it is initialised 
112
                        context.knobPos = -1; // indicate it is initialised
113
                }
113
                }
114
        }
114
        }
115
 
115
 
116
        // Check to see if there is an observation/instance in the dynamic data array
116
        // Check to see if there is an observation/instance in the dynamic data array
117
        // that matches the current observation/instance in the NVRAM
117
        // that matches the current observation/instance in the NVRAM
Line 123... Line 123...
123
                        return;
123
                        return;
124
                // algorithm only works when there is a vector of observations
124
                // algorithm only works when there is a vector of observations
125
 
125
 
126
                context_t &context = contexts[dialIndex];
126
                context_t &context = contexts[dialIndex];
127
 
127
 
128
                // check for timer timeout on consistent timer
128
                // check for timer timeout using systick timer
129
 
-
 
130
                if (context.dial_timer)
-
 
131
                {
-
 
132
                        context.dial_timer--;
-
 
133
                }
-
 
134
                if (context.dial_timer == 0)
129
                if ((context.dial_timer != 0) && (HAL_GetTick() > context.dial_timer))
135
                {
130
                {
136
                        context.dial_timer = DialTimeout;
131
                        contexts[dialIndex].dial_timer = 0; // used timer timeout
137
                        int i;
-
 
138
                        // use dialIndex+1 as tag for data : always non-zero.
132
                                                                                                // use dialIndex+1 as tag for data : always non-zero.
-
 
133
#if defined SEMIHOSTING
-
 
134
                        printf("check %d\n", dialIndex);
-
 
135
#endif
139
                        nvram_info_t *dial_nvram = find_nvram_data(dialIndex + 1);
136
                        nvram_info_t *dial_nvram = find_nvram_data(dialIndex + 1);
140
 
137
 
141
                        // initial read operation if knobPos < 0
138
                        // initial read operation if knobPos < 0
142
                        if (dial_nvram && context.knobPos < 0)
139
                        if (context.knobPos < 0)
143
                        {
140
                        {
-
 
141
                                if (dial_nvram)
-
 
142
                                {
-
 
143
                                        // found NVRAM content
144
                                context.knobPos = dial_nvram->data.pos;
144
                                        context.knobPos = dial_nvram->data.pos;
-
 
145
                                }
-
 
146
                                else
-
 
147
                                // not found in NVRAM, so use default
-
 
148
                                {
-
 
149
                                        context.knobPos = dialIndex;
-
 
150
                                }
145
                                return;
151
                                return;
146
                        }
152
                        }
147
                        if (context.knobPos < 0)
-
 
148
                                context.knobPos = dialIndex; // timed out , not in NVRAM, use a default
-
 
149
 
153
 
150
                        // dont save dial info for invalid data
154
                        // dont save dial info for invalid data
151
                        if (!isValid(context.knobPos))
155
                        if (!isValid(context.knobPos))
152
                                return;
156
                                return;
153
                        // is this a change since the last timeout ?
157
                        // is this a change since the last timeout ?
154
 
158
 
155
                        if (!dial_nvram  || context.knobPos != dial_nvram->data.pos)
159
                        if (!dial_nvram || context.knobPos != dial_nvram->data.pos)
156
                        {
160
                        {
157
 
161
 
158
                                // store the observation and instance in the NVRAM, not dial position.
162
                                // store the observation and instance in the NVRAM, not dial position.
159
                                nvram_info_t curr_val;
163
                                nvram_info_t curr_val;
-
 
164
                                curr_val.u32 = 0;
160
                                curr_val.data.pos = context.knobPos;
165
                                curr_val.data.pos = context.knobPos;
161
                                curr_val.data.tag = dialIndex + 1;
166
                                curr_val.data.tag = dialIndex + 1;
-
 
167
#if defined SEMIHOSTING
-
 
168
                                printf("saving %d\n", dialIndex);
162
 
169
#endif
163
                                write_nvram_data(curr_val);
170
                                write_nvram_data(curr_val);
164
                        }
171
                        }
165
                }
172
                }
166
        }
173
        }
167
 
174
 
Line 236... Line 243...
236
                        Info[itemIndex].Min = DataVal; // 12 bit max value
243
                        Info[itemIndex].Min = DataVal; // 12 bit max value
237
                }
244
                }
238
 
245
 
239
                // detect change in observation being displayed, reset the dial
246
                // detect change in observation being displayed, reset the dial
240
                if (Observation < PLX_MAX_OBS)
247
                if (Observation < PLX_MAX_OBS)
241
                {      
248
                {
242
                        if (Observation != context.OldObservation.Obs || Instance != context.OldObservation.Instance)
249
                        if (Observation != context.OldObservation.Obs || Instance != context.OldObservation.Instance)
243
                        {
250
                        {
244
                               
251
 
245
                                display.clearDisplay(BLACK);
252
                                display.clearDisplay(BLACK);
246
                                dial.draw_scale(DisplayInfo[Observation].Low,
253
                                dial.draw_scale(DisplayInfo[Observation].Low,
247
                                                                DisplayInfo[Observation].High, 12, 1,
254
                                                                DisplayInfo[Observation].High, 12, 1,
248
                                                                DisplayInfo[Observation].TickScale);
255
                                                                DisplayInfo[Observation].TickScale);
249
 
256