Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Beep C12832_lcd EthernetInterface MMA7660 mbed-rtos mbed nsdl_lib
buzzer.cpp
00001 // Buzzer resource implementation 00002 00003 #include "mbed.h" 00004 #include "nsdl_support.h" 00005 #include "buzzer.h" 00006 #include "Beep.h" 00007 00008 #define BUZZ_RES_ID "buzz" 00009 00010 extern Serial pc; 00011 static Beep buzzer(p26); 00012 00013 // Data from PUT request 00014 static char received_cmd[20]; 00015 static char cmd[10]; 00016 00017 /* Only PUT method allowed */ 00018 static uint8_t buzz_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) 00019 { 00020 sn_coap_hdr_s *coap_res_ptr = 0; 00021 memcpy(received_cmd, (char *)received_coap_ptr->payload_ptr, received_coap_ptr->payload_len); 00022 received_cmd[received_coap_ptr->payload_len] = '\0'; 00023 sprintf(cmd, "%s", received_cmd); 00024 00025 if (!strcmp(cmd, "beep")) { 00026 buzzer.beep(300,0); 00027 wait(0.05); 00028 buzzer.nobeep(); 00029 } 00030 else if (!strcmp(cmd, "score")) { 00031 buzzer.beep(400,0); 00032 wait(0.2); 00033 buzzer.nobeep(); 00034 buzzer.beep(600,0); 00035 wait(0.3); 00036 buzzer.nobeep(); 00037 } 00038 else if (!strcmp(cmd, "win")) { 00039 buzzer.beep(700,0); 00040 wait(0.2); 00041 buzzer.nobeep(); 00042 buzzer.beep(700,0); 00043 wait(0.3); 00044 buzzer.nobeep(); 00045 } 00046 00047 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED); 00048 sn_nsdl_send_coap_message(address, coap_res_ptr); 00049 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); 00050 memset(cmd, 0, 10); 00051 return 0; 00052 } 00053 00054 int create_buzz_resource(sn_nsdl_resource_info_s *resource_ptr) 00055 { 00056 nsdl_create_dynamic_resource(resource_ptr, sizeof(BUZZ_RES_ID)-1, (uint8_t*)BUZZ_RES_ID, 0, 0, 0, &buzz_resource_cb, SN_GRS_PUT_ALLOWED); 00057 return 0; 00058 }
Generated on Wed Jul 13 2022 01:21:07 by
1.7.2