diff --git a/examples/Example1_NotecardBasics/Example1_NotecardBasics.ino b/examples/Example1_NotecardBasics/Example1_NotecardBasics.ino index 65fb804..3b46fd7 100644 --- a/examples/Example1_NotecardBasics/Example1_NotecardBasics.ino +++ b/examples/Example1_NotecardBasics/Example1_NotecardBasics.ino @@ -69,8 +69,14 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(usbSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // usbSerial // Initialize the physical I/O channel to the Notecard #ifdef txRxPinsSerial @@ -127,7 +133,7 @@ void loop() static unsigned eventCounter = 0; if (++eventCounter > 25) { - notecard.logDebug("Demo cycle complete. Program stopped. Press RESET to restart.\n"); + usbSerial.println("[APP] Demo cycle complete. Program stopped. Press RESET to restart."); delay(10000); // 10 seconds return; } diff --git a/examples/Example2_PeriodicCommunications/Example2_PeriodicCommunications.ino b/examples/Example2_PeriodicCommunications/Example2_PeriodicCommunications.ino index 8cef03f..cdbbca5 100644 --- a/examples/Example2_PeriodicCommunications/Example2_PeriodicCommunications.ino +++ b/examples/Example2_PeriodicCommunications/Example2_PeriodicCommunications.ino @@ -88,8 +88,14 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(usbSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // usbSerial // Initialize the physical I/O channel to the Notecard #ifdef txRxPinsSerial @@ -151,7 +157,7 @@ void loop() if (millis() > lastStatusMs + 10000) { lastStatusMs = millis(); - notecard.logDebug("press button to simulate a sensor measurement\n"); + usbSerial.println("[APP] press button to simulate a sensor measurement"); } delay(25); digitalWrite(ledPin, LOW); @@ -165,7 +171,7 @@ void loop() } // The button was pressed, so we should begin a transaction - notecard.logDebug("performing sensor measurement\n"); + usbSerial.println("[APP] performing sensor measurement"); lastStatusMs = millis(); // Read the notecard's current temperature and voltage, as simulated sensor diff --git a/examples/Example3_InboundPolling/Example3_InboundPolling.ino b/examples/Example3_InboundPolling/Example3_InboundPolling.ino index 6870d8c..e538bc1 100644 --- a/examples/Example3_InboundPolling/Example3_InboundPolling.ino +++ b/examples/Example3_InboundPolling/Example3_InboundPolling.ino @@ -58,8 +58,14 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(usbSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // usbSerial // Initialize the physical I/O channel to the Notecard #ifdef txRxPinsSerial @@ -129,9 +135,9 @@ void loop() { // Simulate Processing the response here - notecard.logDebug("INBOUND REQUEST: "); - notecard.logDebug(JGetString(body, INBOUND_QUEUE_COMMAND_FIELD)); - notecard.logDebug("\n\n"); + usbSerial.print("[APP] INBOUND REQUEST: "); + usbSerial.println(JGetString(body, INBOUND_QUEUE_COMMAND_FIELD)); + usbSerial.println(); } } notecard.deleteResponse(rsp); diff --git a/examples/Example4_InboundInterrupts/Example4_InboundInterrupts.ino b/examples/Example4_InboundInterrupts/Example4_InboundInterrupts.ino index e622e5b..902dd66 100644 --- a/examples/Example4_InboundInterrupts/Example4_InboundInterrupts.ino +++ b/examples/Example4_InboundInterrupts/Example4_InboundInterrupts.ino @@ -71,8 +71,14 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(usbSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // usbSerial // Initialize the physical I/O channel to the Notecard #ifdef txRxPinsSerial @@ -160,7 +166,9 @@ void loop() { // Simulate Processing the response here char *myCommandType = JGetString(body, INBOUND_QUEUE_COMMAND_FIELD); - notecard.logDebugf("INBOUND REQUEST: %s\n\n", myCommandType); + usbSerial.print("[APP] INBOUND REQUEST: "); + usbSerial.println(myCommandType); + usbSerial.println(); } } notecard.deleteResponse(rsp); diff --git a/examples/Example5_UsingTemplates/Example5_UsingTemplates.ino b/examples/Example5_UsingTemplates/Example5_UsingTemplates.ino index 575969d..d4d857d 100644 --- a/examples/Example5_UsingTemplates/Example5_UsingTemplates.ino +++ b/examples/Example5_UsingTemplates/Example5_UsingTemplates.ino @@ -76,8 +76,14 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(usbSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // usbSerial // Initialize the physical I/O channel to the Notecard #ifdef txRxPinsSerial @@ -155,7 +161,7 @@ void loop() static unsigned eventCounter = 0; if (++eventCounter > 25) { - notecard.logDebug("Demo cycle complete. Program stopped. Press RESET to restart.\n"); + usbSerial.println("[APP] Demo cycle complete. Program stopped. Press RESET to restart."); delay(10000); // 10 seconds return; } diff --git a/examples/Example6_SensorTutorial/Example6_SensorTutorial.ino b/examples/Example6_SensorTutorial/Example6_SensorTutorial.ino index 202dd58..79792a8 100644 --- a/examples/Example6_SensorTutorial/Example6_SensorTutorial.ino +++ b/examples/Example6_SensorTutorial/Example6_SensorTutorial.ino @@ -38,8 +38,14 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(usbSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // usbSerial // Initialize the physical I/O channel to the Notecard #ifdef txRxPinsSerial @@ -66,7 +72,7 @@ void loop() static unsigned eventCounter = 0; if (++eventCounter > 25) { - notecard.logDebug("Demo cycle complete. Program stopped. Press RESET to restart.\n"); + usbSerial.println("[APP] Demo cycle complete. Program stopped. Press RESET to restart."); delay(10000); // 10 seconds return; } @@ -74,10 +80,10 @@ void loop() float temperature = sensor.temp(); float humidity = sensor.humidity(); - usbSerial.print("Temperature = "); + usbSerial.print("[APP] Temperature = "); usbSerial.print(temperature); usbSerial.println(" *C"); - usbSerial.print("Humidity = "); + usbSerial.print("[APP] Humidity = "); usbSerial.print(humidity); usbSerial.println(" %"); diff --git a/examples/Example7_PowerControl/Example7_PowerControl.ino b/examples/Example7_PowerControl/Example7_PowerControl.ino index 743f01e..f4163cd 100644 --- a/examples/Example7_PowerControl/Example7_PowerControl.ino +++ b/examples/Example7_PowerControl/Example7_PowerControl.ino @@ -71,8 +71,15 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !txRxSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(txRxSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // txRxSerial + // Initialize the physical I2C I/O channel to the Notecard notecard.begin(); @@ -134,7 +141,7 @@ void loop() // Bump the number of cycles if (++globalState.cycles > 25) { - notecard.logDebug("Demo cycle complete. Program stopped. Press RESET to restart.\n"); + txRxSerial.println("[APP] Demo cycle complete. Program stopped. Press RESET to restart."); delay(10000); // 10 seconds return; } diff --git a/examples/Example8_BinarySendReceive/Example8_BinarySendReceive.ino b/examples/Example8_BinarySendReceive/Example8_BinarySendReceive.ino index 6a64606..61d61fb 100644 --- a/examples/Example8_BinarySendReceive/Example8_BinarySendReceive.ino +++ b/examples/Example8_BinarySendReceive/Example8_BinarySendReceive.ino @@ -42,8 +42,14 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(usbSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // usbSerial // Initialize the physical I/O channel to the Notecard #ifdef txRxPinsSerial @@ -74,7 +80,7 @@ void loop() static unsigned event_counter = 0; if (++event_counter > 5) { - notecard.logDebug("Demo cycle complete. Program stopped. Press RESET to restart.\n"); + usbSerial.println("[APP] Demo cycle complete. Program stopped. Press RESET to restart."); delay(10000); // 10 seconds return; } @@ -89,7 +95,9 @@ void loop() uint32_t data_len = strlen(data); const uint32_t notecard_binary_area_offset = 0; NoteBinaryStoreTransmit(reinterpret_cast(data), data_len, sizeof(data), notecard_binary_area_offset); - notecard.logDebugf("\n[INFO] Transmitted %d bytes.\n", data_len); + usbSerial.print("\n[APP] Transmitted "); + usbSerial.print(data_len); + usbSerial.println(" bytes."); // Log for the sake of curiosity (not necessary for operation) // NOTE: NoteBinaryMaxEncodedLength() is imprecise. It will most @@ -97,15 +105,16 @@ void loop() // However, in this contrived example there is no difference, // so it works for the purposes of displaying the encoded data -- // which would never be done in practice. - notecard.logDebug("\n*** Encoded Binary Transmission ***\n"); + usbSerial.println("\n[APP] *** Encoded Binary Transmission ***"); uint32_t tx_len = NoteBinaryCodecMaxEncodedLength(data_len); for (size_t i = 0 ; i < tx_len ; ++i) { - notecard.logDebugf("%02x ", data[i]); + usbSerial.print(data[i], HEX); + usbSerial.print(" "); if ((i + 1) % 16 == 0) { - notecard.logDebug("\n"); + usbSerial.println(); } } - notecard.logDebug("\n*** Encoded Binary Transmission ***\n\n"); + usbSerial.println("\n[APP] *** Encoded Binary Transmission ***\n"); ///////////////////////////////////////////////// // Receive data from the Notecard binary data store @@ -125,14 +134,16 @@ void loop() // Receive the data NoteBinaryStoreReceive(reinterpret_cast(rx_buffer), rx_buffer_len, 0, data_len); - notecard.logDebugf("\n[INFO] Received %d bytes.\n", data_len); + usbSerial.print("\n[APP] Received "); + usbSerial.print(data_len); + usbSerial.println(" bytes."); // Display received buffer - notecard.logDebug("\n*** Decoded Data ***\n"); + usbSerial.println("\n[APP] *** Decoded Data ***"); for (size_t i = 0 ; i < data_len ; ++i) { - notecard.logDebugf("%c", rx_buffer[i]); + usbSerial.print(rx_buffer[i]); } - notecard.logDebug("\n*** Decoded Data ***\n\n"); + usbSerial.println("\n[APP] *** Decoded Data ***\n"); // Free the receive buffer free(rx_buffer); diff --git a/examples/Example9_BinarySendReceiveChunked/Example9_BinarySendReceiveChunked.ino b/examples/Example9_BinarySendReceiveChunked/Example9_BinarySendReceiveChunked.ino index e54bd34..c9951ca 100644 --- a/examples/Example9_BinarySendReceiveChunked/Example9_BinarySendReceiveChunked.ino +++ b/examples/Example9_BinarySendReceiveChunked/Example9_BinarySendReceiveChunked.ino @@ -42,8 +42,14 @@ void setup() const size_t usb_timeout_ms = 3000; for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;) ; + + // For low-memory platforms, don't turn on internal Notecard logs. +#ifndef NOTE_C_LOW_MEM notecard.setDebugOutputStream(usbSerial); -#endif +#else +#pragma message("INFO: Notecard debug logs disabled. (non-fatal)") +#endif // !NOTE_C_LOW_MEM +#endif // usbSerial // Initialize the physical I/O channel to the Notecard #ifdef txRxPinsSerial @@ -74,7 +80,7 @@ void loop() static unsigned event_counter = 0; if (++event_counter > 5) { - notecard.logDebug("Demo cycle complete. Program stopped. Press RESET to restart.\n"); + usbSerial.println("[APP] Demo cycle complete. Program stopped. Press RESET to restart."); delay(10000); // 10 seconds return; } @@ -114,16 +120,22 @@ void loop() memcpy(tx_buffer, (data_source + notecard_binary_area_offset), data_len); // Transmit the chunk - notecard.logDebugf("Transmitting chunk #%d, containing %d bytes.\n", chunk, data_len); + usbSerial.print("[APP] Transmitting chunk #"); + usbSerial.print(chunk); + usbSerial.print(", containing "); + usbSerial.print(data_len); + usbSerial.println(" bytes."); if (NoteBinaryStoreTransmit(reinterpret_cast(tx_buffer), data_len, tx_buffer_len, notecard_binary_area_offset)) { --chunk; - notecard.logDebug("Failed to transmit.\n"); + usbSerial.println("[APP] Failed to transmit."); continue; } // Update the offset notecard_binary_area_offset += data_len; - notecard.logDebugf("[INFO] Transmitted %d bytes.\n", data_len); + usbSerial.print("[APP] Transmitted "); + usbSerial.print(data_len); + usbSerial.println(" bytes."); // Log for the sake of curiosity (not necessary for operation) // NOTE: NoteBinaryMaxEncodedLength() is imprecise. It will most @@ -131,15 +143,16 @@ void loop() // encoded. However, in this contrived example there is no // difference, so it works for the purposes of displaying the // encoded data -- which would never be done in practice. - notecard.logDebug("\n*** Encoded Binary Transmission ***\n"); + usbSerial.println("\n[APP] *** Encoded Binary Transmission ***"); uint32_t tx_len = NoteBinaryCodecMaxEncodedLength(data_len); for (size_t i = 0 ; i < tx_len ; ++i) { - notecard.logDebugf("%02x ", tx_buffer[i]); + usbSerial.print(tx_buffer[i], HEX); + usbSerial.print(" "); if ((i + 1) % 16 == 0) { - notecard.logDebug("\n"); + usbSerial.println(); } } - notecard.logDebug("\n*** Encoded Binary Transmission ***\n\n"); + usbSerial.println("\n[APP] *** Encoded Binary Transmission ***\n"); } // Free the transmit buffer @@ -177,10 +190,14 @@ void loop() : (rx_data_len - notecard_binary_area_offset)); // Receive the chunk - notecard.logDebugf("Receiving chunk #%d, containing %d bytes.\n", chunk, rx_len); + usbSerial.print("[APP] Receiving chunk #"); + usbSerial.print(chunk); + usbSerial.print(", containing "); + usbSerial.print(rx_len); + usbSerial.println(" bytes."); if (NoteBinaryStoreReceive(reinterpret_cast(rx_buffer), rx_buffer_len, notecard_binary_area_offset, rx_len)) { --chunk; - notecard.logDebug("Failed to receive.\n"); + usbSerial.println("[APP] Failed to receive."); continue; } @@ -192,22 +209,25 @@ void loop() // Update the offset notecard_binary_area_offset += rx_len; - notecard.logDebugf("[INFO] Received %d bytes.\n", rx_len); + usbSerial.print("\n[APP] Received "); + usbSerial.print(rx_len); + usbSerial.println(" bytes."); // Log for the sake of curiosity - notecard.logDebug("*** Decoded Binary Data ***\n"); + usbSerial.println("[APP] *** Decoded Binary Data ***"); for (size_t i = 0 ; i < rx_len ; ++i) { - notecard.logDebugf("%02x ", rx_buffer[i]); + usbSerial.print(rx_buffer[i], HEX); + usbSerial.print(" "); } - notecard.logDebug("\n*** Decoded Binary Data ***\n\n"); + usbSerial.println("\n[APP] *** Decoded Binary Data ***\n"); } // Display complete buffer - notecard.logDebug("*** Decoded Data ***\n"); + usbSerial.println("[APP] *** Decoded Data ***"); for (size_t i = 0 ; i < rx_data_len ; ++i) { - notecard.logDebugf("%c", data_store[i]); + usbSerial.print(data_store[i]); } - notecard.logDebug("\n*** Decoded Data ***\n\n"); + usbSerial.println("\n[APP] *** Decoded Data ***\n"); // Free the receive buffer free(rx_buffer);