うおーるぼっとをWiiリモコンでコントロールする新しいプログラムです。 以前のものより、Wiiリモコンが早く繋がる様になりました。 It is a program which controls A with the Wii remote. ※ A Bluetooth dongle and a Wii remote control are needed.

Dependencies:   USBHost mbed FATFileSystem mbed-rtos

Committer:
jksoft
Date:
Mon Jun 10 16:01:50 2013 +0000
Revision:
0:fccb789424fc
1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:fccb789424fc 1 /*
jksoft 0:fccb789424fc 2 * Copyright (C) 2009-2012 by Matthias Ringwald
jksoft 0:fccb789424fc 3 *
jksoft 0:fccb789424fc 4 * Redistribution and use in source and binary forms, with or without
jksoft 0:fccb789424fc 5 * modification, are permitted provided that the following conditions
jksoft 0:fccb789424fc 6 * are met:
jksoft 0:fccb789424fc 7 *
jksoft 0:fccb789424fc 8 * 1. Redistributions of source code must retain the above copyright
jksoft 0:fccb789424fc 9 * notice, this list of conditions and the following disclaimer.
jksoft 0:fccb789424fc 10 * 2. Redistributions in binary form must reproduce the above copyright
jksoft 0:fccb789424fc 11 * notice, this list of conditions and the following disclaimer in the
jksoft 0:fccb789424fc 12 * documentation and/or other materials provided with the distribution.
jksoft 0:fccb789424fc 13 * 3. Neither the name of the copyright holders nor the names of
jksoft 0:fccb789424fc 14 * contributors may be used to endorse or promote products derived
jksoft 0:fccb789424fc 15 * from this software without specific prior written permission.
jksoft 0:fccb789424fc 16 * 4. Any redistribution, use, or modification is done solely for
jksoft 0:fccb789424fc 17 * personal benefit and not for any commercial purpose or for
jksoft 0:fccb789424fc 18 * monetary gain.
jksoft 0:fccb789424fc 19 *
jksoft 0:fccb789424fc 20 * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
jksoft 0:fccb789424fc 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
jksoft 0:fccb789424fc 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
jksoft 0:fccb789424fc 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
jksoft 0:fccb789424fc 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
jksoft 0:fccb789424fc 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
jksoft 0:fccb789424fc 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
jksoft 0:fccb789424fc 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
jksoft 0:fccb789424fc 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
jksoft 0:fccb789424fc 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
jksoft 0:fccb789424fc 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
jksoft 0:fccb789424fc 31 * SUCH DAMAGE.
jksoft 0:fccb789424fc 32 *
jksoft 0:fccb789424fc 33 * Please inquire about commercial licensing options at btstack@ringwald.ch
jksoft 0:fccb789424fc 34 *
jksoft 0:fccb789424fc 35 */
jksoft 0:fccb789424fc 36
jksoft 0:fccb789424fc 37 /*
jksoft 0:fccb789424fc 38 * l2cap_signaling.h
jksoft 0:fccb789424fc 39 *
jksoft 0:fccb789424fc 40 * Created by Matthias Ringwald on 7/23/09.
jksoft 0:fccb789424fc 41 */
jksoft 0:fccb789424fc 42
jksoft 0:fccb789424fc 43 #include "l2cap_signaling.h"
jksoft 0:fccb789424fc 44
jksoft 0:fccb789424fc 45 #include <string.h>
jksoft 0:fccb789424fc 46
jksoft 0:fccb789424fc 47 static char *l2cap_signaling_commands_format[] = {
jksoft 0:fccb789424fc 48 "D", // 0x01 command reject: reason {cmd not understood (0), sig MTU exceeded (2:max sig MTU), invalid CID (4:req CID)}, data len, data
jksoft 0:fccb789424fc 49 "22", // 0x02 connection request: PSM, Source CID
jksoft 0:fccb789424fc 50 "2222", // 0x03 connection response: Dest CID, Source CID, Result, Status
jksoft 0:fccb789424fc 51 "22D", // 0x04 config request: Dest CID, Flags, Configuration options
jksoft 0:fccb789424fc 52 "222D", // 0x05 config response: Source CID, Flags, Result, Configuration options
jksoft 0:fccb789424fc 53 "22", // 0x06 disconection request: Dest CID, Source CID
jksoft 0:fccb789424fc 54 "22", // 0x07 disconection response: Dest CID, Source CID
jksoft 0:fccb789424fc 55 "D", // 0x08 echo request: Data
jksoft 0:fccb789424fc 56 "D", // 0x09 echo response: Data
jksoft 0:fccb789424fc 57 "2", // 0x0a information request: InfoType {1=Connectionless MTU, 2=Extended features supported}
jksoft 0:fccb789424fc 58 "22D", // 0x0b information response: InfoType, Result, Data
jksoft 0:fccb789424fc 59 };
jksoft 0:fccb789424fc 60
jksoft 0:fccb789424fc 61 uint8_t sig_seq_nr = 0xff;
jksoft 0:fccb789424fc 62 uint16_t source_cid = 0x40;
jksoft 0:fccb789424fc 63
jksoft 0:fccb789424fc 64 uint8_t l2cap_next_sig_id(void){
jksoft 0:fccb789424fc 65 if (sig_seq_nr == 0xff) {
jksoft 0:fccb789424fc 66 sig_seq_nr = 1;
jksoft 0:fccb789424fc 67 } else {
jksoft 0:fccb789424fc 68 sig_seq_nr++;
jksoft 0:fccb789424fc 69 }
jksoft 0:fccb789424fc 70 return sig_seq_nr;
jksoft 0:fccb789424fc 71 }
jksoft 0:fccb789424fc 72
jksoft 0:fccb789424fc 73 uint16_t l2cap_next_local_cid(void){
jksoft 0:fccb789424fc 74 return source_cid++;
jksoft 0:fccb789424fc 75 }
jksoft 0:fccb789424fc 76
jksoft 0:fccb789424fc 77 uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
jksoft 0:fccb789424fc 78
jksoft 0:fccb789424fc 79 // 0 - Connection handle : PB=10 : BC=00
jksoft 0:fccb789424fc 80 bt_store_16(acl_buffer, 0, handle | (2 << 12) | (0 << 14));
jksoft 0:fccb789424fc 81 // 6 - L2CAP channel = 1
jksoft 0:fccb789424fc 82 bt_store_16(acl_buffer, 6, 1);
jksoft 0:fccb789424fc 83 // 8 - Code
jksoft 0:fccb789424fc 84 acl_buffer[8] = cmd;
jksoft 0:fccb789424fc 85 // 9 - id (!= 0 sequentially)
jksoft 0:fccb789424fc 86 acl_buffer[9] = identifier;
jksoft 0:fccb789424fc 87
jksoft 0:fccb789424fc 88 // 12 - L2CAP signaling parameters
jksoft 0:fccb789424fc 89 uint16_t pos = 12;
jksoft 0:fccb789424fc 90 const char *format = l2cap_signaling_commands_format[cmd-1];
jksoft 0:fccb789424fc 91 uint16_t word;
jksoft 0:fccb789424fc 92 uint8_t * ptr;
jksoft 0:fccb789424fc 93 while (*format) {
jksoft 0:fccb789424fc 94 switch(*format) {
jksoft 0:fccb789424fc 95 case '1': // 8 bit value
jksoft 0:fccb789424fc 96 case '2': // 16 bit value
jksoft 0:fccb789424fc 97 word = va_arg(argptr, int);
jksoft 0:fccb789424fc 98 // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
jksoft 0:fccb789424fc 99 acl_buffer[pos++] = word & 0xff;
jksoft 0:fccb789424fc 100 if (*format == '2') {
jksoft 0:fccb789424fc 101 acl_buffer[pos++] = word >> 8;
jksoft 0:fccb789424fc 102 }
jksoft 0:fccb789424fc 103 break;
jksoft 0:fccb789424fc 104 case 'D': // variable data. passed: len, ptr
jksoft 0:fccb789424fc 105 word = va_arg(argptr, int);
jksoft 0:fccb789424fc 106 ptr = va_arg(argptr, uint8_t *);
jksoft 0:fccb789424fc 107 memcpy(&acl_buffer[pos], ptr, word);
jksoft 0:fccb789424fc 108 pos += word;
jksoft 0:fccb789424fc 109 break;
jksoft 0:fccb789424fc 110 default:
jksoft 0:fccb789424fc 111 break;
jksoft 0:fccb789424fc 112 }
jksoft 0:fccb789424fc 113 format++;
jksoft 0:fccb789424fc 114 };
jksoft 0:fccb789424fc 115 va_end(argptr);
jksoft 0:fccb789424fc 116
jksoft 0:fccb789424fc 117 // Fill in various length fields: it's the number of bytes following for ACL lenght and l2cap parameter length
jksoft 0:fccb789424fc 118 // - the l2cap payload length is counted after the following channel id (only payload)
jksoft 0:fccb789424fc 119
jksoft 0:fccb789424fc 120 // 2 - ACL length
jksoft 0:fccb789424fc 121 bt_store_16(acl_buffer, 2, pos - 4);
jksoft 0:fccb789424fc 122 // 4 - L2CAP packet length
jksoft 0:fccb789424fc 123 bt_store_16(acl_buffer, 4, pos - 6 - 2);
jksoft 0:fccb789424fc 124 // 10 - L2CAP signaling parameter length
jksoft 0:fccb789424fc 125 bt_store_16(acl_buffer, 10, pos - 12);
jksoft 0:fccb789424fc 126
jksoft 0:fccb789424fc 127 return pos;
jksoft 0:fccb789424fc 128 }