A test of creating custom classes for control over RPC. Creates an LED class with member functions callable over serial.
Diff: main.cpp
- Revision:
- 1:ddf1739fcbb8
- Parent:
- 0:b0ab03e03fdc
- Child:
- 2:fe4c1d5a97fa
--- a/main.cpp Wed Sep 29 01:09:48 2010 +0000 +++ b/main.cpp Wed Sep 29 01:20:59 2010 +0000 @@ -53,15 +53,13 @@ }; - -LED::LED(PinName mypin, const char *name) : Base(name), LEDpin(mypin) { //initialize pin - /*Initialization Function*/ +/**Initialization Function**/ +LED::LED(PinName mypin, const char *name) : Base(name), LEDpin(mypin) { //initialize pin LEDpin.write(0); state=false; //set LED to off } - -int LED::toggle() { - /*switch the state of the LED*/ +/**switch the state of the LED**/ +int LED::toggle() { if (state==0) { state=1; } else { @@ -71,8 +69,8 @@ return state; //print the current state of the LED } -void LED::blink(int n=1) { - /*blink the LED n times*/ +/**blink the LED n times**/ +void LED::blink(int n=1) { do { //blink at least once toggle(); //toggle LED state wait(.2); @@ -84,8 +82,8 @@ #ifdef MBED_RPC -const rpc_method *LED::get_rpc_methods() { - /*Create a list of the available methods which can be called for this class*/ +/**Create a list of the available methods which can be called for this class**/ +const rpc_method *LED::get_rpc_methods() { static const rpc_method rpc_methods[] = { { "toggle", rpc_method_caller<int, LED, &LED::toggle> }, //first specify the name string. The arguments to rpc_method_caller appear to be <outputs, RPC class, inputs, reference to function>. //In this case, we have one output and no inputs so they are skipped. We must only specify the class of the object the method belongs to and the address of the method. @@ -95,9 +93,8 @@ }; return rpc_methods; } - -rpc_class *LED::get_rpc_class() { - /*Register the class itself as an RPC-callable class*/ +/**Register the class itself as an RPC-callable class**/ +rpc_class *LED::get_rpc_class() { static const rpc_function funcs[] = { { "new", rpc_function_caller<const char*, PinName, const char*, &Base::construct<LED,PinName,const char*> > }, //still don't fully understand the arguments in this line. I suppose the first argument may just be an output echo of the name. RPC_METHOD_END @@ -115,8 +112,8 @@ Serial pc(USBTX, USBRX); //set up serial communication -int main() { - /*Wait for RPC commands and then call the */ +/**Wait for RPC commands and then call the interpreter**/ +int main() { // specify which classes we would like to be able to call over LED Base::add_rpc_class<Timer>(); //a class included in the core mbed RPC library