-
Notifications
You must be signed in to change notification settings - Fork 13
/
myCode.cpp
215 lines (183 loc) · 3.9 KB
/
myCode.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
*/
#include "../../SPI/src/SPI.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 "pinConfiguration.cpp"
#include "tester.h"
#include "myPwm.h"
#define LED PC13
extern void calibration();
extern void menuSystem(void);
extern void grapher( TestPin *p1,TestPin *p2);
extern void menuSystem(void);
extern void showIcons();
extern bool pinTest();
// Free RTOS heap
uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
extern void menu(void);
bool Tester_waitForkeyPress(const char *msg);
/**
* @brief
*
*/
class MainTask : public xTask
{
public:
MainTask() : xTask("MainTask",10,400)
{
}
void run(void);
protected:
};
/**
*
*/
/**
*/
void MainTask::run()
{
cpuID::identify();
TesterGfx::init();
TesterGfx::splash();
TestPin::initADC(PA0);
pin1.init();
pin2.init();
pin3.init();
xDelay(100);
TesterControl::init();
// The fist Time based sampling is always wrong
// do a dummy one
{
uint16_t *samples;
int nbSamples;
pin2.prepareTimerSample(100*1000,10);
pin2.finishTimer(nbSamples,&samples);
}
//
if(!NVM::hasCalibration())
calibration();
// pinTest();
#if 0
pin2.setToGround();
while(1)
{
pin1.pullUp(TestPin::PULL_LOW);
delayMicroseconds(100);
pin1.pullDown(TestPin::PULL_LOW);
xDelay(4);
}
#endif
#if 0
Coil c(pin1,pin2,pin3);
while(1)
{
c.compute();
}
#endif
#if 0
grapher(&pin2,&pin1);
#endif
#if 0
menuSystem();
#endif
#if 0
Capacitor c(pin1,pin2,pin3);
c.compute();
char st[40];
Component::prettyPrint(c.getValue(),"F",st);
TesterGfx::print(10,20,st);
TesterControl::waitForAnyEvent();
int sum,nb;
pin1.summedRead(sum,nb);
Capacitor::quickEval(pin1,pin2,pin3);
c.compute();
Component::prettyPrint(c.getValue(),"F",st);
TesterGfx::print(10,20,st);
TesterControl::waitForAnyEvent();
#endif
#if 0 // calibration
// Stroboscopic calibration, only on pin2
TesterGfx::print(5,28,"Fine cal");
// dummy scan
Capacitor xcap(pin1,pin2,pin3);
float ccc;
xcap.compute1nfRange(ccc);
pin1.setToGround();
pin3.setToGround();
pin2.setToGround();
TestPinCalibration cal1,cal3;
xDelay(10);
{
float cap;
Capacitor::calibrationVeryLow(pin1,pin2,cal1);
Capacitor::calibrationVeryLow(pin3,pin2,cal3);
}
#endif
//showIcons();
// All ready
Tester tester;
Tester_waitForkeyPress("Press to start");
while(1)
{
TesterGfx::clear();
bool found=tester.probe();
if(!found)
{
Tester_waitForkeyPress("?Unknown?");
}
}
}
/**
*
* @param msg
* @return
*/
bool Tester_waitForkeyPress(const char *msg)
{
TesterGfx::clear();
TesterGfx::print(0,60,msg);
int evt=TesterControl::waitForEvent();
if(evt & CONTROL_LONG)
{
menuSystem();
}
return true;
}
/**
*
*/
void mySetup(void)
{
afio_cfg_debug_ports( AFIO_DEBUG_SW_ONLY); // get PB3 & PB4
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
// Remap Timer from PA6/7 tp PB4/5
afio_remap(AFIO_REMAP_TIM3_PARTIAL);
SPI.begin();
SPI.setBitOrder(MSBFIRST); // Set the SPI bit order
SPI.setDataMode(SPI_MODE0); //Set the SPI data mode 0
SPI.setClockDivider (SPI_CLOCK_DIV4); // Given for 10 Mhz...
Serial.end(); // dont let usb bother us
interrupts();
Serial1.begin(115200);
Logger("Starting...\n");
MainTask *mainTask=new MainTask();
vTaskStartScheduler();
}
/**
*
*/
void myLoop()
{
xAssert(0);
}
// EOF