Test program to demonstrate usage of uTerminal library
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
Go to the documentation of this file.
00001 /** 00002 * @file main.cpp 00003 * uTerminal_Example is a simple example demonstrating how to 00004 * use the uTerminal library. 00005 * 00006 * @author Fernando Cosentino 00007 */ 00008 00009 #include "mbed.h" 00010 #include "uTerminal.h" 00011 00012 //================================================================ 00013 // INSTANCING THE TERMINAL: 00014 00015 /* 00016 // Create a Serial object yourself 00017 Serial pc(P0_19, P0_18); // TX, RX pins for board n-DAP 00018 uTerminal terminal(&pc); // argument is the address of a Serial object 00019 */ 00020 00021 // or... 00022 // This will automatically create an internal Serial object 00023 //uTerminal terminal(P0_19, P0_18); // TX, RX pins for board n-DAP 00024 00025 // or... 00026 // Create a USBSerial object yourself (works with blocking and non-blocking) 00027 //USBSerial pc; // blocking 00028 USBSerial pc(0x1f00, 0x2012, 0x0001, false); // non-blocking 00029 uTerminal terminal(&pc); // argument is the address of a USBSerial object 00030 00031 //================================================================ 00032 00033 00034 char sbuf[1024]; // useb by sprintf 00035 00036 /** 00037 * Callback called to process a message received by uTerminal 00038 * If Auto-mode is used, this is called whenever a message arrives. 00039 * Otherwise, called whenever termina.Process() is polled. 00040 */ 00041 00042 void msg_received() { 00043 int i; 00044 00045 terminal.print("Received:\n"); 00046 terminal.print(terminal.Command); 00047 terminal.print(" = "); 00048 terminal.print(terminal.Value); 00049 terminal.print("\n"); 00050 00051 sprintf(sbuf, "NumParams: %d\n", terminal.NumParams); 00052 terminal.print(sbuf); 00053 00054 for (i=0; i<terminal.NumParams; i++) { 00055 sprintf(sbuf, "Param %d = ", i); 00056 terminal.print(sbuf); 00057 terminal.GetParam(); 00058 terminal.print(terminal.Param); 00059 terminal.print("\n"); 00060 } 00061 } 00062 00063 00064 /** 00065 * Main loop 00066 */ 00067 int main() { 00068 00069 // Attach the callback. This is optional, you can inspect the 00070 // member objects Command, Value and Param from anywhere. 00071 // But this is convenient 00072 terminal.attach(&msg_received); 00073 00074 // Uncomment below for auto-mode (fires interrupt whenever there is a message) 00075 terminal.ModeAuto(); 00076 00077 // Uncomment below for manual mode (polled) 00078 //terminal.ModeManual(); // optional since default is manual mode 00079 00080 // Warn user the program is running 00081 terminal.print("\nInitialised!\n\n"); 00082 00083 while(1) { 00084 /* 00085 // Polled (manual) version: 00086 if (terminal.Process()) { 00087 // you can actually call msg_received() from here yourself, 00088 // if the callback feature is not used. 00089 terminal.print("Processed!\n"); 00090 } 00091 */ 00092 } 00093 }
Generated on Fri Jul 22 2022 00:21:19 by
1.7.2