Skip to content

Commit 286f98c

Browse files
committed
Changes based on code review
1 parent 91018b5 commit 286f98c

19 files changed

+235
-231
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ them to the [support forum](https://forum.arduino.cc/index.php?board=103).
5656
5757
# Enable debug interface on Serail1
5858

59-
*Default disable the debug interface.
59+
* Default disable the debug interface.
6060

61-
If you want to enable debug trace on Serail1 to debug corelib, follow these instructions.
61+
If you want to enable debug trace on Serial1 to debug corelib, follow these instructions.
6262

6363
1. Shut down the IDE
6464
2. Go to Arduino15 directory

cores/arduino/printk.cpp

Lines changed: 5 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -29,202 +29,24 @@
2929
*/
3030

3131
#include <stdarg.h>
32+
#include <cstdio>
3233
#include "UARTClass.h"
3334

3435
extern "C" void printk(const char *fmt, va_list args);
35-
int __vsnprintf(char *dest, int size, const char *fmt, va_list args)
36-
{
37-
int might_format = 0;
38-
int len = 0;
39-
char lastchar = 0;
40-
bool binary_format = false;
41-
42-
if (!dest || !size)
43-
return 0;
44-
45-
while (*fmt && len < size) {
46-
if (!might_format) {
47-
if (*fmt == '\n' && lastchar != '\r') {
48-
if (len < size) {
49-
lastchar = *dest++ = '\r', len++;
50-
continue;
51-
} else
52-
break;
53-
} else if (*fmt != '%') {
54-
if (len < size)
55-
lastchar = *dest++ = *fmt, len++;
56-
else
57-
break;
58-
} else
59-
might_format = 1;
60-
} else {
61-
if (*fmt == '%') {
62-
if (len < size)
63-
*dest++ = '%', len++;
64-
else
65-
break;
66-
might_format = 0;
67-
} else {
68-
switch (*fmt) {
69-
case '0':
70-
case '1':
71-
might_format |= 2;
72-
goto still_format;
73-
break;
74-
case '2':
75-
might_format |= 4;
76-
goto still_format;
77-
break;
78-
case '4':
79-
might_format |= 8;
80-
goto still_format;
81-
break;
82-
case 'b':
83-
binary_format = true;
84-
goto still_format;
85-
break;
86-
case 'd':
87-
case 'i':
88-
case 'u':
89-
if (!binary_format) {
90-
unsigned long num =
91-
va_arg(args,
92-
unsigned long);
93-
unsigned long pos = 999999999;
94-
unsigned long remainder = num;
95-
int found_largest_digit = 0;
96-
97-
if (*fmt != 'u'
98-
&& (num & (1 << 31))) {
99-
if (len < size)
100-
*dest++ =
101-
'-',
102-
len++;
103-
num = (~num) + 1;
104-
remainder = num;
105-
}
106-
while (pos >= 9) {
107-
if (found_largest_digit
108-
|| remainder >
109-
pos) {
110-
found_largest_digit
111-
= 1;
112-
if (len < size)
113-
*dest++
114-
=
115-
(
116-
char)
117-
((
118-
remainder
119-
/ (
120-
pos
121-
+
122-
1))
123-
+
124-
48),
125-
len++;
126-
else
127-
break;
128-
}
129-
remainder %= (pos + 1);
130-
pos /= 10;
131-
}
132-
if (len < size)
133-
*dest++ =
134-
(char)(
135-
remainder
136-
+
137-
48),
138-
len++;
139-
break;
140-
}
141-
case 'x':
142-
case 'X':
143-
case 'p': {
144-
unsigned long num =
145-
va_arg(args, unsigned long);
146-
int sz = sizeof(num) * 2;
147-
148-
if (might_format & 8) {
149-
sz = 4;
150-
} else if (might_format & 4) {
151-
sz = 2;
152-
} else if (might_format & 2) {
153-
sz = 1;
154-
}
155-
for (; sz; sz--) {
156-
char nibble;
157-
if (!binary_format) {
158-
nibble =
159-
(num >>
160-
((sz -
161-
1) <<
162-
2) & 0xf);
163-
nibble +=
164-
nibble >
165-
9 ? 87 : 48;
166-
} else {
167-
nibble =
168-
(num >>
169-
((sz -
170-
1) <<
171-
3) & 0xff);
172-
}
173-
if (len < size)
174-
*dest++ =
175-
nibble,
176-
len++;
177-
else
178-
break;
179-
}
180-
break;
181-
}
182-
case 's': {
183-
char *s = va_arg(args, char *);
184-
while (*s)
185-
if (len < size)
186-
*dest++ =
187-
*s++, len++;
188-
else
189-
break;
190-
break;
191-
}
192-
case 'c': {
193-
char c = va_arg(args, int);
194-
if (len < size)
195-
*dest++ = c, len++;
196-
break;
197-
}
198-
default:
199-
if (len < size)
200-
*dest++ = '%', len++;
201-
if (len < size)
202-
*dest++ = *fmt, len++;
203-
break;
204-
}
205-
might_format = 0;
206-
still_format:
207-
(void)might_format;
208-
}
209-
}
210-
++fmt;
211-
}
212-
*dest = '\0';
213-
return len;
214-
}
215-
21636
extern UARTClass Serial1;
21737
#define PRINTK_BUFSIZ 256
38+
21839
void printk(const char *fmt, va_list args)
21940
{
22041
#ifdef CONFIGURE_DEBUG_CORELIB_ENABLED
221-
int len = 0;
42+
int len = 0;
22243

22344
char tmp[PRINTK_BUFSIZ];
22445

225-
len = __vsnprintf(tmp, PRINTK_BUFSIZ, fmt, args);
46+
len = vsnprintf(tmp, PRINTK_BUFSIZ, fmt, args);
22647

22748
tmp[len] = '\0';
22849
Serial1.println(tmp);
22950
#endif
23051
}
52+

libraries/CurieBLE/examples/IMUBleCentral/IMUBleCentral.ino

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
License along with this library; if not, write to the Free Software
1616
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
18+
1819
#include <CurieBLE.h>
1920

2021
/*
@@ -31,18 +32,12 @@ typedef struct {
3132
} imuFrameType;
3233

3334
imuFrameType imuBuf[MAX_IMU_RECORD];
34-
35-
unsigned seqNum = 0;
36-
37-
long previousMillis = 0; // last time the battery level was checked, in ms
38-
39-
BLECentral bleCentral;; // BLE Central Device (the board you're programming)
35+
BLECentral bleCentral; // BLE Central Device (the board you're programming)
4036

4137
BLEService bleImuService("F7580001-153E-D4F6-F26D-43D8D98EEB13");
42-
// Tx IMU data Characteristic
43-
BLECharacteristic bleImuChar("F7580003-153E-D4F6-F26D-43D8D98EEB13", // standard 16-bit characteristic UUID
44-
BLERead | BLENotify, sizeof(imuBuf)); // remote clients will be able to
45-
// get notifications if this characteristic changes
38+
BLECharacteristic bleImuChar("F7580003-153E-D4F6-F26D-43D8D98EEB13", // standard 128-bit characteristic UUID
39+
BLERead | BLENotify, sizeof(imuBuf)); // remote clients will be able to
40+
// get notifications if this characteristic changes
4641

4742
void ble_connected(BLEHelper &role)
4843
{
@@ -66,7 +61,6 @@ void bleImuCharacteristicWritten(BLEHelper& central, BLECharacteristic& characte
6661
Serial.print(value->slot[1]);
6762
Serial.print("\t");
6863
Serial.println(value->slot[2]);
69-
Serial1.print("\r\n");
7064
}
7165

7266
bool adv_found(uint8_t type,
@@ -117,9 +111,7 @@ bool adv_found(uint8_t type,
117111
return true;
118112
}
119113

120-
void setup() {
121-
Serial1.begin(115200);
122-
114+
void setup() {
123115
Serial.begin(115200); // initialize serial communication
124116
pinMode(13, OUTPUT); // initialize the LED on pin 13 to indicate when a central is connected
125117

@@ -147,6 +139,5 @@ void setup() {
147139
void loop()
148140
{
149141
delay(2000);
150-
Serial1.println("Live..");
151142
}
152143

libraries/CurieBLE/examples/IMUBleNotification/IMUBleNotification.ino

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
License along with this library; if not, write to the Free Software
1616
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
18+
1819
#include <CurieBLE.h>
1920
#include <CurieIMU.h>
2021

@@ -34,19 +35,12 @@ imuFrameType imuBuf[MAX_IMU_RECORD];
3435

3536
unsigned seqNum = 0;
3637

37-
long previousMillis = 0; // last time the battery level was checked, in ms
38-
39-
4038
BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming)
41-
BLEService bleImuService("F7580001-153E-D4F6-F26D-43D8D98EEB13");
42-
43-
// Tx IMU data Characteristic
44-
45-
BLECharacteristic bleImuChar("F7580003-153E-D4F6-F26D-43D8D98EEB13", // standard 16-bit characteristic UUID
46-
BLERead | BLENotify, sizeof(imuBuf)); // remote clients will be able to
47-
// get notifications if this characteristic changes
39+
BLEService bleImuService("F7580001-153E-D4F6-F26D-43D8D98EEB13"); // Tx IMU data Characteristic
40+
BLECharacteristic bleImuChar("F7580003-153E-D4F6-F26D-43D8D98EEB13", // standard 128-bit characteristic UUID
41+
BLERead | BLENotify, sizeof(imuBuf)); // remote clients will be able to
42+
// get notifications if this characteristic changes
4843
void setup() {
49-
Serial1.begin(115200); // For corelib debug
5044

5145
Serial.begin(9600); // initialize serial communication
5246
pinMode(13, OUTPUT); // initialize the LED on pin 13 to indicate when a central is connected

libraries/CurieBLE/examples/LEDCentral/LEDCentral.ino

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ BLECentral bleCentral; // create central instance
2727
BLEPeripheralHelper *blePeripheral1 = NULL;
2828

2929
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service
30-
// create switch characteristic and allow remote device to read and write
31-
BLECharCharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
32-
30+
BLECharCharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);// create switch characteristic and allow remote device to read and write
3331

3432
void bleCentralConnectHandler(BLEHelper& peripheral)
3533
{
@@ -116,8 +114,6 @@ bool adv_found(uint8_t type,
116114
}
117115

118116
void setup() {
119-
Serial1.begin(115200);
120-
121117
Serial.begin(9600);
122118
pinMode(ledPin, OUTPUT); // use the LED on pin 13 as an output
123119

@@ -141,7 +137,7 @@ void setup() {
141137

142138
void loop()
143139
{
144-
static unsigned char counter = 0;
140+
static unsigned int counter = 0;
145141
static char ledstate = 0;
146142
delay(2000);
147143
if (blePeripheral1)

libraries/CurieBLE/examples/Scanning/Scanning.ino

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ bool adv_found(uint8_t type,
9494
}
9595

9696
void setup() {
97-
log_init();
98-
Serial1.begin(115200);
99-
10097
Serial.begin(115200); // initialize serial communication
10198

10299
/* Setup callback */
@@ -106,27 +103,27 @@ void setup() {
106103
It will start continuously scanning BLE advertising
107104
*/
108105
bleCentral.begin();
109-
Serial1.println("Bluetooth device active, start scanning...");
106+
Serial.println("Bluetooth device active, start scanning...");
110107
}
111108

112109
void loop() {
113110
// Output the scanned device per 3s
114111
delay(3000);
115-
Serial1.print("\r\n\r\n\t\t\tScaning result\r\n \tMAC\t\t\t\tLocal Name\r\n");
116-
Serial1.print("-------------------------------------------------------------\r\n");
112+
Serial.print("\r\n\r\n\t\t\tScaning result\r\n \tMAC\t\t\t\tLocal Name\r\n");
113+
Serial.print("-------------------------------------------------------------\r\n");
117114

118115
for (int i = 0; i < list_index; i++)
119116
{
120117

121-
Serial1.print(device_list[i].macaddr);
122-
Serial1.print(" | ");
123-
Serial1.println(device_list[i].loacalname);
118+
Serial.print(device_list[i].macaddr);
119+
Serial.print(" | ");
120+
Serial.println(device_list[i].loacalname);
124121
}
125122
if (list_index == 0)
126123
{
127-
Serial1.print("No device found\r\n");
124+
Serial.print("No device found\r\n");
128125
}
129-
Serial1.print("-------------------------------------------------------------\r\n");
126+
Serial.print("-------------------------------------------------------------\r\n");
130127
adv_list_clear();
131128
}
132129

0 commit comments

Comments
 (0)