httpserver for Internet piano

Dependents:   Internet-Piano_WIZwiki-W7500 Internet-Piano_India_Academy

Fork of httpServer by IOP

Committer:
justinkim
Date:
Fri Jul 03 07:32:27 2015 +0000
Revision:
1:8291b3e9c064
Parent:
0:e59cc54df17c
Child:
3:4c09c3f44a8f
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hjjeon 0:e59cc54df17c 1 /* FsHandler.cpp */
hjjeon 0:e59cc54df17c 2 #include "mbed.h"
hjjeon 0:e59cc54df17c 3 #include "FsHandler.h"
hjjeon 0:e59cc54df17c 4 //#define DEBUG
hjjeon 0:e59cc54df17c 5 #include "hl_debug.h"
hjjeon 0:e59cc54df17c 6
justinkim 1:8291b3e9c064 7 #define Do3 131 //C octave3
justinkim 1:8291b3e9c064 8 #define Do3s 139 //C#
justinkim 1:8291b3e9c064 9 #define Re3 147 //D
justinkim 1:8291b3e9c064 10 #define Re3s 156//D#
justinkim 1:8291b3e9c064 11 #define Mi3 165 //E
justinkim 1:8291b3e9c064 12 #define Fa3 175 //F
justinkim 1:8291b3e9c064 13 #define Fa3s 185 //F#
justinkim 1:8291b3e9c064 14 #define So3 196 //G
justinkim 1:8291b3e9c064 15 #define So3s 208 //G#
justinkim 1:8291b3e9c064 16 #define La3 220 //A
justinkim 1:8291b3e9c064 17 #define La3s 233 //A#
justinkim 1:8291b3e9c064 18 #define Ti3 247 //B
justinkim 1:8291b3e9c064 19 #define Do4 262 //C octave4
justinkim 1:8291b3e9c064 20 #define Do4s 277 //C#
justinkim 1:8291b3e9c064 21 #define Re4 294 //D
justinkim 1:8291b3e9c064 22 #define Re4s 311//D#
justinkim 1:8291b3e9c064 23 #define Mi4 330 //E
justinkim 1:8291b3e9c064 24 #define Fa4 349 //F
justinkim 1:8291b3e9c064 25 #define Fa4s 370 //F#
justinkim 1:8291b3e9c064 26 #define So4 392 //G
justinkim 1:8291b3e9c064 27 #define So4s 415 //G#
justinkim 1:8291b3e9c064 28 #define La4 440 //A
justinkim 1:8291b3e9c064 29 #define La4s 466 //A#
justinkim 1:8291b3e9c064 30 #define Ti4 494 //B
justinkim 1:8291b3e9c064 31 #define Do5 523 //C octave5
justinkim 1:8291b3e9c064 32 #define Do5s 554 //C#
justinkim 1:8291b3e9c064 33 #define Re5 587 //D
justinkim 1:8291b3e9c064 34 #define Re5s 622//D#
justinkim 1:8291b3e9c064 35 #define Mi5 659 //E
justinkim 1:8291b3e9c064 36 #define Fa5 699 //F
justinkim 1:8291b3e9c064 37 #define Fa5s 740 //F#
justinkim 1:8291b3e9c064 38 #define So5 784 //G
justinkim 1:8291b3e9c064 39 #define So5s 831 //G#
justinkim 1:8291b3e9c064 40 #define La5 880 //A
justinkim 1:8291b3e9c064 41 #define La5s 932 //A#
justinkim 1:8291b3e9c064 42 #define Ti5 988 //B
justinkim 1:8291b3e9c064 43
justinkim 1:8291b3e9c064 44 PwmOut Buzzer(D5);
justinkim 1:8291b3e9c064 45
justinkim 1:8291b3e9c064 46 float C_3 = 1000000/Do3,
justinkim 1:8291b3e9c064 47 Cs_3 = 1000000/Do3s,
justinkim 1:8291b3e9c064 48 D_3 = 1000000/Re3,
justinkim 1:8291b3e9c064 49 Ds_3 = 1000000/Re3s,
justinkim 1:8291b3e9c064 50 E_3 = 1000000/Mi3,
justinkim 1:8291b3e9c064 51 F_3 = 1000000/Fa3,
justinkim 1:8291b3e9c064 52 Fs_3 = 1000000/Fa3s,
justinkim 1:8291b3e9c064 53 G_3 = 1000000/So3,
justinkim 1:8291b3e9c064 54 Gs_3 = 1000000/So3s,
justinkim 1:8291b3e9c064 55 A_3 = 1000000/La3,
justinkim 1:8291b3e9c064 56 As_3 = 1000000/La3s,
justinkim 1:8291b3e9c064 57 B_3 = 1000000/Ti3,
justinkim 1:8291b3e9c064 58 C_4 = 1000000/Do4,
justinkim 1:8291b3e9c064 59 Cs_4 = 1000000/Do4s,
justinkim 1:8291b3e9c064 60 D_4 = 1000000/Re4,
justinkim 1:8291b3e9c064 61 Ds_4 = 1000000/Re4s,
justinkim 1:8291b3e9c064 62 E_4 = 1000000/Mi4,
justinkim 1:8291b3e9c064 63 F_4 = 1000000/Fa4,
justinkim 1:8291b3e9c064 64 Fs_4 = 1000000/Fa4s,
justinkim 1:8291b3e9c064 65 G_4 = 1000000/So4,
justinkim 1:8291b3e9c064 66 Gs_4 = 1000000/So4s,
justinkim 1:8291b3e9c064 67 A_4 = 1000000/La4,
justinkim 1:8291b3e9c064 68 As_4 = 1000000/La4s,
justinkim 1:8291b3e9c064 69 B_4 = 1000000/Ti4,
justinkim 1:8291b3e9c064 70 C_5 = 1000000/Do5,
justinkim 1:8291b3e9c064 71 Cs_5 = 1000000/Do5s,
justinkim 1:8291b3e9c064 72 D_5 = 1000000/Re5,
justinkim 1:8291b3e9c064 73 Ds_5 = 1000000/Re5s,
justinkim 1:8291b3e9c064 74 E_5 = 1000000/Mi5,
justinkim 1:8291b3e9c064 75 F_5 = 1000000/Fa5,
justinkim 1:8291b3e9c064 76 Fs_5 = 1000000/Fa5s,
justinkim 1:8291b3e9c064 77 G_5 = 1000000/So5,
justinkim 1:8291b3e9c064 78 Gs_5 = 1000000/So5s,
justinkim 1:8291b3e9c064 79 A_5 = 1000000/La5,
justinkim 1:8291b3e9c064 80 As_5 = 1000000/La5s,
justinkim 1:8291b3e9c064 81 B_5 = 1000000/Ti5;
justinkim 1:8291b3e9c064 82
justinkim 1:8291b3e9c064 83 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,
justinkim 1:8291b3e9c064 84 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};
justinkim 1:8291b3e9c064 85 int tones_num = 32;
justinkim 1:8291b3e9c064 86
justinkim 1:8291b3e9c064 87 void Tune(PwmOut name, int period);
justinkim 1:8291b3e9c064 88 void Auto_tunes(PwmOut name, int period);
justinkim 1:8291b3e9c064 89 void Stop_tunes(PwmOut name);
justinkim 1:8291b3e9c064 90
hjjeon 0:e59cc54df17c 91 DigitalOut led_red(LED1);
hjjeon 0:e59cc54df17c 92 DigitalOut led_green(LED2);
hjjeon 0:e59cc54df17c 93 DigitalOut led_blue(LED3);
hjjeon 0:e59cc54df17c 94
hjjeon 0:e59cc54df17c 95 DigitalIn din(PC_14);
hjjeon 0:e59cc54df17c 96
hjjeon 0:e59cc54df17c 97 static int matchstrings(const char* one, const char* two)
hjjeon 0:e59cc54df17c 98 {
hjjeon 0:e59cc54df17c 99 int m = 0;
hjjeon 0:e59cc54df17c 100
hjjeon 0:e59cc54df17c 101 for (m = 0; m < min(strlen(one), strlen(two)) ; m++) {
hjjeon 0:e59cc54df17c 102 if (one[m] != two[m])
hjjeon 0:e59cc54df17c 103 return m;
hjjeon 0:e59cc54df17c 104 }
hjjeon 0:e59cc54df17c 105 return m;
hjjeon 0:e59cc54df17c 106 }
hjjeon 0:e59cc54df17c 107
hjjeon 0:e59cc54df17c 108 std::map<const char*, const char*> HTTPFsRequestHandler::m_fsMap;
hjjeon 0:e59cc54df17c 109
hjjeon 0:e59cc54df17c 110 HTTPFsRequestHandler::HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp)
hjjeon 0:e59cc54df17c 111 : HTTPRequestHandler(Msg, Tcp)
hjjeon 0:e59cc54df17c 112 {
hjjeon 0:e59cc54df17c 113 m_rootPath = rootPath;
hjjeon 0:e59cc54df17c 114 m_localPath = localPath;
hjjeon 0:e59cc54df17c 115
hjjeon 0:e59cc54df17c 116 string myPath = m_rootPath + m_localPath;
hjjeon 0:e59cc54df17c 117
hjjeon 0:e59cc54df17c 118 // Now replace the virtual root path with a mounted device path
hjjeon 0:e59cc54df17c 119 std::map<const char*, const char*>::iterator it;
hjjeon 0:e59cc54df17c 120 const char *bestMatch = NULL;
hjjeon 0:e59cc54df17c 121 const char *bestMatchExchange = NULL;
hjjeon 0:e59cc54df17c 122 int match_ind = -1;
hjjeon 0:e59cc54df17c 123 for (it = m_fsMap.begin() ; it != m_fsMap.end() ; it++) {
hjjeon 0:e59cc54df17c 124 // find best match (if the given logical path is containted in the root
hjjeon 0:e59cc54df17c 125 int s = matchstrings(myPath.c_str(), it->second);
hjjeon 0:e59cc54df17c 126 INFO("Matching Root %s with handler %s results in %d identical characters\n", myPath.c_str(), it->second, s);
hjjeon 0:e59cc54df17c 127 if ((s == strlen(it->second)) && (s > match_ind)) {
hjjeon 0:e59cc54df17c 128 match_ind = s;
hjjeon 0:e59cc54df17c 129 bestMatch = it->first;
hjjeon 0:e59cc54df17c 130 bestMatchExchange = it->second;
hjjeon 0:e59cc54df17c 131 }
hjjeon 0:e59cc54df17c 132 }
hjjeon 0:e59cc54df17c 133
hjjeon 0:e59cc54df17c 134 if (bestMatch != NULL) {
hjjeon 0:e59cc54df17c 135 m_rootPath = bestMatch;
hjjeon 0:e59cc54df17c 136 m_localPath = string(myPath).substr(strlen(bestMatchExchange));
hjjeon 0:e59cc54df17c 137 }
hjjeon 0:e59cc54df17c 138
hjjeon 0:e59cc54df17c 139 handleRequest();
hjjeon 0:e59cc54df17c 140 }
hjjeon 0:e59cc54df17c 141
hjjeon 0:e59cc54df17c 142 HTTPFsRequestHandler::~HTTPFsRequestHandler()
hjjeon 0:e59cc54df17c 143 {
hjjeon 0:e59cc54df17c 144 }
hjjeon 0:e59cc54df17c 145
hjjeon 0:e59cc54df17c 146 int HTTPFsRequestHandler::handleGetRequest()
hjjeon 0:e59cc54df17c 147 {
hjjeon 0:e59cc54df17c 148 HTTPHeaders headers;
hjjeon 0:e59cc54df17c 149 int retval = 0; //success
hjjeon 0:e59cc54df17c 150 uint8_t pin_state;
hjjeon 0:e59cc54df17c 151
hjjeon 0:e59cc54df17c 152 if( std::string::npos != msg.uri.find("get_dio14.cgi") )
hjjeon 0:e59cc54df17c 153 {
hjjeon 0:e59cc54df17c 154 if(din)
hjjeon 0:e59cc54df17c 155 pin_state = 1;
hjjeon 0:e59cc54df17c 156 else
hjjeon 0:e59cc54df17c 157 pin_state = 0;
hjjeon 0:e59cc54df17c 158
hjjeon 0:e59cc54df17c 159 /*
hjjeon 0:e59cc54df17c 160 *len = sprintf((char *)buf, "DioCallback({\"dio_p\":\"14\",\
hjjeon 0:e59cc54df17c 161 \"dio_s\":\"%d\"\
hjjeon 0:e59cc54df17c 162 });",
hjjeon 0:e59cc54df17c 163 pin_state // Digital io status
hjjeon 0:e59cc54df17c 164 );
hjjeon 0:e59cc54df17c 165
hjjeon 0:e59cc54df17c 166
hjjeon 0:e59cc54df17c 167 Tcp.
hjjeon 0:e59cc54df17c 168 */
hjjeon 0:e59cc54df17c 169 }
hjjeon 0:e59cc54df17c 170 else //read html pages
hjjeon 0:e59cc54df17c 171 {
hjjeon 0:e59cc54df17c 172 if (m_localPath.length() > 4)
hjjeon 0:e59cc54df17c 173 getStandardHeaders(headers, m_localPath.substr(m_localPath.length()-4).c_str());
hjjeon 0:e59cc54df17c 174 else
hjjeon 0:e59cc54df17c 175 getStandardHeaders(headers);
hjjeon 0:e59cc54df17c 176
hjjeon 0:e59cc54df17c 177 INFO("Handling Get Request (root = %s, local = %s).", m_rootPath.c_str(), m_localPath.c_str());
hjjeon 0:e59cc54df17c 178
hjjeon 0:e59cc54df17c 179 std::string reqPath;
hjjeon 0:e59cc54df17c 180
hjjeon 0:e59cc54df17c 181 // Check if we received a directory with the local bath
hjjeon 0:e59cc54df17c 182 if ((m_localPath.length() == 0) || (m_localPath.substr( m_localPath.length()-1, 1) == "/")) {
hjjeon 0:e59cc54df17c 183 // yes, we shall append the default page name
hjjeon 0:e59cc54df17c 184 m_localPath += "index.html";
hjjeon 0:e59cc54df17c 185 }
hjjeon 0:e59cc54df17c 186
hjjeon 0:e59cc54df17c 187 reqPath = m_rootPath + m_localPath;
hjjeon 0:e59cc54df17c 188
hjjeon 0:e59cc54df17c 189 INFO("Mapping \"%s\" to \"%s\"", msg.uri.c_str(), reqPath.c_str());
hjjeon 0:e59cc54df17c 190
hjjeon 0:e59cc54df17c 191 FILE *fp = fopen(reqPath.c_str(), "r");
hjjeon 0:e59cc54df17c 192 if (fp != NULL) {
hjjeon 0:e59cc54df17c 193 char * pBuffer = NULL;
hjjeon 0:e59cc54df17c 194 int sz = 8192;
hjjeon 0:e59cc54df17c 195 while( pBuffer == NULL) {
hjjeon 0:e59cc54df17c 196 sz /= 2;
hjjeon 0:e59cc54df17c 197 pBuffer = (char*)malloc(sz);
hjjeon 0:e59cc54df17c 198 if (sz < 128)
hjjeon 0:e59cc54df17c 199 error ("OutOfMemory");
hjjeon 0:e59cc54df17c 200 }
hjjeon 0:e59cc54df17c 201
hjjeon 0:e59cc54df17c 202 // File was found and can be returned
hjjeon 0:e59cc54df17c 203
hjjeon 0:e59cc54df17c 204 // first determine the size
hjjeon 0:e59cc54df17c 205 fseek(fp, 0, SEEK_END);
hjjeon 0:e59cc54df17c 206 long size = ftell(fp);
hjjeon 0:e59cc54df17c 207 fseek(fp, 0, SEEK_SET);
hjjeon 0:e59cc54df17c 208
hjjeon 0:e59cc54df17c 209 startResponse(200, size);
hjjeon 0:e59cc54df17c 210 while(!feof(fp) && !ferror(fp)) {
hjjeon 0:e59cc54df17c 211 int cnt = fread(pBuffer, 1, sz , fp);
hjjeon 0:e59cc54df17c 212 if (cnt < 0)
hjjeon 0:e59cc54df17c 213 cnt = 0;
hjjeon 0:e59cc54df17c 214 processResponse(cnt, pBuffer);
hjjeon 0:e59cc54df17c 215 }
hjjeon 0:e59cc54df17c 216 delete pBuffer;
hjjeon 0:e59cc54df17c 217 endResponse();
hjjeon 0:e59cc54df17c 218 fclose(fp);
hjjeon 0:e59cc54df17c 219 }
hjjeon 0:e59cc54df17c 220 else {
hjjeon 0:e59cc54df17c 221 retval = 404;
hjjeon 0:e59cc54df17c 222 ERR("Requested file was not found !");
hjjeon 0:e59cc54df17c 223 }
hjjeon 0:e59cc54df17c 224 }
hjjeon 0:e59cc54df17c 225
hjjeon 0:e59cc54df17c 226 return retval;
hjjeon 0:e59cc54df17c 227 }
hjjeon 0:e59cc54df17c 228
hjjeon 0:e59cc54df17c 229 int HTTPFsRequestHandler::handlePostRequest()
hjjeon 0:e59cc54df17c 230 {
justinkim 1:8291b3e9c064 231 int i = 0;
hjjeon 0:e59cc54df17c 232 int pin = 0;
hjjeon 0:e59cc54df17c 233
justinkim 1:8291b3e9c064 234 if( std::string::npos != msg.uri.find("set_LED.cgi") )
hjjeon 0:e59cc54df17c 235 {
hjjeon 0:e59cc54df17c 236 pin = get_http_param_value("pin");
justinkim 1:8291b3e9c064 237 if(pin==0) Tune(Buzzer, C_4);
justinkim 1:8291b3e9c064 238 else if(pin==1) Tune(Buzzer, Cs_4);
justinkim 1:8291b3e9c064 239 else if(pin==2) Tune(Buzzer, D_4);
justinkim 1:8291b3e9c064 240 else if(pin==3) Tune(Buzzer, Ds_4);
justinkim 1:8291b3e9c064 241 else if(pin==4) Tune(Buzzer, E_4);
justinkim 1:8291b3e9c064 242 else if(pin==5) Tune(Buzzer, F_4);
justinkim 1:8291b3e9c064 243 else if(pin==6) Tune(Buzzer, Fs_4);
justinkim 1:8291b3e9c064 244 else if(pin==7) Tune(Buzzer, G_4);
justinkim 1:8291b3e9c064 245 else if(pin==8) Tune(Buzzer, Gs_4);
justinkim 1:8291b3e9c064 246 else if(pin==9) Tune(Buzzer, A_4);
justinkim 1:8291b3e9c064 247 else if(pin==10) Tune(Buzzer, As_4);
justinkim 1:8291b3e9c064 248 else if(pin==11) Tune(Buzzer, B_4);
justinkim 1:8291b3e9c064 249 else if(pin==12) Tune(Buzzer, C_5);
justinkim 1:8291b3e9c064 250 else if(pin==13) Tune(Buzzer, Cs_5);
justinkim 1:8291b3e9c064 251 else if(pin==14) Tune(Buzzer, D_5);
justinkim 1:8291b3e9c064 252 else if(pin==15) Tune(Buzzer, Ds_5);
justinkim 1:8291b3e9c064 253 else if(pin==16) Tune(Buzzer, E_5);
justinkim 1:8291b3e9c064 254 else if(pin==17) Tune(Buzzer, F_5);
justinkim 1:8291b3e9c064 255 else if(pin==18) Tune(Buzzer, Fs_5);
justinkim 1:8291b3e9c064 256 else if(pin==19) Tune(Buzzer, G_5);
justinkim 1:8291b3e9c064 257 else if(pin==20) Tune(Buzzer, Gs_5);
justinkim 1:8291b3e9c064 258 else if(pin==21) Tune(Buzzer, A_5);
justinkim 1:8291b3e9c064 259 else if(pin==22) Tune(Buzzer, As_5);
justinkim 1:8291b3e9c064 260 else if(pin==23) Tune(Buzzer, B_5);
hjjeon 0:e59cc54df17c 261 else
hjjeon 0:e59cc54df17c 262 {
hjjeon 0:e59cc54df17c 263 WARN("Wrong pin number");
hjjeon 0:e59cc54df17c 264 }
hjjeon 0:e59cc54df17c 265
hjjeon 0:e59cc54df17c 266 return 0;
justinkim 1:8291b3e9c064 267 }
justinkim 1:8291b3e9c064 268 else if( std::string::npos != msg.uri.find("set_AUTO.cgi") )
justinkim 1:8291b3e9c064 269 {
justinkim 1:8291b3e9c064 270 pin = get_http_param_value("pin");
justinkim 1:8291b3e9c064 271 if(pin==0)
justinkim 1:8291b3e9c064 272 {
justinkim 1:8291b3e9c064 273 for(i=0; i<tones_num; i++)
justinkim 1:8291b3e9c064 274 {
justinkim 1:8291b3e9c064 275 Auto_tunes(Buzzer, tones[i]);
justinkim 1:8291b3e9c064 276 wait_ms(124);
justinkim 1:8291b3e9c064 277 }
justinkim 1:8291b3e9c064 278 Stop_tunes(Buzzer);
justinkim 1:8291b3e9c064 279 }
justinkim 1:8291b3e9c064 280 else if(pin == 99)
justinkim 1:8291b3e9c064 281 {
justinkim 1:8291b3e9c064 282 Stop_tunes(Buzzer);
justinkim 1:8291b3e9c064 283 }
justinkim 1:8291b3e9c064 284 else
justinkim 1:8291b3e9c064 285 {
justinkim 1:8291b3e9c064 286 WARN("Wrong pin number");
justinkim 1:8291b3e9c064 287 }
justinkim 1:8291b3e9c064 288
justinkim 1:8291b3e9c064 289 return 0;
justinkim 1:8291b3e9c064 290 }
hjjeon 0:e59cc54df17c 291 else
hjjeon 0:e59cc54df17c 292 {
hjjeon 0:e59cc54df17c 293 return 404;
hjjeon 0:e59cc54df17c 294 }
hjjeon 0:e59cc54df17c 295 }
hjjeon 0:e59cc54df17c 296
hjjeon 0:e59cc54df17c 297 int HTTPFsRequestHandler::handlePutRequest()
hjjeon 0:e59cc54df17c 298 {
hjjeon 0:e59cc54df17c 299 return 404;
hjjeon 0:e59cc54df17c 300 }
hjjeon 0:e59cc54df17c 301
hjjeon 0:e59cc54df17c 302 uint32_t HTTPFsRequestHandler::get_http_param_value(char* param_name)
hjjeon 0:e59cc54df17c 303 {
hjjeon 0:e59cc54df17c 304 uint8_t * name = 0;
hjjeon 0:e59cc54df17c 305 uint8_t * pos2;
hjjeon 0:e59cc54df17c 306 uint16_t len = 0;
hjjeon 0:e59cc54df17c 307 char value[10];
hjjeon 0:e59cc54df17c 308 uint32_t ret = 0;
hjjeon 0:e59cc54df17c 309
hjjeon 0:e59cc54df17c 310 //msg.attri
hjjeon 0:e59cc54df17c 311 if((name = (uint8_t *)strstr(msg.attri, param_name)))
hjjeon 0:e59cc54df17c 312 {
hjjeon 0:e59cc54df17c 313 name += strlen(param_name) + 1;
hjjeon 0:e59cc54df17c 314 pos2 = (uint8_t*)strstr((char*)name, "&");
hjjeon 0:e59cc54df17c 315 if(!pos2)
hjjeon 0:e59cc54df17c 316 {
hjjeon 0:e59cc54df17c 317 pos2 = name + strlen((char*)name);
hjjeon 0:e59cc54df17c 318 }
hjjeon 0:e59cc54df17c 319 len = pos2 - name;
hjjeon 0:e59cc54df17c 320
hjjeon 0:e59cc54df17c 321 if(len)
hjjeon 0:e59cc54df17c 322 {
hjjeon 0:e59cc54df17c 323 strncpy(value, (char*)name, len);
hjjeon 0:e59cc54df17c 324 ret = atoi(value);
hjjeon 0:e59cc54df17c 325 }
hjjeon 0:e59cc54df17c 326 }
hjjeon 0:e59cc54df17c 327 return ret;
hjjeon 0:e59cc54df17c 328 }
hjjeon 0:e59cc54df17c 329
justinkim 1:8291b3e9c064 330 /**
justinkim 1:8291b3e9c064 331 * @brief Tune Function
justinkim 1:8291b3e9c064 332 * @param name : Choose the PwmOut
justinkim 1:8291b3e9c064 333 period : this param is tune value. (C_3...B_5)
justinkim 1:8291b3e9c064 334 * @retval None
justinkim 1:8291b3e9c064 335 */
justinkim 1:8291b3e9c064 336 void Tune(PwmOut name, int period)
justinkim 1:8291b3e9c064 337 {
justinkim 1:8291b3e9c064 338 name.period_us(period);
justinkim 1:8291b3e9c064 339 name.write(0.50f); // 50% duty cycle
justinkim 1:8291b3e9c064 340 wait_ms(250); // 1/4 beat
justinkim 1:8291b3e9c064 341 name.period_us(0); // Sound off
justinkim 1:8291b3e9c064 342 }
justinkim 1:8291b3e9c064 343
justinkim 1:8291b3e9c064 344 /**
justinkim 1:8291b3e9c064 345 * @brief Auto tunes Function
justinkim 1:8291b3e9c064 346 * @param name : Choose the PwmOut
justinkim 1:8291b3e9c064 347 period : this param is tune value. (C_3...B_5)
justinkim 1:8291b3e9c064 348 * @retval None
justinkim 1:8291b3e9c064 349 */
justinkim 1:8291b3e9c064 350 void Auto_tunes(PwmOut name, int period)
justinkim 1:8291b3e9c064 351 {
justinkim 1:8291b3e9c064 352 name.period_us(period);
justinkim 1:8291b3e9c064 353 name.write(0.50f); // 50% duty cycle
justinkim 1:8291b3e9c064 354 wait_ms(250); // 1/4 beat
justinkim 1:8291b3e9c064 355 }
justinkim 1:8291b3e9c064 356
justinkim 1:8291b3e9c064 357 void Stop_tunes(PwmOut name)
justinkim 1:8291b3e9c064 358 {
justinkim 1:8291b3e9c064 359 name.period_us(0);
justinkim 1:8291b3e9c064 360 }