-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwombat_coms.ino
153 lines (124 loc) · 2.38 KB
/
wombat_coms.ino
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
/*
WOMBAT PI Metal detector
wombatpi.net
Modified: 31-Mar-2024
Communication over the serial port and WiFi
--- Not used. ---
Commands in:
Data Out: Sent out the Serial port
*/
// include the stdlib, so atoi function works
//
#include <stdlib.h>
#include "wombat.h"
#define MAX_COMMAND (10)
#define END_CHAR (13)
char rxBuffer[MAX_COMMAND];
int rxCount = 0;
// Returns
// 0 if success
//-1 if failure
int setPulseWidth(int newPulseWidth)
{
return(-1);
}
int sendPulseWidth()
{
// not used
}
//--------------------------------------------------------------------------------------------
// Processing of all Serial / Wifi Commands
//
void checkCommands()
{
char inChar = 0;
bool commandIn = false;
int tempValue = 0;
// ensure quick return if no serial
//
if(Serial.available() <= 0)
{
return;
}
while(Serial.available() > 0)
{
inChar = Serial.read();
rxBuffer[rxCount] = inChar;
// end of command character ?
if(inChar == END_CHAR)
{
rxBuffer[rxCount] = 0; // null terminated the buffer
commandIn = true;
break;
}
else
{
rxCount++;
if(rxCount >= MAX_COMMAND)
{
// avoid buffer overflow
//
rxCount = 0;
}
}
}
// read everything else and ignore
//
while(Serial.available() > 0)
{
Serial.read();
}
rxCount = 0;
// do we have a command ?
//
if(commandIn == true)
{
// process the command
//
if(rxBuffer[0] == 'P')
{
// set the pulse width
//
// value checking is in the setPulseWidth function
//
tempValue = atoi(&rxBuffer[1]);
if(setPulseWidth(tempValue) == 0)
{
// success
//
sendPulseWidth();
}
}
else if(rxBuffer[0] == 's')
{
}
else if(rxBuffer[0] == 'A')
{
// how many samples to Average in the single sample mode
//
}
else if(rxBuffer[0] == 'M')
{
// Set Mode
//
switch(rxBuffer[1])
{
case('S'):
{
mode = S;
}
break;
case('a'):
{
mode = a;
}
break;
default:
{
// do nothing
}
break;
}
}
}
}