-
Notifications
You must be signed in to change notification settings - Fork 13
/
tester.cpp
192 lines (170 loc) · 3.34 KB
/
tester.cpp
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "Arduino.h"
#include "fancyLock.h"
#include "testPins.h"
#include "allComponents.h"
#include "dso_adc.h"
#include "testerGfx.h"
#include "testerControl.h"
#include "componentSignature.h"
#include "cpuID.h"
#include "pinConfiguration.h"
#include "waveForm.h"
#include "tester.h"
extern void menuSystem(void);
extern TestPin pin1,pin2,pin3;
Tester::Tester()
{
pinTable[0]=&pin1;
pinTable[1]=&pin2;
pinTable[2]=&pin3;
pinTable[3]=&pin1;
pinTable[4]=&pin2;
pinTable[5]=&pin3;
}
/**
* \fn probe for 3 poles
* @param a
* @param b
* @param c
* @param comp
*/
bool Tester::probe3Pins(int dex,Component **comp)
{
COMPONENT_TYPE xtype;
TestPin **pins=pinTable+dex-1;
Component *c2=Component::identity3(*pins[0],*pins[1],*pins[2],xtype);
if(!c2)
return false;
delete *comp;
*comp=c2;
return true;
}
/**
* \fn probe for 2 poles
* @param a
* @param b
* @param c
* @param comp
*/
bool Tester::probe2Pins(int dex,Component **comp)
{
COMPONENT_TYPE xtype;
TestPin **pins=pinTable+dex-1;
Component *c2=Component::identity2(*pins[0],*pins[1],*pins[2],xtype);
if(!c2)
return false;
if(!*comp)
{
*comp=c2;
return true;
}
bool replace=false;
if(c2->likely()>(*comp)->likely())
{
replace=true;
}
if(replace)
{
delete *comp;
*comp=c2;
}else
{
delete c2;
}
return true;
}
/**
*
* @param dex
* @param p1
* @param p2
* @param p3
* @param c
*/
void Tester::scan2Pins(int dex, Component **c)
{
probe2Pins(dex,c);
}
/**
*
* @param dex
* @param p1
* @param p2
* @param p3
* @param c
*/
void Tester::scan3Pins(int dex, Component **c)
{
probe3Pins(dex,c);
}
/**
*
*/
bool Tester::probe(void)
{
bool ret=true;
COMPONENT_TYPE type;
// 1 : Zeroing
TesterGfx::clear();
TesterGfx::print(30,40,"Zeroing..");
zeroAllPins();
TesterGfx::clear();
TesterGfx::print(0,40,"Click to probe");
next:
TesterGfx::clear();
TesterGfx::print(18,40,"Detecting");
Component *c=NULL;
TesterGfx::progress6(0);
scan3Pins(1,&c);
TesterGfx::progress6(1);
scan3Pins(2,&c);
TesterGfx::progress6(2);
scan3Pins(3,&c);
if(!c)
{
TesterGfx::progress6(3);
scan2Pins(1,&c);
TesterGfx::progress6(4);
scan2Pins(2,&c);
TesterGfx::progress6(5);
scan2Pins(3,&c);
}
if(!c)
{
return false;
}
TesterGfx::clear();
const char *sname=c->getShortName();
TesterGfx::print(8,40,sname);
TesterGfx::bottomLine(" Measuring");
// Valid component detected ?
if(!c->compute())
{
delete c;
return false; // invalid
}
zeroAllPins();
TesterGfx::clear();
c->draw(0);
while(1)
{
int evt=TesterControl::waitForEvent();
if(evt & CONTROL_LONG)
{
delete c;
menuSystem();
return true;
}
if(evt & CONTROL_SHORT)
goto doneAndDone; // probe next
// TODO LONG => menu
if(evt & CONTROL_ROTARY)
{
int count=TesterControl::getRotary();
c->changePage(count);
}
}
doneAndDone:
delete c;
return ret;
}