Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
RpcDigitalOut.cpp
00001 #include "RpcHandlerBase.h" 00002 00003 namespace MiMic 00004 { 00005 class DigitalOutHandler :RpcHandlerBase 00006 { 00007 public: 00008 static NyLPC_TBool new1(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00009 { 00010 //u 00011 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00012 PinName pin; 00013 if(getParamsAsPin(mod,i_rpc,&pin,1)){ 00014 addNewObjectBatch(mod,i_rpc->method.id,new ModJsonRpc::RpcObject<DigitalOut>(new DigitalOut(pin))); 00015 } 00016 return NyLPC_TBool_TRUE; 00017 } 00018 static NyLPC_TBool new2(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00019 { 00020 //ud return iid 00021 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00022 PinName pin; 00023 if(getParamsAsPin(mod,i_rpc,&pin,1)){ 00024 int v; 00025 if(getParamInt(mod,i_rpc,v,1)){ 00026 addNewObjectBatch(mod,i_rpc->method.id,new ModJsonRpc::RpcObject<DigitalOut>(new DigitalOut(pin,v))); 00027 } 00028 } 00029 return NyLPC_TBool_TRUE; 00030 } 00031 static NyLPC_TBool write(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00032 { 00033 //dd return void 00034 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00035 DigitalOut* inst=(DigitalOut*)getObjectBatch(mod,i_rpc); 00036 if(inst!=NULL){ 00037 int v; 00038 if(getParamInt(mod,i_rpc,v,1)){ 00039 inst->write(v); 00040 mod->putResult(i_rpc->method.id); 00041 } 00042 } 00043 return NyLPC_TBool_TRUE; 00044 } 00045 static NyLPC_TBool read(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00046 { 00047 //d return d 00048 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00049 DigitalOut* inst=(DigitalOut*)getObjectBatch(mod,i_rpc); 00050 if(inst!=NULL){ 00051 mod->putResult(i_rpc->method.id,"%d",(int)(inst->read())); 00052 } 00053 return NyLPC_TBool_TRUE; 00054 } 00055 }; 00056 00057 00058 00059 const static struct NyLPC_TJsonRpcMethodDef func_table[]= 00060 { 00061 { "_new1" ,"u" ,DigitalOutHandler::new1}, 00062 { "_new2" ,"ud" ,DigitalOutHandler::new2}, 00063 { "write" ,"dd" ,DigitalOutHandler::write}, 00064 { "read" ,"d" ,DigitalOutHandler::read}, 00065 { NULL ,NULL ,NULL} 00066 }; 00067 00068 const struct NyLPC_TJsonRpcClassDef MbedJsApi::RPC_MBED_DIGITAL_OUT={ 00069 "mbedJS","DigitalOut",func_table 00070 }; 00071 00072 00073 00074 }
Generated on Tue Jul 12 2022 16:22:59 by
