Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
device_HID_debug_demo/main.c

===== Description =====

This demo monitors the USB port for any Debug messages.
- If "hi" is received, it replies with "Hello"
- If "hello" is received, it replies with "G'Day Mate!"
Use the "Netcruzer USB Terminal" app to send and receive USB Debug messages. It can be downloaded here: https://netcruzer.com/usbterminal/

This demo does not implement any USB code in the main.c file, and instructs the system to do it all. This is done by including the "NZ_USBHID_ENABLE" define in the projdefs.h file.

Details:
The "Netcruzer Library" contains two circular buffer implementations. Any one can be used for this project. The standard one (nz_circularBufferStd.c) is used for this demo, requiring the following to be done(is already done!):

===== Required Hardware =====

The project requires a SBC66 Netcruzer board with an USB Port (not USB Host).

===== Building Project =====

This project is located in the "src/demos/usb/device_HID_debug_demo" folder of the Netcruzer Download. To compile for Netcruzer Board, open this project in MPLAB X, and select the "Project Configuration" for desired board. For example "SBC66ZL_R1" for the SBC66ZL Revision 1 board. For details click here A common error is "The system cannot find the path specified". This generally means you don't have the required XC16 compiler version installed. Go to "Project Properties", and select your installed XC16 compiler in the "Project Configuration" section.

===== Programming Board =====

After compiling (build), the board can be programmed via the USB Bootloader or a PIC Programmer. USB Programming is simplified when using the SBC board together with a Prototype Board.

===== File History =====

2013-07-22, David H. (DH):

#define THIS_IS_MAIN_FILE //Uniquely identifies this as the file with the main application entry function main()
#include "HardwareProfile.h" //Required for all Netcruzer projects
#include "nz_helpers.h"
//Add debugging. DEBUG_CONF_MAIN macro sets debugging to desired level (defined in projdefs.h)
#if !defined(DEBUG_CONF_MAIN)
#define DEBUG_CONF_MAIN DEBUG_CONF_DEFAULT //Default Debug Level, disabled if DEBUG_LEVEL_ALLOFF defined, else DEBUG_LEVEL_ERROR
#endif
#define MY_DEBUG_LEVEL DEBUG_CONF_MAIN
#include "nz_debug.h"
int main(void) {
//Default initialization. All ports inputs. All analog features disabled. Tick 1ms
DEBUG_PUT_STR(DEBUG_LEVEL_INFO, "\nThis is a test debug message");
//Main loop
while (1) {
nzSysTaskDefault(); //Main netcruzer task, call in main loop.
}
}
#if defined(HAS_NZ_DEBUGGING)
void debugService(void) {
//Check if a debug message was received
if (cbufHasWholePacket(CIRBUF_RX_DEBUG)) {
//Check if we received "hi". If so, reply with "Hello" on a new line
if (cbufPacketStrcmp(CIRBUF_RX_DEBUG, "hi") == 0) {
debugPutString("\nHello");
}
//Check if we received "hello". If so, reply with "G'Day Mate!" on a new line
else if (cbufPacketStrcmp(CIRBUF_RX_DEBUG, "hello") == 0) {
debugPutString("\nG'Day Mate!");
}
//Add your custom debug command here....................
else if (cbufPacketStrcmp(CIRBUF_RX_DEBUG, "myString") == 0) {
//Do something.........
}
//Remove received packet. If it was not processed above, it is lost!
cbufRemovePacket(CIRBUF_RX_DEBUG);
}
}
#endif