-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
156 lines (124 loc) · 4.32 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "util/delay.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "ui.h"
#include "io.h"
enum Menu{
CURSOR_MENU,
MINIMAP_MENU,
MEASURE_MENU,
SCALE_MENU,
TIMEBASE_MENU,
OFFSET_MENU,
TRIGGER_MENU
};
int main(void)
{
init_control();
init_lcd();
init_adc();
sei();
set_orientation(West);
rectangle dataP[SWIDTH];
for(int i = 0; i < SWIDTH; i++)
dataP[i].left=dataP[i].right=dataP[i].top=dataP[i].bottom=0;
uiGrid grid = {.major=20, .minor=5};
uiPlot plot = {.dp=dataP, .data=adcbuf};
uiSlider minimap = {.x=110, .y=12, .pos=10, .color=GREEN};
bool clearMeasureFlag = false;
uiText textDisplay = {.x=SPAD+5, .y=23, .text="140 characters goes here"};
uiCursor offsetCursor = {.arrow='<', .color=BLACK, .trace=false};
uiCursor triggerCursor = {.arrow='>', .color=BLACK, .trace=false};
uiCursor measureCursor[4] = {
{.arrow='^', .color=ORANGE, .trace=true},
{.arrow='^', .color=ORANGE, .trace=true},
{.arrow='>', .color=RED, .trace=true},
{.arrow='>', .color=RED, .trace=true}
};
uiTextBox optionBox[7] = {
{.x=20, .y=9 , .text="CURSOR", .color=CYAN},
{.x=0, .y=0 , .text="", .color=BLACK}, /* Placeholder */
{.x=250, .y=9 , .text="MEASURE", .color=GREEN},
{.x=20, .y=SCBOTTOM-9, .text="SCALE", .color=BLUE},
{.x=90, .y=SCBOTTOM-9, .text="TIMEBASE", .color=YELLOW},
{.x=180, .y=SCBOTTOM-9, .text="OFFSET", .color=MAGENTA},
{.x=260, .y=SCBOTTOM-9, .text="TRIGGER", .color=RED}
};
for(int i=0; i < 7; i++)
uiTextBoxDraw(&optionBox[i]);
ioPrefs user_prefs;
ioPrefsReset(&user_prefs);
for/*ever*/(;;)
{
/* ------- Grid and Plotting -------- */
if(!ioPaused && cnt%2==0) start_adc(user_prefs.timebase);
uiGridDraw(&grid);
uiPlotUpdate(&plot, user_prefs.scale/100.0, user_prefs.scrollpos*10, user_prefs.offset);
/* ------- Minimap -------- */
uiSliderMove(&minimap, user_prefs.scrollpos);
if(pbstate == MINIMAP_MENU)
uiSliderStatus(&minimap, CYAN);
else if(plot.clipping)
uiSliderStatus(&minimap, RED);
else if(ioPaused)
uiSliderStatus(&minimap, LIGHTGREY);
else // Not triggering
uiSliderStatus(&minimap, GREEN);
/* ------- Option Boxes -------- */
if(pbstate != MINIMAP_MENU)
uiTextBoxSelect(&optionBox[pbstate], true);
uiTextBoxSelect(&optionBox[lastpb], false);
/* ------- Measurement Menu -------- */
if(ioShowMeasure){
uiTextRefresh(&textDisplay, ioGetText());
clearMeasureFlag = true;
}
if(!ioShowMeasure && clearMeasureFlag)
clearMeasureFlag = false, uiGridHide(&grid);
/* ------- User Input -------- */
switch(pbstate){
case CURSOR_MENU:
rp = &user_prefs.mcpos[ioCursor];
rspec = 255;
rstep = 1, rmax = 300, rmin = 20;
for (int i = 0; i < 4; i++) {
measureCursor[i].hover = (i == ioCursor) ? true : false;
uiCursorMove(&measureCursor[i], user_prefs.mcpos[i]);
uiCursorDraw(&measureCursor[i]);
}
break;
case MINIMAP_MENU:
rp = &user_prefs.scrollpos, rspec = 254;
rstep = 1, rmax = 72, rmin = 1;
for (int i = 0; i < 4; i++)
uiCursorHide(&measureCursor[i]);
break;
case MEASURE_MENU:
rp = 0, rspec = 253;
rstep = rmax = rmin = 0;
break;
case SCALE_MENU:
rp = &user_prefs.scale, rspec = 50;
rstep = 5, rmax = 100, rmin = 0;
break;
case TIMEBASE_MENU:
rp = &user_prefs.timebase, rspec = 0;
rstep = 2, rmax = 100, rmin = 0;
break;
case OFFSET_MENU:
rp = &user_prefs.offset, rspec = 120;
rstep = 5, rmax = 220, rmin = 20;
uiCursorMove(&offsetCursor, user_prefs.offset);
break;
case TRIGGER_MENU:
rp = &user_prefs.trigger, rspec = 120;
rstep = 5, rmax = 220, rmin = 20;
uiCursorMove(&triggerCursor, user_prefs.trigger);
break;
case 7: // NOTHING
default:
break;
}
}
}