Skip to content

Commit 67b6b6e

Browse files
committed
Rewrite systemPrint to support PRINT_TO_RF.
1 parent 55135d8 commit 67b6b6e

File tree

1 file changed

+43
-75
lines changed

1 file changed

+43
-75
lines changed

Firmware/LoRaSerial_Firmware/System.ino

Lines changed: 43 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,84 @@
1-
//Helper functions to print to all available ports
21
void systemPrint(const char* value)
32
{
4-
Serial.print(value);
5-
6-
#if defined(ARDUINO_ARCH_SAMD)
7-
Serial1.print(value);
8-
#endif
9-
}
10-
11-
void systemPrintln(const char* value)
12-
{
13-
systemPrint(value);
14-
15-
Serial.println();
16-
#if defined(ARDUINO_ARCH_SAMD)
17-
Serial1.println();
18-
#endif
19-
}
20-
21-
void systemPrint(const __FlashStringHelper* value)
22-
{
23-
//Communicate an AT response over serial or the RF link (if available)
24-
if (serialState == SERIAL_COMMAND)
3+
if (printerEndpoint == PRINT_TO_SERIAL)
254
{
265
Serial.print(value);
276

287
#if defined(ARDUINO_ARCH_SAMD)
298
Serial1.print(value);
309
#endif
3110
}
32-
else if(serialState == SERIAL_REMOTE_COMMAND_TX || serialState == SERIAL_REMOTE_COMMAND_RX)
11+
else if (printerEndpoint == PRINT_TO_RF)
3312
{
34-
if (isLinked() == true && radioState == RADIO_LINKED_RECEIVING_STANDBY)
13+
//Move these characters into the transmit buffer
14+
for (int x = 0 ; x < strlen(value) ; x++)
3515
{
36-
//Move this response to the outgoing packet and send
37-
// for (int x = 0 ; x < strlen(value) ; x++)
38-
// outgoingPacket[x] = value[x];
39-
40-
sendCommandDataPacket();
41-
changeState(RADIO_LINKED_TRANSMITTING);
16+
commandTXBuffer[commandTXHead++] = value[x];
17+
commandTXHead %= sizeof(commandTXBuffer);
4218
}
4319
}
4420
}
4521

46-
void systemPrintln(const __FlashStringHelper * value)
22+
void systemPrintln(const char* value)
4723
{
4824
systemPrint(value);
49-
50-
Serial.println();
51-
#if defined(ARDUINO_ARCH_SAMD)
52-
Serial1.println();
53-
#endif
25+
systemPrint("\r\n");
5426
}
5527

5628
void systemPrint(int value)
5729
{
58-
Serial.print(value);
59-
60-
#if defined(ARDUINO_ARCH_SAMD)
61-
Serial1.print(value);
62-
#endif
30+
char temp[20];
31+
sprintf(temp, "%d", value);
32+
systemPrint(temp);
6333
}
6434

6535
void systemPrintln(int value)
6636
{
6737
systemPrint(value);
68-
69-
Serial.println();
70-
#if defined(ARDUINO_ARCH_SAMD)
71-
Serial1.println();
72-
#endif
38+
systemPrint("\r\n");
7339
}
7440

7541
void systemPrint(uint8_t value, uint8_t printType)
7642
{
77-
Serial.print(value, printType);
43+
char temp[20];
7844

79-
#if defined(ARDUINO_ARCH_SAMD)
80-
Serial1.print(value, printType);
81-
#endif
45+
if (printType == HEX)
46+
sprintf(temp, "%02X", value);
47+
else if (printType == DEC)
48+
sprintf(temp, "%d", value);
49+
50+
systemPrint(temp);
8251
}
8352

8453
void systemPrintln(uint8_t value, uint8_t printType)
8554
{
8655
systemPrint(value, printType);
87-
88-
Serial.println();
89-
#if defined(ARDUINO_ARCH_SAMD)
90-
Serial1.println();
91-
#endif
56+
systemPrint("\r\n");
9257
}
9358

9459
void systemPrint(float value, uint8_t decimals)
9560
{
96-
Serial.print(value, decimals);
97-
98-
#if defined(ARDUINO_ARCH_SAMD)
99-
Serial1.print(value, decimals);
100-
#endif
61+
char temp[20];
62+
sprintf(temp, "%.*f", decimals, value);
63+
systemPrint(temp);
10164
}
10265

10366
void systemPrintln(float value, uint8_t decimals)
10467
{
10568
systemPrint(value, decimals);
106-
107-
Serial.println();
108-
#if defined(ARDUINO_ARCH_SAMD)
109-
Serial1.println();
110-
#endif
69+
systemPrint("\r\n");
11170
}
11271

11372
void systemPrintln()
11473
{
115-
Serial.println();
116-
117-
#if defined(ARDUINO_ARCH_SAMD)
118-
Serial1.println();
119-
#endif
74+
systemPrint("\r\n");
12075
}
12176

12277
void systemWrite(uint8_t value)
12378
{
124-
Serial.write(value);
125-
126-
#if defined(ARDUINO_ARCH_SAMD)
127-
Serial1.write(value);
128-
#endif
79+
char temp[2];
80+
sprintf(temp, "%c", value);
81+
systemPrint(temp);
12982
}
13083

13184
void systemFlush()
@@ -289,3 +242,18 @@ void movePacketToSettings(Settings settings, uint8_t* packetBuffer)
289242
for (uint8_t x = 0 ; x < sizeof(settings) ; x++)
290243
bytePtr[x] = packetBuffer[x];
291244
}
245+
246+
//Given two letters, convert to base 10
247+
uint8_t charToHex(char a, char b)
248+
{
249+
a = toupper(a);
250+
b = toupper(b);
251+
252+
if ('0' <= a && a <= '9') a -= '0';
253+
if ('A' <= a && a <= 'F') a = a - 'A' + 10;
254+
255+
if ('0' <= b && b <= '9') b -= '0';
256+
if ('A' <= b && b <= 'F') b = b - 'A' + 10;
257+
258+
return((a << 4) | b);
259+
}

0 commit comments

Comments
 (0)