NanoService device game controller for NSPong.

Dependencies:   Beep C12832_lcd EthernetInterface MMA7660 mbed-rtos mbed nsdl_lib

NS_Game_Controller

NS_Game_Controller is a game controller software for NSPong.

NSPong is a HTML5 demo game developed on top of ARM Sensinode’s NanoService Platform. The game uses for example RealTimeMultiplayerNodeJS, Box2D and CAAT libraries, which are specifically built for HTML5 multiplayer games with the client/server model.

NSPong is available at https://github.com/NSPong/NSPong.

Demo video is available at https://vimeo.com/95207889.

Committer:
Shage
Date:
Tue May 13 17:17:38 2014 +0000
Revision:
0:e8d7be634e3c
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Shage 0:e8d7be634e3c 1 // Buzzer resource implementation
Shage 0:e8d7be634e3c 2
Shage 0:e8d7be634e3c 3 #include "mbed.h"
Shage 0:e8d7be634e3c 4 #include "nsdl_support.h"
Shage 0:e8d7be634e3c 5 #include "buzzer.h"
Shage 0:e8d7be634e3c 6 #include "Beep.h"
Shage 0:e8d7be634e3c 7
Shage 0:e8d7be634e3c 8 #define BUZZ_RES_ID "buzz"
Shage 0:e8d7be634e3c 9
Shage 0:e8d7be634e3c 10 extern Serial pc;
Shage 0:e8d7be634e3c 11 static Beep buzzer(p26);
Shage 0:e8d7be634e3c 12
Shage 0:e8d7be634e3c 13 // Data from PUT request
Shage 0:e8d7be634e3c 14 static char received_cmd[20];
Shage 0:e8d7be634e3c 15 static char cmd[10];
Shage 0:e8d7be634e3c 16
Shage 0:e8d7be634e3c 17 /* Only PUT method allowed */
Shage 0:e8d7be634e3c 18 static uint8_t buzz_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
Shage 0:e8d7be634e3c 19 {
Shage 0:e8d7be634e3c 20 sn_coap_hdr_s *coap_res_ptr = 0;
Shage 0:e8d7be634e3c 21 memcpy(received_cmd, (char *)received_coap_ptr->payload_ptr, received_coap_ptr->payload_len);
Shage 0:e8d7be634e3c 22 received_cmd[received_coap_ptr->payload_len] = '\0';
Shage 0:e8d7be634e3c 23 sprintf(cmd, "%s", received_cmd);
Shage 0:e8d7be634e3c 24
Shage 0:e8d7be634e3c 25 if (!strcmp(cmd, "beep")) {
Shage 0:e8d7be634e3c 26 buzzer.beep(300,0);
Shage 0:e8d7be634e3c 27 wait(0.05);
Shage 0:e8d7be634e3c 28 buzzer.nobeep();
Shage 0:e8d7be634e3c 29 }
Shage 0:e8d7be634e3c 30 else if (!strcmp(cmd, "score")) {
Shage 0:e8d7be634e3c 31 buzzer.beep(400,0);
Shage 0:e8d7be634e3c 32 wait(0.2);
Shage 0:e8d7be634e3c 33 buzzer.nobeep();
Shage 0:e8d7be634e3c 34 buzzer.beep(600,0);
Shage 0:e8d7be634e3c 35 wait(0.3);
Shage 0:e8d7be634e3c 36 buzzer.nobeep();
Shage 0:e8d7be634e3c 37 }
Shage 0:e8d7be634e3c 38 else if (!strcmp(cmd, "win")) {
Shage 0:e8d7be634e3c 39 buzzer.beep(700,0);
Shage 0:e8d7be634e3c 40 wait(0.2);
Shage 0:e8d7be634e3c 41 buzzer.nobeep();
Shage 0:e8d7be634e3c 42 buzzer.beep(700,0);
Shage 0:e8d7be634e3c 43 wait(0.3);
Shage 0:e8d7be634e3c 44 buzzer.nobeep();
Shage 0:e8d7be634e3c 45 }
Shage 0:e8d7be634e3c 46
Shage 0:e8d7be634e3c 47 coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CHANGED);
Shage 0:e8d7be634e3c 48 sn_nsdl_send_coap_message(address, coap_res_ptr);
Shage 0:e8d7be634e3c 49 sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
Shage 0:e8d7be634e3c 50 memset(cmd, 0, 10);
Shage 0:e8d7be634e3c 51 return 0;
Shage 0:e8d7be634e3c 52 }
Shage 0:e8d7be634e3c 53
Shage 0:e8d7be634e3c 54 int create_buzz_resource(sn_nsdl_resource_info_s *resource_ptr)
Shage 0:e8d7be634e3c 55 {
Shage 0:e8d7be634e3c 56 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);
Shage 0:e8d7be634e3c 57 return 0;
Shage 0:e8d7be634e3c 58 }