Ergänzt das jQueryMobile Beispiel um die Fehlenden Aktoren wie LED 3 und Servo 2.

Fork of RPCHTTPServerVariable by smd.iotkit2.ch

Committer:
stefan1691
Date:
Wed Apr 08 12:31:28 2015 +0000
Revision:
14:3835863bc412
Korrektur AnalogIn laut . https://developer.mbed.org/questions/3897/AnalogIn-not-working-in-rpc/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stefan1691 14:3835863bc412 1 /* mbed Microcontroller Library
stefan1691 14:3835863bc412 2 * Copyright (c) 2006-2013 ARM Limited
stefan1691 14:3835863bc412 3 *
stefan1691 14:3835863bc412 4 * Licensed under the Apache License, Version 2.0 (the "License");
stefan1691 14:3835863bc412 5 * you may not use this file except in compliance with the License.
stefan1691 14:3835863bc412 6 * You may obtain a copy of the License at
stefan1691 14:3835863bc412 7 *
stefan1691 14:3835863bc412 8 * http://www.apache.org/licenses/LICENSE-2.0
stefan1691 14:3835863bc412 9 *
stefan1691 14:3835863bc412 10 * Unless required by applicable law or agreed to in writing, software
stefan1691 14:3835863bc412 11 * distributed under the License is distributed on an "AS IS" BASIS,
stefan1691 14:3835863bc412 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
stefan1691 14:3835863bc412 13 * See the License for the specific language governing permissions and
stefan1691 14:3835863bc412 14 * limitations under the License.
stefan1691 14:3835863bc412 15 */
stefan1691 14:3835863bc412 16 #ifndef RPCVARIABLE_H_
stefan1691 14:3835863bc412 17 #define RPCVARIABLE_H_
stefan1691 14:3835863bc412 18
stefan1691 14:3835863bc412 19 #include "rpc.h"
stefan1691 14:3835863bc412 20
stefan1691 14:3835863bc412 21 namespace mbed {
stefan1691 14:3835863bc412 22
stefan1691 14:3835863bc412 23 /**
stefan1691 14:3835863bc412 24 *Class to read and set an attached variable using the RPC
stefan1691 14:3835863bc412 25 *
stefan1691 14:3835863bc412 26 */
stefan1691 14:3835863bc412 27 template<class T>
stefan1691 14:3835863bc412 28 class RPCVariable: public RPC {
stefan1691 14:3835863bc412 29 public:
stefan1691 14:3835863bc412 30 /**
stefan1691 14:3835863bc412 31 * Constructor
stefan1691 14:3835863bc412 32 *
stefan1691 14:3835863bc412 33 *@param ptr Pointer to the variable to make accessible over RPC. Any type of
stefan1691 14:3835863bc412 34 *variable can be connected
stefan1691 14:3835863bc412 35 *@param name The name of that this object will be over RPC
stefan1691 14:3835863bc412 36 */
stefan1691 14:3835863bc412 37 template<class A>
stefan1691 14:3835863bc412 38 RPCVariable(A * ptr, const char * name) : RPC(name) {
stefan1691 14:3835863bc412 39 _ptr = ptr;
stefan1691 14:3835863bc412 40 }
stefan1691 14:3835863bc412 41 /**
stefan1691 14:3835863bc412 42 *Read the variable over RPC.
stefan1691 14:3835863bc412 43 *
stefan1691 14:3835863bc412 44 *@return The value of the variable
stefan1691 14:3835863bc412 45 */
stefan1691 14:3835863bc412 46 T read() {
stefan1691 14:3835863bc412 47 return (*_ptr);
stefan1691 14:3835863bc412 48 }
stefan1691 14:3835863bc412 49 /**
stefan1691 14:3835863bc412 50 *Write a value to the variable over RPC
stefan1691 14:3835863bc412 51 *
stefan1691 14:3835863bc412 52 *@param The value to be written to the attached variable.
stefan1691 14:3835863bc412 53 */
stefan1691 14:3835863bc412 54 void write(T value) {
stefan1691 14:3835863bc412 55 *_ptr = value;
stefan1691 14:3835863bc412 56 }
stefan1691 14:3835863bc412 57
stefan1691 14:3835863bc412 58 virtual const struct rpc_method *get_rpc_methods();
stefan1691 14:3835863bc412 59 static struct rpc_class *get_rpc_class();
stefan1691 14:3835863bc412 60
stefan1691 14:3835863bc412 61 private:
stefan1691 14:3835863bc412 62 T * _ptr;
stefan1691 14:3835863bc412 63 };
stefan1691 14:3835863bc412 64
stefan1691 14:3835863bc412 65 template<class T>
stefan1691 14:3835863bc412 66 const rpc_method *RPCVariable<T>::get_rpc_methods() {
stefan1691 14:3835863bc412 67 static const rpc_method rpc_methods[] = {
stefan1691 14:3835863bc412 68 {"read" , rpc_method_caller<T, RPCVariable, &RPCVariable::read> },
stefan1691 14:3835863bc412 69 {"write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> },
stefan1691 14:3835863bc412 70 RPC_METHOD_SUPER(RPC)
stefan1691 14:3835863bc412 71 };
stefan1691 14:3835863bc412 72 return rpc_methods;
stefan1691 14:3835863bc412 73 }
stefan1691 14:3835863bc412 74
stefan1691 14:3835863bc412 75 template<class T>
stefan1691 14:3835863bc412 76 rpc_class *RPCVariable<T>::get_rpc_class() {
stefan1691 14:3835863bc412 77 static const rpc_function funcs[] = {
stefan1691 14:3835863bc412 78 "new", rpc_function_caller<const char*, T, const char*, &RPC::construct<RPCVariable, T, const char*> > ,
stefan1691 14:3835863bc412 79 RPC_METHOD_END
stefan1691 14:3835863bc412 80 };
stefan1691 14:3835863bc412 81 static rpc_class c = {"RPCVariable", funcs, NULL};
stefan1691 14:3835863bc412 82 return &c;
stefan1691 14:3835863bc412 83 }
stefan1691 14:3835863bc412 84
stefan1691 14:3835863bc412 85 }
stefan1691 14:3835863bc412 86
stefan1691 14:3835863bc412 87 #endif //RPCVARIABLE_H_