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

Dependencies:   EthernetNetIf HTTPServer RPCInterface3 mbed

Fork of ethernet_test_http_2 by Yasushi TAUCHI

Committer:
komoritan
Date:
Sat Feb 14 00:23:14 2015 +0000
Revision:
2:20de0d2106cd
Parent:
1:450649df4bd0
Fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
komoritan 1:450649df4bd0 1 /* (c) KDDI Technology
komoritan 1:450649df4bd0 2 *
komoritan 1:450649df4bd0 3 * This Source Code Form is subject to the terms of the Mozilla Public
komoritan 1:450649df4bd0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
komoritan 1:450649df4bd0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
komoritan 1:450649df4bd0 6
yueee_yt 0:c14da41d70ea 7 #include "mbed.h"
yueee_yt 0:c14da41d70ea 8 #include "EthernetNetIf.h"
yueee_yt 0:c14da41d70ea 9 #include "HTTPServer.h"
yueee_yt 0:c14da41d70ea 10 #include "RPCFunction.h"
yueee_yt 0:c14da41d70ea 11
komoritan 1:450649df4bd0 12 AnalogIn gyro1_adc(p16);// ジャイロ(角速度)1
komoritan 1:450649df4bd0 13 AnalogIn gyro2_adc(p17);// ジャイロ(角速度)2
yueee_yt 0:c14da41d70ea 14
yueee_yt 0:c14da41d70ea 15 #if 1
yueee_yt 0:c14da41d70ea 16 /*
yueee_yt 0:c14da41d70ea 17 * Use DHCP
yueee_yt 0:c14da41d70ea 18 */
yueee_yt 0:c14da41d70ea 19 EthernetNetIf ethif;
yueee_yt 0:c14da41d70ea 20 #else
yueee_yt 0:c14da41d70ea 21 /*
yueee_yt 0:c14da41d70ea 22 * Use "static IP address" (Parameters:IP, Subnet mask, Gateway, DNS)
yueee_yt 0:c14da41d70ea 23 */
yueee_yt 0:c14da41d70ea 24 EthernetNetIf ethif(IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx));
yueee_yt 0:c14da41d70ea 25 #endif
yueee_yt 0:c14da41d70ea 26
yueee_yt 0:c14da41d70ea 27 HTTPServer server;
yueee_yt 0:c14da41d70ea 28 LocalFileSystem local("local");
komoritan 1:450649df4bd0 29
komoritan 1:450649df4bd0 30 // 角速度(ジャイロ)情報を返却する
komoritan 1:450649df4bd0 31 void doGetGyro(char* input, char* output);
komoritan 1:450649df4bd0 32 // RPC Interfaceを宣言(getGyro:外部IF公開名、doGetGyro:外部からのコール後、処理する関数名)
komoritan 1:450649df4bd0 33 RPCFunction test(&doGetGyro, "getGyro");
yueee_yt 0:c14da41d70ea 34
yueee_yt 0:c14da41d70ea 35 int main(void) {
yueee_yt 0:c14da41d70ea 36
yueee_yt 0:c14da41d70ea 37 if (ethif.setup()) {
yueee_yt 0:c14da41d70ea 38 error("Ethernet setup failed.");
yueee_yt 0:c14da41d70ea 39 return 1;
yueee_yt 0:c14da41d70ea 40 }
yueee_yt 0:c14da41d70ea 41
yueee_yt 0:c14da41d70ea 42 wait(1);
yueee_yt 0:c14da41d70ea 43 server.addHandler<RPCHandler>("/rpc");
yueee_yt 0:c14da41d70ea 44 FSHandler::mount("/local", "/");
yueee_yt 0:c14da41d70ea 45 server.addHandler<FSHandler>("/");
yueee_yt 0:c14da41d70ea 46 server.bind(80);
yueee_yt 0:c14da41d70ea 47 while (1) {
yueee_yt 0:c14da41d70ea 48 Net::poll();
yueee_yt 0:c14da41d70ea 49 }
yueee_yt 0:c14da41d70ea 50 }
yueee_yt 0:c14da41d70ea 51
komoritan 1:450649df4bd0 52 // 角速度(ジャイロ)情報を返却する
komoritan 1:450649df4bd0 53 void doGetGyro(char* input, char* output) {
komoritan 1:450649df4bd0 54
komoritan 1:450649df4bd0 55 float gy1_data;
komoritan 1:450649df4bd0 56 float gy2_data;
komoritan 1:450649df4bd0 57 gy1_data=gyro1_adc.read(); // ジャイロ1データの読み込み
komoritan 1:450649df4bd0 58 gy2_data=gyro2_adc.read(); // ジャイロ1データの読み込み
komoritan 1:450649df4bd0 59
komoritan 1:450649df4bd0 60 // ジャイロセンサーから取得した値をoutputに対して文字列として設定し、
komoritan 1:450649df4bd0 61 // クライアント側に返却する。
komoritan 1:450649df4bd0 62 sprintf(output, "Gyro1:%2.5f, Gyro2:%2.5f",gy1_data ,gy2_data);
komoritan 1:450649df4bd0 63 }