smd.iotkit2.ch / Mbed 2 deprecated RPCHTTPServerSmartHome

Dependencies:   EthernetInterface HttpServer Motor Servo mbed-rtos mbed StepperMotorUni TMP175

Fork of RPCHTTPServerSimple by smd.iotkit2.ch

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RpcClassesExt.h Source File

RpcClassesExt.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2015 Marcel (mc-b) Bernet
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_CLASSES_EXT_H
00017 #define MBED_CLASSES_EXT_H
00018 
00019 #include "rpc.h"
00020 #include "Servo.h"
00021 #include "Motor.h"
00022 #include "StepperMotorUni.h"
00023 #include "TMP175.h"
00024 
00025 namespace mbed 
00026 {
00027 /**
00028  * Temperatur TMP75 Sensor am I2C Bus
00029  */    
00030 class RpcTMP75 : public RPC 
00031 {
00032 public:
00033     RpcTMP75(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) 
00034     {
00035         o.vSetConfigurationTMP175( SHUTDOWN_MODE_OFF | COMPARATOR_MODE | POLARITY_0 |FAULT_QUEUE_6 | RESOLUTION_12, 0x48 );
00036         o.vSetTemperatureLowTMP175( 0.0 );
00037         o.vSetTemperatureHighTMP175( 60.0 );        
00038     }
00039 
00040     int read(void) 
00041     {
00042         return o.fReadTemperatureTMP175();
00043     }
00044 
00045     virtual const struct rpc_method *get_rpc_methods() 
00046     {
00047         static const rpc_method rpc_methods[] = 
00048         {
00049             {"read", rpc_method_caller<int, RpcTMP75, &RpcTMP75::read>},
00050             RPC_METHOD_SUPER(RPC)
00051         };
00052         return rpc_methods;
00053     }
00054     static struct rpc_class *get_rpc_class() 
00055     {
00056         static const rpc_function funcs[] = 
00057         {
00058             {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcTMP75, PinName, PinName, const char*> >},
00059             RPC_METHOD_END
00060         };
00061         static rpc_class c = {"RpcTMP75", funcs, NULL};
00062         return &c;
00063     }
00064 private:
00065     TMP175 o;
00066 };
00067 
00068 /** 
00069  * Servo RPC Template 
00070 */
00071 class RpcServo : public RPC 
00072 {
00073 public:
00074     RpcServo(PinName a0, const char *name=NULL) : RPC(name), o(a0) 
00075     {
00076         // Servo kalibrieren, damit er die vollen 180° verwendet.
00077         o.calibrate ( 0.0009, 180.0);
00078     }
00079 
00080     void write(float a0) {o.write(a0);}
00081     float read(void) {return o.read();}
00082 
00083     virtual const struct rpc_method *get_rpc_methods() 
00084     {
00085         static const rpc_method rpc_methods[] = 
00086         {
00087             {"write", rpc_method_caller<RpcServo, float, &RpcServo::write>},
00088             {"read", rpc_method_caller<float, RpcServo, &RpcServo::read>},
00089             RPC_METHOD_SUPER(RPC)
00090         };
00091         return rpc_methods;
00092     }
00093     static struct rpc_class *get_rpc_class() 
00094     {
00095         static const rpc_function funcs[] = 
00096         {
00097             {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcServo, PinName, const char*> >},
00098             RPC_METHOD_END
00099         };
00100         static rpc_class c = {"RpcServo", funcs, NULL};
00101         return &c;
00102     }
00103 private:
00104     Servo o;
00105 };
00106 
00107 /**
00108  * Motor RPC Template 
00109  */
00110 class RpcMotor : public RPC 
00111 {
00112 public:
00113     RpcMotor(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {}
00114 
00115     void up  () { o.speed(  0.5f ); }
00116     void down() { o.speed( -0.5f ); }
00117     void stop() { o.speed(  0.0f ); }
00118 
00119     virtual const struct rpc_method *get_rpc_methods() 
00120     {
00121         static const rpc_method rpc_methods[] = 
00122         {
00123             {"up", rpc_method_caller<RpcMotor, &RpcMotor::up>},
00124             {"down", rpc_method_caller<RpcMotor, &RpcMotor::down>},
00125             {"stop", rpc_method_caller<RpcMotor, &RpcMotor::stop>},
00126             RPC_METHOD_SUPER(RPC)
00127         };
00128         return rpc_methods;
00129     }
00130     static struct rpc_class *get_rpc_class() 
00131     {
00132         static const rpc_function funcs[] = 
00133         {
00134             {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcMotor, PinName, PinName, PinName, const char*> >},
00135             RPC_METHOD_END
00136         };
00137         static rpc_class c = {"RpcMotor", funcs, NULL};
00138         return &c;
00139     }
00140 private:
00141     Motor o;
00142 };
00143 
00144 /** 
00145  * Stepper motor mbed RPC Template
00146  * HACK: PinName direkt angegeben, weil nur max. 3 Argumente zulaessig sind.
00147  */
00148 class RpcStepper : public RPC 
00149 {
00150 public:
00151     RpcStepper( const char *name=NULL) : RPC(name), o( PTB18, PTB19, PTC1, PTC8 ) 
00152     {
00153         o.set_pps( 300 );
00154     }
00155 
00156     void up  () { o.move_steps(  100 ); }
00157     void down() { o.move_steps( -100 ); }
00158 
00159     virtual const struct rpc_method *get_rpc_methods() 
00160     {
00161         static const rpc_method rpc_methods[] = 
00162         {
00163             {"up", rpc_method_caller<RpcStepper, &RpcStepper::up>},
00164             {"down", rpc_method_caller<RpcStepper, &RpcStepper::down>},
00165             RPC_METHOD_SUPER(RPC)
00166         };
00167         return rpc_methods;
00168     }
00169     static struct rpc_class *get_rpc_class() 
00170     {
00171         static const rpc_function funcs[] = 
00172         {
00173             {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcStepper, const char*> >},
00174             RPC_METHOD_END
00175         };
00176         static rpc_class c = {"RpcStepper", funcs, NULL};
00177         return &c;
00178     }
00179 private:
00180     StepperMotorUni o;
00181 };
00182 
00183 /** 
00184  * RGB LED Strip
00185 */
00186 class RpcLEDStrip : public RPC 
00187 {
00188 public:
00189     RpcLEDStrip(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), r(a0), g(a1), b(a2) {}
00190 
00191     void write( int a0 ) 
00192     {
00193         //printf( "RGB %f, %f, %f\n", 1.0f / 255.0f * ((a0 & 0xFF0000) / 65636), 1.0f / 255.0f * (a0 & 0xFF00) / 256, 1.0f / 255.0f * (a0 & 0xFF) );
00194         r.write( 1.0f / 255.0f * ((a0 & 0xFF0000) / 65636) );
00195         g.write( 1.0f / 255.0f * (a0 & 0xFF00) / 256 );
00196         b.write( 1.0f / 255.0f * (a0 & 0xFF)  );
00197     }
00198 
00199     virtual const struct rpc_method *get_rpc_methods() 
00200     {
00201         static const rpc_method rpc_methods[] = 
00202         {
00203             {"write", rpc_method_caller<RpcLEDStrip, int, &RpcLEDStrip::write>},
00204             RPC_METHOD_SUPER(RPC)
00205         };
00206         return rpc_methods;
00207     }
00208     static struct rpc_class *get_rpc_class() 
00209     {
00210         static const rpc_function funcs[] = 
00211         {
00212             {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcLEDStrip, PinName, PinName, PinName, const char*> >},
00213             RPC_METHOD_END
00214         };
00215         static rpc_class c = {"RpcLEDStrip", funcs, NULL};
00216         return &c;
00217     }
00218 private:
00219     PwmOut r;
00220     PwmOut g;
00221     PwmOut b;
00222 };
00223 
00224 }
00225 
00226 #endif