Fx0とLCDを使用するサンプルです。Ethernet用です。
Dependencies: EthernetNetIf HTTPServer RPCInterface2 TextLCD mbed
Fork of ethernet_test_http_2 by
Diff: main.cpp
- Revision:
- 1:e20fecacd8f6
- Parent:
- 0:c14da41d70ea
--- a/main.cpp Mon May 09 12:34:17 2011 +0000 +++ b/main.cpp Sat Feb 14 00:16:52 2015 +0000 @@ -1,16 +1,15 @@ +/* (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); - +#include "TextLCD.h" +#define TEXTLCD_LEN 16 #if 1 /* * Use DHCP @@ -22,31 +21,35 @@ */ EthernetNetIf ethif(IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx)); #endif + + TextLCD lcd(p24, p26, p27, p28, p29, p30); //LCD HTTPServer server; LocalFileSystem local("local"); - void LcdWrite(char *input,char *output); - RPCFunction rpcFunc(&LcdWrite, "LcdWrite"); + + // LCDディスプレイに文字列を表示させる + void doSetLcd(char* input, char* output); + // RPC Interfaceを宣言(setLcd:外部IF公開名、doSetLcd:外部からのコール後、処理する関数名) + RPCFunction test(&doSetLcd, "setLcd"); int main(void) { - Base::add_rpc_class<DigitalOut>(); - - lcd.cls(); lcd.locate(0,0); - lcd.printf("Program init.. "); + // LCD上段に以下を記載する + lcd.printf("Program start.."); if (ethif.setup()) { error("Ethernet setup failed."); return 1; } + + // IPアドレスを取得 IpAddr ethIp=ethif.getIp(); - + // デフォルトはLCD下段にIPアドレスを表示 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 +57,28 @@ while (1) { Net::poll(); } - return 0; } -void LcdWrite(char *input , char *output) -{ + +// LCDの下段にinputされた文字列を表示する +void doSetLcd(char* input, char* output) { + + lcd.locate(0,1); + // 2行目を全て空白表示とする + for (int i = 0; i < TEXTLCD_LEN; i++){ + lcd.printf(" "); + } + + if (TEXTLCD_LEN < strlen(input)) { + // inputデータが16文字を越える場合には、 + // LCD下段に一律"bad data"表示し、クライアント側に"fail"を返却する + lcd.locate(0,1); + lcd.printf("bad data"); + sprintf(output, "fail"); + } else { + // inputデータが16文字以下の場合には、 + // LCD下段に表示し、クライアント側に"success"を返却する lcd.locate(0,1); lcd.printf("%s",input); + sprintf(output, "success"); + } } -