Library for httpserver
Fork of httpServer_with_Ethernt by
Revision 5:62b15cc96f1b, committed 2017-11-28
- Comitter:
- wiznetw7500
- Date:
- Tue Nov 28 08:54:11 2017 +0000
- Parent:
- 4:2903435e3811
- Commit message:
- Internet Piano
Changed in this revision
Handler/FsHandler.cpp | Show annotated file Show diff for this revision Revisions of this file |
Handler/FsHandler.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2903435e3811 -r 62b15cc96f1b Handler/FsHandler.cpp --- a/Handler/FsHandler.cpp Fri Feb 12 07:39:47 2016 +0000 +++ b/Handler/FsHandler.cpp Tue Nov 28 08:54:11 2017 +0000 @@ -4,13 +4,95 @@ //#define DEBUG #include "hl_debug.h" +#define Do3 131 //C octave3 +#define Do3s 139 //C# +#define Re3 147 //D +#define Re3s 156//D# +#define Mi3 165 //E +#define Fa3 175 //F +#define Fa3s 185 //F# +#define So3 196 //G +#define So3s 208 //G# +#define La3 220 //A +#define La3s 233 //A# +#define Ti3 247 //B +#define Do4 262 //C octave4 +#define Do4s 277 //C# +#define Re4 294 //D +#define Re4s 311//D# +#define Mi4 330 //E +#define Fa4 349 //F +#define Fa4s 370 //F# +#define So4 392 //G +#define So4s 415 //G# +#define La4 440 //A +#define La4s 466 //A# +#define Ti4 494 //B +#define Do5 523 //C octave5 +#define Do5s 554 //C# +#define Re5 587 //D +#define Re5s 622//D# +#define Mi5 659 //E +#define Fa5 699 //F +#define Fa5s 740 //F# +#define So5 784 //G +#define So5s 831 //G# +#define La5 880 //A +#define La5s 932 //A# +#define Ti5 988 //B + +PwmOut Buzzer(D3); + +float C_3 = 1000000/Do3, + Cs_3 = 1000000/Do3s, + D_3 = 1000000/Re3, + Ds_3 = 1000000/Re3s, + E_3 = 1000000/Mi3, + F_3 = 1000000/Fa3, + Fs_3 = 1000000/Fa3s, + G_3 = 1000000/So3, + Gs_3 = 1000000/So3s, + A_3 = 1000000/La3, + As_3 = 1000000/La3s, + B_3 = 1000000/Ti3, + C_4 = 1000000/Do4, + Cs_4 = 1000000/Do4s, + D_4 = 1000000/Re4, + Ds_4 = 1000000/Re4s, + E_4 = 1000000/Mi4, + F_4 = 1000000/Fa4, + Fs_4 = 1000000/Fa4s, + G_4 = 1000000/So4, + Gs_4 = 1000000/So4s, + A_4 = 1000000/La4, + As_4 = 1000000/La4s, + B_4 = 1000000/Ti4, + C_5 = 1000000/Do5, + Cs_5 = 1000000/Do5s, + D_5 = 1000000/Re5, + Ds_5 = 1000000/Re5s, + E_5 = 1000000/Mi5, + F_5 = 1000000/Fa5, + Fs_5 = 1000000/Fa5s, + G_5 = 1000000/So5, + Gs_5 = 1000000/So5s, + A_5 = 1000000/La5, + As_5 = 1000000/La5s, + B_5 = 1000000/Ti5; + +int tones[] = {E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0, D_4, D_4, D_4, 0, E_4, G_4, G_4, 0, + E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0, D_4, D_4, E_4, D_4, C_4, 0, 0, 0}; +int tones_num = 32; + +void Tune(PwmOut name, int period); +void Auto_tunes(PwmOut name, int period); +void Stop_tunes(PwmOut name); + DigitalOut led_red(LED1); DigitalOut led_green(LED2); DigitalOut led_blue(LED3); DigitalIn din(PC_14); -AnalogIn ain0(A0); -AnalogIn ain1(A1); static int matchstrings(const char* one, const char* two) { @@ -61,33 +143,30 @@ { } -std::map<int, EthernetInterface*> HTTPFsRequestHandler::m_eth_list; - int HTTPFsRequestHandler::handleGetRequest() { HTTPHeaders headers; - EthernetInterface test_eth; int retval = 0; //success + uint8_t pin_state; - if( std::string::npos != msg.uri.find("get_netinfo.cgi") ) + if( std::string::npos != msg.uri.find("get_dio14.cgi") ) { - char buf[256]; - - sprintf(buf, "NetinfoCallback({\"mac\":\"%s\",\"ip\":\"%s\",\"sn\":\"%s\",\"gw\":\"%s\",\"temp\":\"%s\"});" - ,m_eth_list[0]->getMACAddress(),m_eth_list[0]->getIPAddress(),m_eth_list[0]->getNetworkMask(),m_eth_list[0]->getGateway()); - - tcp.send(buf, strlen(buf)); + if(din) + pin_state = 1; + else + pin_state = 0; + + /* + *len = sprintf((char *)buf, "DioCallback({\"dio_p\":\"14\",\ + \"dio_s\":\"%d\"\ + });", + pin_state // Digital io status + ); + + + Tcp. + */ } - - else if( std::string::npos != msg.uri.find("get_ain.cgi") ) - { - char buf[256]; - - sprintf(buf, "AinCallback({\"ain_v0\":\"%.3f\",\"ain_v1\":\"%.3f\"});",ain0.read()*100, ain1.read()*100); - - tcp.send(buf, strlen(buf)); - } - else //read html pages { if (m_localPath.length() > 4) @@ -149,31 +228,66 @@ int HTTPFsRequestHandler::handlePostRequest() { - + int i = 0; int pin = 0; - if( std::string::npos != msg.uri.find("set_dio.cgi") ) + if( std::string::npos != msg.uri.find("set_LED.cgi") ) { pin = get_http_param_value("pin"); - if(pin == 8) - { - led_red = get_http_param_value("val"); - } - else if(pin == 9) - { - led_green = get_http_param_value("val"); - } - else if(pin == 5) - { - led_blue = get_http_param_value("val"); - } + if(pin==0) Tune(Buzzer, C_4); + else if(pin==1) Tune(Buzzer, Cs_4); + else if(pin==2) Tune(Buzzer, D_4); + else if(pin==3) Tune(Buzzer, Ds_4); + else if(pin==4) Tune(Buzzer, E_4); + else if(pin==5) Tune(Buzzer, F_4); + else if(pin==6) Tune(Buzzer, Fs_4); + else if(pin==7) Tune(Buzzer, G_4); + else if(pin==8) Tune(Buzzer, Gs_4); + else if(pin==9) Tune(Buzzer, A_4); + else if(pin==10) Tune(Buzzer, As_4); + else if(pin==11) Tune(Buzzer, B_4); + else if(pin==12) Tune(Buzzer, C_5); + else if(pin==13) Tune(Buzzer, Cs_5); + else if(pin==14) Tune(Buzzer, D_5); + else if(pin==15) Tune(Buzzer, Ds_5); + else if(pin==16) Tune(Buzzer, E_5); + else if(pin==17) Tune(Buzzer, F_5); + else if(pin==18) Tune(Buzzer, Fs_5); + else if(pin==19) Tune(Buzzer, G_5); + else if(pin==20) Tune(Buzzer, Gs_5); + else if(pin==21) Tune(Buzzer, A_5); + else if(pin==22) Tune(Buzzer, As_5); + else if(pin==23) Tune(Buzzer, B_5); else { WARN("Wrong pin number"); } return 0; - } + } + else if( std::string::npos != msg.uri.find("set_AUTO.cgi") ) + { + pin = get_http_param_value("pin"); + if(pin==0) + { + for(i=0; i<tones_num; i++) + { + Auto_tunes(Buzzer, tones[i]); + wait_ms(124); + } + Stop_tunes(Buzzer); + } + else if(pin == 99) + { + Stop_tunes(Buzzer); + } + else + { + WARN("Wrong pin number"); + } + + return 0; + } else { return 404; @@ -213,4 +327,34 @@ return ret; } +/** + * @brief Tune Function + * @param name : Choose the PwmOut + period : this param is tune value. (C_3...B_5) + * @retval None + */ +void Tune(PwmOut name, int period) +{ + name.period_us(period); + name.write(0.50f); // 50% duty cycle + wait_ms(250); // 1/4 beat + name.period_us(0); // Sound off +} +/** + * @brief Auto tunes Function + * @param name : Choose the PwmOut + period : this param is tune value. (C_3...B_5) + * @retval None + */ +void Auto_tunes(PwmOut name, int period) +{ + name.period_us(period); + name.write(0.50f); // 50% duty cycle + wait_ms(250); // 1/4 beat +} + +void Stop_tunes(PwmOut name) +{ + name.period_us(0); +}
diff -r 2903435e3811 -r 62b15cc96f1b Handler/FsHandler.h --- a/Handler/FsHandler.h Fri Feb 12 07:39:47 2016 +0000 +++ b/Handler/FsHandler.h Tue Nov 28 08:54:11 2017 +0000 @@ -25,11 +25,8 @@ #include "mbed.h" #include "HTTPRequestHandler.h" -#include "HTTPConnection.h" -#include "EthernetInterface.h" #include <map> -#include <list> #include <string> /** class HTTPFsRequestHandler serves requests with file-system objects @@ -40,7 +37,6 @@ std::string m_localPath; public: - /** constructor for HTTPFsRequestHandler object and stores the request related data locally. * the request handling will be initiated from within the constructor. * @param rootPath : The path under which the handler was registered. @@ -78,15 +74,10 @@ */ static void mount(const char* requestPath, const char* localPath) { m_fsMap[requestPath] = localPath; } - //Test - //static std::list<EthernetInterface> m_eth_list; - static std::map<int, EthernetInterface*> m_eth_list; - static void mount_eth(EthernetInterface* eth) { m_eth_list[0] = eth; } - /** Parse a uri string for uri file name and argument:value pairs */ int parseUriArgs(string uri, map<string, string>& args); uint32_t get_http_param_value(char* param_name); }; -#endif // __FSHANDLER_H__ +#endif // __FSHANDLER_H__ \ No newline at end of file