-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathHost.pde
120 lines (115 loc) · 3.26 KB
/
Host.pde
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
/**
* Copyright 2009 Jonathan Oxer <[email protected]>
* Distributed under the same terms as OBDuino
*/
#ifdef MEGA
/**
* processHostCommands
*/
void processHostCommands()
{
// Check for state change from the front panel button
if(logActive && !digitalRead(LOG_LED))
{
logActive = 0;
digitalWrite(VDIP_STATUS_LED, LOW);
VDIP.print("CLF OBDUINO.CSV");
VDIP.print(13, BYTE);
HOST.println("Stop logging");
}
if( !logActive && digitalRead(LOG_LED))
{
logActive = 1;
digitalWrite(VDIP_STATUS_LED, HIGH);
VDIP.print("OPW OBDUINO.CSV");
VDIP.print(13, BYTE);
HOST.println("Start logging");
}
// Check for commands from the host
if( HOST.available() > 0)
{
char readChar = HOST.read();
if(readChar == '1')
{ // Open file and start logging
HOST.println("Start logging");
logActive = 1;
digitalWrite(VDIP_STATUS_LED, HIGH);
digitalWrite(LOG_LED, HIGH);
VDIP.print("OPW OBDUINO.CSV");
VDIP.print(13, BYTE);
HOST.print("> ");
} else if( readChar == '2') { // Stop logging and close file
HOST.println("Stop logging");
while(digitalRead(VDIP_RTS_PIN) == HIGH)
{
HOST.println("VDIP BUFFER FULL");
}
logActive = 0;
digitalWrite(VDIP_STATUS_LED, LOW);
digitalWrite(LOG_LED, LOW);
VDIP.print("CLF OBDUINO.CSV");
VDIP.print(13, BYTE);
HOST.print("> ");
} else if (readChar == '3'){ // Display the file
HOST.println("Reading file");
VDIP.print("RD OBDUINO.CSV");
VDIP.print(13, BYTE);
processVdipBuffer();
HOST.print("> ");
} else if (readChar == '4'){ // Delete the file
HOST.println("Deleting file");
VDIP.print("DLF OBDUINO.CSV");
VDIP.print(13, BYTE);
HOST.print("> ");
} else if (readChar == '5'){ // Directory listing
HOST.println("Directory listing");
VDIP.print("DIR");
VDIP.print(13, BYTE);
HOST.print("> ");
} else if (readChar == '6'){ // Reset the VDIP
HOST.print(" * Initialising flash storage ");
pinMode(VDIP_RESET, OUTPUT);
digitalWrite(VDIP_RESET, LOW);
delay( 100 );
digitalWrite(VDIP_RESET, HIGH);
delay( 100 );
VDIP.print("IPA"); // Sets the VDIP to ASCII mode
VDIP.print(13, BYTE);
HOST.println("[OK]");
HOST.print("> ");
} else { // HELP!
HOST.print("Unrecognised command '");
HOST.print(readChar);
HOST.println("'");
HOST.println("1 - Start logging");
HOST.println("2 - Stop logging");
HOST.println("3 - Display logfile");
HOST.println("4 - Delete logfile");
HOST.println("5 - Directory listing");
HOST.println("6 - Reset VDIP module");
HOST.print("> ");
}
}
}
#endif
/**
* hostPrint
* Analogous to Serial.print, but does nothing if MEGA is not defined. This allows
* other parts of the code to always call this function without having to check
* if a host serial connection is available
*/
void hostPrint( char* message )
{
#ifdef MEGA
HOST.print(message);
#endif
}
/**
* hostPrintLn
*/
void hostPrintLn( char* message )
{
#ifdef MEGA
HOST.println(message);
#endif
}