전시회용
Fork of httpServer-orgel by
Diff: Handler/FsHandler.cpp
- Revision:
- 6:9aefb9ff74ce
- Parent:
- 5:3c24e937da61
- Child:
- 7:d19f02b618d0
--- a/Handler/FsHandler.cpp Wed May 04 00:43:24 2016 +0000 +++ b/Handler/FsHandler.cpp Thu Jun 02 00:58:45 2016 +0000 @@ -3,12 +3,103 @@ #include "FsHandler.h" //#define DEBUG #include "hl_debug.h" +#include "pwm_tone.h" -DigitalOut led_red(LED1); -DigitalOut led_green(LED2); -DigitalOut led_blue(LED3); +PwmOut Buzzer1(D5); +PwmOut Buzzer2(D6); +PwmOut Buzzer3(D11); +PwmOut Buzzer4(D12); -PwmOut myservo(PC_10); +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, + C_6 = 1000000/Do6, + Cs_6 = 1000000/Do6s, + D_6 = 1000000/Re6, + Ds_6 = 1000000/Re6s, + E_6 = 1000000/Mi6, + F_6 = 1000000/Fa6, + Fs_6 = 1000000/Fa6s, + G_6 = 1000000/So6, + Gs_6 = 1000000/So6s, + A_6 = 1000000/La6, + As_6 = 1000000/La6s, + B_6 = 1000000/Ti6; + +int mario1[80] = {E_5,E_5,0,E_5,0,C_5,E_5,0, + G_5,0,0,0,G_4,0,0,0, + C_5,0,0,G_4,0,0,E_4,0, + E_4,A_4,0,B_4,0,As_4,A_4,0, + G_4,E_5,G_5,0,A_5,0,F_5,G_5, + 0,E_5,0,C_5,D_5,B_4,0,0, + C_5,0,0,G_4,0,0,E_4,0, + E_4,A_4,0,B_4,0,As_4,A_4,0, + G_4,E_5,G_5,0,A_5,0,F_5,G_5, + 0,E_5,0,C_5,D_5,B_4,0,0 + }; +int mario2[80] = {Fs_4,F_4,0,F_4,0,F_4,F_4,0, + G_4,0,0,0,0,0,0,0, + E_4,0,0,E_4,0,0,C_4,0, + C_4,C_4,0,D_4,0,Cs_4,C_4,0, + C_4,G_4,B_4,0,C_5,0,A_4,B_4, + 0,G_4,0,E_4,F_4,D_4,0,0, + E_4,0,0,E_4,0,0,C_4,0, + C_4,C_4,0,D_4,0,Cs_4,C_4,0, + C_4,G_4,B_4,0,C_5,0,A_4,B_4, + 0,G_4,0,E_4,F_4,D_4,0,0 + }; +int mario3[80] = {B_4,B_4,0,B_4,0,B_4,B_4,0, + E_5,0,0,0,E_5,0,0,0, + E_5,0,0,C_4,0,0,A_4,0, + A_4,D_5,0,E_5,0,Ds_5,D_5,0, + C_5,A_5,C_6,0,D_6,0,B_5,C_6, + 0,A_5,0,F_5,G_5,E_5,0,0, + E_5,0,0,C_5,0,0,A_4,0, + A_4,D_5,0,E_5,0,Ds_5,D_5,0, + C_5,A_5,C_6,0,D_6,0,B_5,C_6, + 0,A_5,0,F_5,G_5,E_5,0,0 + }; + +//int love1[512] = {G_4,0,0,0,0,0,0,0,0,0,0,0,B_4,0,0,G_4,F_4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,E_4,0,0,0,0,0,0,0,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,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0}; + +int tones_num = 80; +int love_num = 512; static int matchstrings(const char* one, const char* two) { @@ -147,58 +238,83 @@ int HTTPFsRequestHandler::handlePostRequest() { - char ch; - double duty; - myservo.period_ms(20); int pin = 0; + int i; - 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(Buzzer1, C_4, 4); + else if(pin==1) Tune(Buzzer1, Cs_4, 4); + else if(pin==2) Tune(Buzzer1, D_4, 4); + else if(pin==3) Tune(Buzzer1, Ds_4, 4); + else if(pin==4) Tune(Buzzer1, E_4, 4); + else if(pin==5) Tune(Buzzer1, F_4, 4); + else if(pin==6) Tune(Buzzer1, Fs_4, 4); + else if(pin==7) Tune(Buzzer1, G_4, 4); + else if(pin==8) Tune(Buzzer1, Gs_4, 4); + else if(pin==9) Tune(Buzzer1, A_4, 4); + else if(pin==10) Tune(Buzzer1, As_4, 4); + else if(pin==11) Tune(Buzzer1, B_4, 4); + else if(pin==12) Tune(Buzzer1, C_5, 4); + else if(pin==13) Tune(Buzzer1, Cs_5, 4); + else if(pin==14) Tune(Buzzer1, D_5, 4); + else if(pin==15) Tune(Buzzer1, Ds_5, 4); + else if(pin==16) Tune(Buzzer1, E_5, 4); + else if(pin==17) Tune(Buzzer1, F_5, 4); + else if(pin==18) Tune(Buzzer1, Fs_5, 4); + else if(pin==19) Tune(Buzzer1, G_5, 4); + else if(pin==20) Tune(Buzzer1, Gs_5, 4); + else if(pin==21) Tune(Buzzer1, A_5, 4); + else if(pin==22) Tune(Buzzer1, As_5, 4); + else if(pin==23) Tune(Buzzer1, B_5, 4); else { WARN("Wrong pin number"); } return 0; - } - else if( std::string::npos != msg.uri.find("set_dio2.cgi") ) + } + else if( std::string::npos != msg.uri.find("set_AUTO.cgi") ) { - ch = get_http_param_value("pin"); - - if(ch == 0) + pin = get_http_param_value("pin"); + if(pin==0) { - duty = 0.05; - myservo = duty; - printf("duty : %lf\r\n", duty); + for(i=0; i<tones_num; i++) + { + Auto_tunes(Buzzer1, mario1[i], 1); // Auto performance + Auto_tunes(Buzzer2, mario2[i], 1); // Auto performance + Auto_tunes(Buzzer3, mario3[i], 1); // Auto performance + Stop_tunes(Buzzer1); + Stop_tunes(Buzzer2); + Stop_tunes(Buzzer3); + } } - else if(ch == 1) + else if(pin == 1) { - duty = 1; - myservo = duty; - printf("duty : %lf\r\n", duty); - //myservo.pulsewidth_ms(1.0); + for(i=0; i<love_num; i++) + { + //Auto_tunes(Buzzer1, love1[i], 1); // Auto performance + //Auto_tunes(Buzzer2, love2[i], 1); // Auto performance + //Auto_tunes(Buzzer3, love3[i], 1); // Auto performance + //Auto_tunes(Buzzer4, love4[i], 1); // Auto performance + Stop_tunes(Buzzer1); + Stop_tunes(Buzzer2); + Stop_tunes(Buzzer3); + Stop_tunes(Buzzer4); + } } - else if(ch == 2) + else if(pin == 99) { - duty = 0.2; - myservo = duty; - printf("duty : %lf\r\n", duty); - //myservo.pulsewidth_ms(1.0); - } - } + ; + } + else + { + WARN("Wrong pin number"); + } + + return 0; + } else { return 404;