Fx0と加速度センサーを使用するサンプルです。Ethernet用です。

Dependencies:   EthernetNetIf HTTPServer RPCInterface3 mbed

Fork of ethernet_test_http_2 by Yasushi TAUCHI

Revision:
1:450649df4bd0
Parent:
0:c14da41d70ea
--- a/main.cpp	Mon May 09 12:34:17 2011 +0000
+++ b/main.cpp	Sat Feb 14 00:22:23 2015 +0000
@@ -1,15 +1,16 @@
+/* (c) KDDI Technology
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
 #include "mbed.h"
-#include "TextLCD.h"
 #include "EthernetNetIf.h"
 #include "HTTPServer.h"
 #include "RPCFunction.h"
 
-DigitalOut led1(LED1,"led1");
-DigitalOut led2(LED2,"led2");
-DigitalOut led3(LED3,"led3");
-DigitalOut led4(LED4,"led4");
-
-TextLCD lcd(p24, p26, p27, p28, p29, p30);
+AnalogIn gyro1_adc(p16);// ジャイロ(角速度)1
+AnalogIn gyro2_adc(p17);// ジャイロ(角速度)2
 
 #if 1
 /*
@@ -25,28 +26,20 @@
     
     HTTPServer server;
     LocalFileSystem local("local");
-    void LcdWrite(char *input,char *output);
-    RPCFunction rpcFunc(&LcdWrite, "LcdWrite");
+
+    // 角速度(ジャイロ)情報を返却する
+    void doGetGyro(char* input, char* output);
+    // RPC Interfaceを宣言(getGyro:外部IF公開名、doGetGyro:外部からのコール後、処理する関数名)
+    RPCFunction test(&doGetGyro, "getGyro");
 
 int main(void) {
 
-    Base::add_rpc_class<DigitalOut>();
-
-    lcd.cls();
-    lcd.locate(0,0);
-    lcd.printf("Program init..  ");
-
     if (ethif.setup()) {
         error("Ethernet setup failed.");
         return 1;
     }
-    IpAddr ethIp=ethif.getIp();
     
-    lcd.locate(0,1);
-    lcd.printf("%d.%d.%d.%d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
-    led1=1;
     wait(1);
-    server.addHandler<SimpleHandler>("/hello");
     server.addHandler<RPCHandler>("/rpc");
     FSHandler::mount("/local", "/");
     server.addHandler<FSHandler>("/");
@@ -54,11 +47,17 @@
     while (1) {
         Net::poll();
     }
-    return 0;
-}
-void LcdWrite(char *input , char *output)
-{
-    lcd.locate(0,1);
-    lcd.printf("%s",input);
 }
 
+// 角速度(ジャイロ)情報を返却する
+void doGetGyro(char* input, char* output) {
+
+  float gy1_data;
+  float gy2_data;
+  gy1_data=gyro1_adc.read(); // ジャイロ1データの読み込み
+  gy2_data=gyro2_adc.read(); // ジャイロ1データの読み込み
+  
+  // ジャイロセンサーから取得した値をoutputに対して文字列として設定し、
+  // クライアント側に返却する。
+  sprintf(output, "Gyro1:%2.5f, Gyro2:%2.5f",gy1_data ,gy2_data);
+}