-
Notifications
You must be signed in to change notification settings - Fork 0
/
T2M_usb.ino
87 lines (78 loc) · 2.48 KB
/
T2M_usb.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
/***************************************************
T2MINI control software by John Ackermann N8UR.
USB serial functions
****************************************************/
void usb_setup() {
// initialize serial:
Serial.begin(115200);
delay(100);
// splash
Serial.println("");
Serial.println("TAPR T2-Mini Control Software ");
Serial.println(version);
Serial.println("Copyright 2016 John Ackermann N8UR");
Serial.println("Licensed under MIT license");
Serial.println("");
Serial.println("Command example: <2B> (arrow, boardnum, command, arrow)");
Serial.println("Boardnum 1-8, 0 addresses all");
Serial.println("Command: A = 1 MHz, B = 2.5 MHz, C = 5 MHz, D = 10 MHz");
Serial.println(" S = arm for Sync (divider restarts after any ");
Serial.println(" command on next sync input positive edge)");
Serial.println("");
} // usb_setup()
boolean get_usb_data() {
if ( getSerialString() ) {
execute = cmd_parse(dataBuffer);
return execute;
}
} //get_usb_data
boolean getSerialString(){
static byte dataBufferIndex = 0;
boolean storeString;
while(Serial.available()>0){
char incomingbyte = Serial.read();
if(incomingbyte==startChar){
dataBufferIndex = 0; //Initialize dataBufferIndex variable
storeString = true;
}
if(storeString){
// Abort if index outside buffer size
if(dataBufferIndex==DATABUFFERSIZE){
dataBufferIndex = 0;
break;
}
if(incomingbyte==endChar){
dataBuffer[dataBufferIndex] = 0; //null terminate the C string
//Data string is complete.
storeString = false;
return true;
}
else{
dataBuffer[dataBufferIndex++] = incomingbyte;
dataBuffer[dataBufferIndex] = 0; //null terminate the C string
}
}
else{
}
}
//All data read; no valid string
return false;
}
void usb_print_status(int boardnum, byte cmd_mask){
Serial.print ("Board: ");
Serial.print (boardnum);
if (board == '0') { Serial.print(" (Select All)"); }
Serial.print (" command: ");
Serial.print (cmd);
Serial.print(" Mask: ");
usb_print_bits(cmd_mask);
Serial.println("");
}
void usb_print_bits(byte myByte){
for (byte mask = 0x80; mask; mask >>= 1){
if (mask & myByte)
Serial.print('1');
else
Serial.print('0');
}
} // usb_printBits()