BlackOneとAndroidの連携デモプログラム AndroidAccessoryを改造してBlackOneとAndroidが連携できるようにしました。 サポートしているのは、デモアプリの ”Buttons” B1-SW1, B2-SW2, B3-SW3 ”LED2” RGB-LED のみです。 LCDに表示するイメージをマイクロSDカードに入れてLCDのソケットに挿入しておく必要があります。 イメージは、320X240ドットで”\Image”という名前のフォルダの直下に”10.jpg”という名前で入れてください。

Dependencies:   TextLCD mbed

Committer:
techand
Date:
Fri Dec 23 04:33:33 2011 +0000
Revision:
0:7b556109fd46

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
techand 0:7b556109fd46 1 /*
techand 0:7b556109fd46 2 Copyright (c) 2010 Peter Barrett
techand 0:7b556109fd46 3
techand 0:7b556109fd46 4 Permission is hereby granted, free of charge, to any person obtaining a copy
techand 0:7b556109fd46 5 of this software and associated documentation files (the "Software"), to deal
techand 0:7b556109fd46 6 in the Software without restriction, including without limitation the rights
techand 0:7b556109fd46 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
techand 0:7b556109fd46 8 copies of the Software, and to permit persons to whom the Software is
techand 0:7b556109fd46 9 furnished to do so, subject to the following conditions:
techand 0:7b556109fd46 10
techand 0:7b556109fd46 11 The above copyright notice and this permission notice shall be included in
techand 0:7b556109fd46 12 all copies or substantial portions of the Software.
techand 0:7b556109fd46 13
techand 0:7b556109fd46 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
techand 0:7b556109fd46 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
techand 0:7b556109fd46 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
techand 0:7b556109fd46 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
techand 0:7b556109fd46 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
techand 0:7b556109fd46 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
techand 0:7b556109fd46 20 THE SOFTWARE.
techand 0:7b556109fd46 21 */
techand 0:7b556109fd46 22
techand 0:7b556109fd46 23 /*
techand 0:7b556109fd46 24 Tue Apr 26 2011 Bart Janssens: added a socket listener
techand 0:7b556109fd46 25 */
techand 0:7b556109fd46 26
techand 0:7b556109fd46 27 #ifndef SOCKET_H_INCLUDED
techand 0:7b556109fd46 28 #define SOCKET_H_INCLUDED
techand 0:7b556109fd46 29
techand 0:7b556109fd46 30 #define SOCKET_HCI 1
techand 0:7b556109fd46 31 #define SOCKET_L2CAP 2
techand 0:7b556109fd46 32 #define SOCKET_RFCOM 3
techand 0:7b556109fd46 33
techand 0:7b556109fd46 34 typedef struct
techand 0:7b556109fd46 35 {
techand 0:7b556109fd46 36 u8 AddressSpecific[0]; // BDADDR,psm etc
techand 0:7b556109fd46 37 } SocketAddrHdr;
techand 0:7b556109fd46 38
techand 0:7b556109fd46 39
techand 0:7b556109fd46 40
techand 0:7b556109fd46 41 enum SocketState
techand 0:7b556109fd46 42 {
techand 0:7b556109fd46 43 SocketState_Unknown,
techand 0:7b556109fd46 44 SocketState_Opening,
techand 0:7b556109fd46 45 SocketState_Open,
techand 0:7b556109fd46 46 SocketState_Closing,
techand 0:7b556109fd46 47 SocketState_Closed,
techand 0:7b556109fd46 48 SocketState_Listen,
techand 0:7b556109fd46 49 SocketState_Accept
techand 0:7b556109fd46 50 };
techand 0:7b556109fd46 51
techand 0:7b556109fd46 52 typedef void (*SocketCallback)(int socket, SocketState state, const u8* data, int len, void* userData);
techand 0:7b556109fd46 53
techand 0:7b556109fd46 54 class SocketListener
techand 0:7b556109fd46 55 {
techand 0:7b556109fd46 56 public:
techand 0:7b556109fd46 57 int ID;
techand 0:7b556109fd46 58 int Type;
techand 0:7b556109fd46 59 int port;
techand 0:7b556109fd46 60 SocketCallback Callback;
techand 0:7b556109fd46 61 void* userData;
techand 0:7b556109fd46 62 };
techand 0:7b556109fd46 63
techand 0:7b556109fd46 64 //===========================================================================
techand 0:7b556109fd46 65 //===========================================================================
techand 0:7b556109fd46 66 // Don't need to look at or use anything below this line:
techand 0:7b556109fd46 67 // Internal representation of socket
techand 0:7b556109fd46 68
techand 0:7b556109fd46 69 class SocketHandler;
techand 0:7b556109fd46 70 class SocketInternal
techand 0:7b556109fd46 71 {
techand 0:7b556109fd46 72 public:
techand 0:7b556109fd46 73
techand 0:7b556109fd46 74 u8 ID;
techand 0:7b556109fd46 75 u8 State;
techand 0:7b556109fd46 76 u8 Type;
techand 0:7b556109fd46 77 u8 B0;
techand 0:7b556109fd46 78 int port;
techand 0:7b556109fd46 79 SocketCallback Callback;
techand 0:7b556109fd46 80 void* userData;
techand 0:7b556109fd46 81 u8 Data[0]; // Extra socket data starts here
techand 0:7b556109fd46 82
techand 0:7b556109fd46 83 void Recv(const u8* data, int len)
techand 0:7b556109fd46 84 {
techand 0:7b556109fd46 85 Callback(ID,(SocketState)State,data,len,userData);
techand 0:7b556109fd46 86 }
techand 0:7b556109fd46 87
techand 0:7b556109fd46 88 void SetState(SocketState state)
techand 0:7b556109fd46 89 {
techand 0:7b556109fd46 90 State = state;
techand 0:7b556109fd46 91 Callback(ID,(SocketState)State,0,0,userData);
techand 0:7b556109fd46 92 }
techand 0:7b556109fd46 93 };
techand 0:7b556109fd46 94
techand 0:7b556109fd46 95 class SocketHandler
techand 0:7b556109fd46 96 {
techand 0:7b556109fd46 97 public:
techand 0:7b556109fd46 98 virtual int Open(SocketInternal* sock, SocketAddrHdr* addr) = 0;
techand 0:7b556109fd46 99 virtual int Create(SocketInternal* sock, SocketAddrHdr* addr) = 0;
techand 0:7b556109fd46 100 virtual int Send(SocketInternal* sock, const u8* data, int len) = 0;
techand 0:7b556109fd46 101 virtual int Close(SocketInternal* sock) = 0;
techand 0:7b556109fd46 102 virtual int Accept(SocketInternal* sock, SocketAddrHdr* addr) = 0;
techand 0:7b556109fd46 103 };
techand 0:7b556109fd46 104
techand 0:7b556109fd46 105 int RegisterSocketHandler(int type, SocketHandler* handler);
techand 0:7b556109fd46 106 SocketInternal* GetSocketInternal(int socket);
techand 0:7b556109fd46 107
techand 0:7b556109fd46 108 int Socket_Open(int type, SocketAddrHdr* addr, SocketCallback callback, void* userData); // Open a socket
techand 0:7b556109fd46 109 int Socket_Listen(int type, int port,SocketCallback callback, void* userData);
techand 0:7b556109fd46 110 int Socket_InUse(int type, int port);
techand 0:7b556109fd46 111 int Socket_Accept(int socket, SocketCallback callback, void* userData);
techand 0:7b556109fd46 112 SocketInternal* Socket_Create(int type,SocketAddrHdr* addr, int port);
techand 0:7b556109fd46 113 int Socket_Send(int socket, const u8* data, int len);
techand 0:7b556109fd46 114 int Socket_State(int socket);
techand 0:7b556109fd46 115 int Socket_Close(int socket);
techand 0:7b556109fd46 116
techand 0:7b556109fd46 117 #define ERR_SOCKET_TYPE_NOT_FOUND -200
techand 0:7b556109fd46 118 #define ERR_SOCKET_NOT_FOUND -201
techand 0:7b556109fd46 119 #define ERR_SOCKET_NONE_LEFT -202
techand 0:7b556109fd46 120 #define ERR_SOCKET_IN_USE -203
techand 0:7b556109fd46 121
techand 0:7b556109fd46 122 #endif // SOCKET_H_INCLUDED