2016 12 2 : ( )
I. 1 1.1 1 1.2 1 1.3 1 II. 3 2.1 3 2.2 4 2.3 5 III. 6 3.1 6 3.2 7 3.3 7 3.4 7 IV. 11 4.1 11 4.2 12 4.3 13 4.4 15 V. 16 A. 17 B. 18
I. 1.1,.. NFC(Near Field Communication) NFC. NFC.. 1.2.... 1.3.. 1. 1.. - 1 -
그림 1 예상구상도 100%.. 300.. 그림 2 쿠도이노사진..... - 2 -
.. MAC(Media Access Control Address). MAC NIC(Network Interface Card) 48. MAC MAC. II. 2.1....,,.,.. ' (OHA Open Handset Alliance)' 2007 11. (Google), ' '. (Linux) 2.6 (OS;operating system),, - 3 -
... ' '..,..., (Microcontroller). LED.... (Atmel AVR),...,. C++++ C++.,, LED,,, ( ).. - 4 -
그림 3 쿠도이노핀번호 2.2 그림 4 어플리케이션의동작순서 - 5 -
2.3 2.2 MAC.. Lock/Unlock. 그림 5 어플리케이션기본레이아웃. if (BTSerial.available()) Serial.println(BTSerial.read());. 3 4. Lock/Unlock. - 6 -
III. 3.1 표 3.1 업무분담표 팀원 김동식 송지호 업무분담업무 - 어플리케이션프로그램제작 - 아두이노스케쳐를사용하여쿠도이소소스코딩 - 프로그래밍화면디자인 - 졸업작품전시회출품및결과발표 - 쿠도이노를이용한하드웨어적부분제작 - 프로그램디버깅 - 작품실행및성능평가 - 졸업작품전시회출품및결과발표 3.2 표 2 15. 15. 15. 16. 16. 16. 16. 16. 16. 16. 16. 16. 주제선정도어락회로분석블루투스모듈, 쿠도이노 set 10 11 12 1 2 3 4 5 7 8 9 10 자료조사회로구성블루투스통신및쿠도이노 코딩도어락모터제어오픈소스활용도어락블루 투스제어어플리케이션제작기능수정 - 7 -
3.3 3.3.1 l (NT910S3Q-MD1S, ) l ( SⅡ) 3.3.2 l l l l 3.4 l l l Microsoft Windows 7 pro 32 Eclips l Java SE 2.1a l - 8 -
IV. 4.1 그림 6 작품전체사진 그림 7 도어락본체사진 - 9 -
그림 8 쿠도이노사진 4.2-10 -
그림 9 어플리케이션 4.3 -. -. - -. - - 11 -
4.4 -. - -, - -. RSSI -. LED - 12 -
V. [1],,, 2016 1 3 [2],,, [3],,, - 13 -
A. (, ) #include<softwareserial.h> SoftwareSerial BTSerial(13, 12); int input_1 = 11; int input_2 = 10; // & // void setup() { Serial.begin(9600); BTSerial.begin(9600); pinmode(11,output); pinmode(10,output); void loop() { if (BTSerial.available()) { // Serial.println(BTSerial.read()); // int abc; abc = BTSerial.read(); //data if(abc=='4') { digitalwrite(11, HIGH); digitalwrite(10, LOW); delay(800); digitalwrite(11, HIGH); digitalwrite(10, HIGH); - 14 -
if(abc =='0') { digitalwrite(11, LOW); digitalwrite(10, HIGH); delay(800); digitalwrite(11, HIGH); digitalwrite(10, HIGH); if(abc =='5') { digitalwrite(11, LOW); digitalwrite(10, LOW): if(abc =='7') { digitalwrite(11, HIGH); digitalwrite(10, HIGH); - 15 -
B. <MainActivity.java> package kr.re.dev.arduinoecho; import java.io.ioexception;import java.io.inputstream; import java.io.outputstream; import java.lang.reflect.field; import java.nio.bytebuffer; import java.util.linkedlist; import java.util.set; import kr.re.dev.bluetooth.bluetoothserialclient; import kr.re.dev.bluetooth.bluetoothserialclient.bluetoothstreaminghandler; import kr.re.dev.bluetooth.bluetoothserialclient.onbluetoothenabledlistener; import kr.re.dev.bluetooth.bluetoothserialclient.onscanlistener; import kr.re.dev.bluetoothecho.r; import android.app.activity; import android.app.alertdialog; import android.app.progressdialog; import android.bluetooth.bluetoothdevice; import android.bluetooth.bluetoothsocket; import android.content.dialoginterface; import android.content.intent; import android.content.dialoginterface.oncancellistener; import android.graphics.color; import android.os.bundle; import android.text.html; import android.text.method.scrollingmovementmethod; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.view.onclicklistener; import android.view.viewconfiguration; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import arduino.bt.simplebt.bluetoothservice; import arduino.bt.simplebt.devicelistactivity; import android.widget.arrayadapter; import android.widget.button; import android.widget.edittext; import android.widget.listview; import android.widget.textview; import android.widget.toast; public class MainActivity extends Activity { private static final boolean D = false; - 16 -
private static final String TAG = null; protected static final String mdevices = null; private LinkedList<BluetoothDevice> mbluetoothdevices = new LinkedList<BluetoothDevice>(); private ArrayAdapter<String> mdevicearrayadapter; private EditText medittextinput; private TextView mtextview; private Button mbuttonsend; private Button mrock; private Button munrock; private boolean mconnecttoselectddevice; private ProgressDialog mloadingdialog; private AlertDialog mdevicelistdialog; private Menu mmenu; private BluetoothSerialClient mclient; private boolean write; private Object mremotedevice; private Object mbluetoothadapter; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mclient = BluetoothSerialClient.getInstance(); if(mclient == null) { Toast.makeText(getApplicationContext(), "Cannot use the Bluetooth device.", Toast.LENGTH_SHORT).show(); finish(); overflowmenuinactionbar(); initprogressdialog(); initdevicelistdialog(); initwidget(); private void overflowmenuinactionbar(){ try { ViewConfiguration config = ViewConfiguration.get(this); Field menukeyfield = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); if(menukeyfield!= null) { menukeyfield.setaccessible(true); menukeyfield.setboolean(config, false); catch (Exception ex) { //. 3.x. //, 3.x. - 17 -
protected void onpause() { mclient.cancelscan(getapplicationcontext()); super.onpause(); protected void onresume() { super.onresume(); enablebluetooth(); private void initprogressdialog() { mloadingdialog = new ProgressDialog(this); mloadingdialog.setcancelable(false); private void initwidget() { mtextview = (TextView) findviewbyid(r.id.textviewterminal); mtextview.setmovementmethod(new ScrollingMovementMethod()); medittextinput = (EditText) findviewbyid(r.id.edittextinput); mbuttonsend = (Button) findviewbyid(r.id.buttonsend); mrock=(button)findviewbyid(r.id.rock); munrock=(button)findviewbyid(r.id.unrock); mbuttonsend.setonclicklistener(new OnClickListener(){ public void onclick(view v) { sendstringdata(medittextinput.gettext().tostring(), 0); medittextinput.settext(""); ); mrock.setonclicklistener(new OnClickListener(){ public void onclick(view v) { sendstringdata(medittextinput.gettext().tostring(), 0); medittextinput.settext(" (00)\n**************************"); sendstringdata(medittextinput.gettext().tostring(), 0); medittextinput.settext(""); ); munrock.setonclicklistener(new OnClickListener(){ public void onclick(view v) { sendstringdata(medittextinput.gettext().tostring(), 0); medittextinput.settext(" (44)\n**************************"); sendstringdata(medittextinput.gettext().tostring(), 0); medittextinput.settext(""); - 18 -
{ ); private void initdevicelistdialog() { mdevicearrayadapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.item_device); ListView listview = new ListView(getApplicationContext()); listview.setadapter(mdevicearrayadapter); listview.setonitemclicklistener(new OnItemClickListener() { public void onitemclick(adapterview<?> parent, View view, int position, long id) String item = (String) parent.getitematposition(position); for(bluetoothdevice device : mbluetoothdevices) { if(item.contains(device.getaddress())) { connect(device, mclient); mdevicelistdialog.cancel(); ); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.settitle("select bluetooth device"); builder.setview(listview); builder.setpositivebutton("scan", new DialogInterface.OnClickListener() { public void onclick(dialoginterface dialog, int id) { scandevices(); ); mdevicelistdialog = builder.create(); mdevicelistdialog.setcanceledontouchoutside(false); private void adddevicetoarrayadapter(bluetoothdevice device) { if(mbluetoothdevices.contains(device)) { mbluetoothdevices.remove(device); mdevicearrayadapter.remove(device.getname() + "\n" + device.getaddress()); mbluetoothdevices.add(device); mdevicearrayadapter.add(device.getname() + "\n" + device.getaddress() ); mdevicearrayadapter.notifydatasetchanged(); private void enablebluetooth() { BluetoothSerialClient btset = mclient; btset.enablebluetooth(this, new OnBluetoothEnabledListener() { - 19 -
public void onbluetoothenabled(boolean success) { if(success) { getpaireddevices(); else { finish(); ); private void addtext(string text) { mtextview.append(text); final int scrollamount = mtextview.getlayout().getlinetop(mtextview.getlinecount()) - mtextview.getheight(); if (scrollamount > 0) mtextview.scrollto(0, scrollamount); else mtextview.scrollto(0, 0); private void getpaireddevices() { Set<BluetoothDevice> devices = mclient.getpaireddevices(); for(bluetoothdevice device: devices) { adddevicetoarrayadapter(device); mconnecttoselectddevice(); private void mconnecttoselectddevice() { // TODO Auto-generated method stub private void scandevices() { BluetoothSerialClient btset = mclient; btset.scandevices(getapplicationcontext(), new OnScanListener() { String message =""; public void onstart() { Log.d("Test", "Scan Start."); mloadingdialog.show(); message = "Scanning..."; mloadingdialog.setmessage("scanning..."); - 20 -
mloadingdialog.setcancelable(true); mloadingdialog.setcanceledontouchoutside(false); mloadingdialog.setoncancellistener(new OnCancelListener() { public void oncancel(dialoginterface dialog) { BluetoothSerialClient btset = mclient; btset.cancelscan(getapplicationcontext()); ); public void onfounddevice(bluetoothdevice bluetoothdevice) { adddevicetoarrayadapter(bluetoothdevice); message= "\n" + bluetoothdevice.getname() + "\n" + bluetoothdevice.getaddress(); mloadingdialog.setmessage(message); public void onfinish() { Log.d("Test", "Scan finish."); message = ""; mloadingdialog.cancel(); mloadingdialog.setcancelable(false); mloadingdialog.setoncancellistener(null); mdevicelistdialog.show(); ); void connecttoselectddevice(object msocket) { mremotedevice = getdevicefrombondedlist(accessibility_service); java.util.uuid uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); try { // msocket = ((BluetoothDevice) mremotedevice).createrfcommsockettoservicerecord(uuid); // RFCOMM ((BluetoothSocket) msocket).connect(); // OutputStream moutputstream = ((BluetoothSocket) msocket).getoutputstream(); Object minputstream = ((BluetoothSocket) msocket).getinputstream(); // beginlistenfordata(); - 21 -
catch(exception e) { // finish(); // private void beginlistenfordata() { // TODO Auto-generated method stub private Object getdevicefrombondedlist(string selecteddevicename) { // TODO Auto-generated method stub return null; private void connect(bluetoothdevice device, BluetoothSerialClient handler) { mloadingdialog.setmessage("connecting..."); mloadingdialog.setcancelable(false); mloadingdialog.show(); BluetoothSerialClient btset = mclient; btset.connect(getapplicationcontext(), device, mbthandler); handler.write("44".getbytes()); /* try { Thread.sleep(12000); catch (InterruptedException e) { // TODO Auto-generated catch block e.printstacktrace(); handler.write("00".getbytes());*/ /* */ private BluetoothStreamingHandler mbthandler = new BluetoothStreamingHandler() { ByteBuffer mmbytebuffer = ByteBuffer.allocate(1024); public void onerror(exception e) { mloadingdialog.cancel(); addtext("blue : Connection error - " + e.tostring() + "\n"); mmenu.getitem(0).settitle(r.string.action_connect); public void ondisconnected() { mmenu.getitem(0).settitle(r.string.action_connect); mloadingdialog.cancel(); addtext("blue : Disconnected.\n"); - 22 -
public void ondata(byte[] buffer, int length) { if(length == 0) return; if(mmbytebuffer.position() + length >= mmbytebuffer.capacity()) { ByteBuffer newbuffer = ByteBuffer.allocate(mmByteBuffer.capacity() * 2); newbuffer.put(mmbytebuffer.array(), 0, mmbytebuffer.position()); mmbytebuffer = newbuffer; mmbytebuffer.put(buffer, 0, length); if(buffer[length - 1] == '\0') { addtext(mclient.getconnecteddevice().getname() + " : " + new String(mmByteBuffer.array(), 0, mmbytebuffer.position()) + '\n'); mmbytebuffer.clear(); public void onconnected() { addtext(" 1.. ## & ##\n" 2.. ## ## \n " + "3..\n 4. 5.\n # bluetooth name : " + " " + mclient.getconnecteddevice().getname() + "\n\n\n"); mloadingdialog.cancel(); mmenu.getitem(0).settitle(r.string.action_disconnect); ; private BluetoothSerialClient handler; private void sendmessage(charsequence message) { if (mbtservice.getstate()!= BluetoothService.STATE_CONNECTED) Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); return; public void sendstringdata(string data, int length) { data += '\0'; byte[] buffer = data.getbytes(); if(mbthandler.write(buffer)) { addtext("blue : " + data + '\n'); //************************************************************************* protected void ondestroy() { super.ondestroy(); - 23 -
mclient.claer(); ; public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.main, menu); mmenu = menu; return true; public boolean onoptionsitemselected(menuitem item) { boolean connect = mclient.isconnection(); if(item.getitemid() == R.id.action_connect) { if (!connect) { mdevicelistdialog.show(); else { mbthandler.close(); return true; else { showcodedlg(); return true; private void showcodedlg() { TextView codeview = new TextView(this); codeview.settext(html.fromhtml(readcode())); codeview.setmovementmethod(new ScrollingMovementMethod()); codeview.setbackgroundcolor(color.parsecolor("#202020")); new AlertDialog.Builder(this, android.r.style.theme_holo_light_dialogwhenlarge).setview(codeview).setpositivebutton("ok", new AlertDialog.OnClickListener() { public void onclick(dialoginterface dialog, int which) { dialog.cancel(); ).show(); private String readcode() { try { InputStream is = getassets().open("hc_06_echo.txt"); int length = is.available(); byte[] buffer = new byte[length]; is.read(buffer); is.close(); String code = new String(buffer); buffer = null; - 24 -
return code; catch (IOException e) { e.printstacktrace(); return ""; public void Rock(View view){ sendmessage("00"); public void Unrock(View view){ sendmessage("44"); //************************************************************************* - 25 -
<Bluetoothserialclient.java> package kr.re.dev.bluetooth; import java.io.ioexception; import java.io.inputstream; import java.io.outputstream; import java.util.set; import java.util.uuid; import java.util.concurrent.executorservice; import java.util.concurrent.executors; import java.util.concurrent.atomic.atomicboolean; import android.app.activity; import android.bluetooth.bluetoothadapter; import android.bluetooth.bluetoothdevice; import android.bluetooth.bluetoothsocket; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.intentfilter; import android.os.bundle; import android.os.handler; import android.os.looper; public class BluetoothSerialClient { static final private String SERIAL_UUID = "00001101-0000-1000-8000-00805F9B34FB"; static private BluetoothSerialClient sthis = null; private static String address = "20:15:06:10:58:94"; private BluetoothAdapter mbluetoothadapter; private OnBluetoothEnabledListener monbluetoothuplistener; private OnScanListener monscanlistener; private BluetoothSocket mbluetoothsocket; private UUID muuid = UUID.fromString(SERIAL_UUID); private AtomicBoolean misconnection = new AtomicBoolean(false); private ExecutorService mreadexecutor; private ExecutorService mwriteexecutor; private BluetoothStreamingHandler mbluetoothstreaminghandler; private Handler mmainhandler = new Handler(Looper.getMainLooper()); private BluetoothDevice cbnublue; private BluetoothDevice mconnecteddevice= cbnublue; private InputStream minputstream; private OutputStream moutputstream; /** * BluetoothSerialClient. * @return BluetoothSerialClient. null. - 26 -
*/ public static BluetoothSerialClient getinstance() { if(sthis == null) { sthis = new BluetoothSerialClient(); if(sthis.mbluetoothadapter == null) { sthis = null; return null; return sthis; private BluetoothSerialClient() { mbluetoothadapter = BluetoothAdapter.getDefaultAdapter(); mreadexecutor = Executors.newSingleThreadExecutor(); mwriteexecutor = Executors.newSingleThreadExecutor(); /** *. *. */ public void claer() { close(); mreadexecutor.shutdownnow(); mwriteexecutor.shutdownnow(); sthis = null; /** *. <br/> *,. * @param context activity * @param onbluetoothenabledlistener on/off. */ public void enablebluetooth(context context, OnBluetoothEnabledListener onbluetoothenabledlistener) { if(!mbluetoothadapter.isenabled()) { monbluetoothuplistener = onbluetoothenabledlistener; Intent intent = new Intent(context, BluetoothUpActivity.class); context.startactivity(intent); else { onbluetoothenabledlistener.onbluetoothenabled(true); /** - 27 -
*. * @return false off. */ public boolean isenabled() { return mbluetoothadapter.isenabled(); /** *. * @param context * @param device. {@link getpaireddevices {@link scandevices. * @param bluetoothstreaminghandler. * @return false. {@link enablebluetooth. */ public boolean connect(final Context context,final BluetoothDevice device, final BluetoothStreamingHandler bluetoothstreaminghandler) { if(!isenabled()) return false; mconnecteddevice = device; mbluetoothstreaminghandler = bluetoothstreaminghandler; if(isconnection()) { mwriteexecutor.execute(new Runnable() { public void run() { try { misconnection.set(false); mbluetoothsocket.close(); Thread.sleep(2000); catch (InterruptedException e) { e.printstacktrace(); catch (IOException e) { e.printstacktrace(); connect(context, device, bluetoothstreaminghandler); ); else { misconnection.set(true); connectclient(); return true; /** *. * @return */ - 28 -
public Set<BluetoothDevice> getpaireddevices() { Set<BluetoothDevice> paireddevices = mbluetoothadapter.getbondeddevices(); if(paireddevices.size() > 0){ BluetoothDevice getdevicefrombondedlist; { BluetoothDevice selecteddevice = null; //. return paireddevices; // TODO Auto-generated method stub /** *. * @param context * @param OnScanListener. * @return */ public boolean scandevices(context context, OnScanListener OnScanListener) { if(!mbluetoothadapter.isenabled()) return false; if(mbluetoothadapter.isdiscovering()) { mbluetoothadapter.canceldiscovery(); try { context.unregisterreceiver(mdiscoveryreceiver); catch(illegalargumentexception e) { e.printstacktrace(); monscanlistener = OnScanListener; IntentFilter filterfound = new IntentFilter(BluetoothDevice.ACTION_FOUND); filterfound.addaction(bluetoothadapter.action_discovery_started); filterfound.addaction(bluetoothadapter.action_discovery_finished); context.registerreceiver(mdiscoveryreceiver, filterfound); mbluetoothadapter.startdiscovery(); return true; /** *. * @param context */ public void cancelscan(context context) { if(!mbluetoothadapter.isenabled()!mbluetoothadapter.isdiscovering()) return; - 29 -
mbluetoothadapter.canceldiscovery(); try { context.unregisterreceiver(mdiscoveryreceiver); catch(illegalargumentexception e) { e.printstacktrace(); if(monscanlistener!= null) monscanlistener.onfinish(); /** *. * @return true/false */ public boolean isconnection() { return misconnection.get(); /** *. * @return null. */ public BluetoothDevice getconnecteddevice() { return mconnecteddevice; private void connectclient() { try { mbluetoothsocket = mconnecteddevice.createrfcommsockettoservicerecord(muuid); catch (IOException e) { close(); e.printstacktrace(); mbluetoothstreaminghandler.onerror(e); return; mwriteexecutor.execute(new Runnable() { public void run() { try { mbluetoothadapter.canceldiscovery(); mbluetoothsocket.connect(); manageconnectedsocket(mbluetoothsocket); callconnectedhandlerevent(); mreadexecutor.execute(mreadrunnable); catch (final IOException e) { close(); e.printstacktrace(); mmainhandler.post(new Runnable() { public void run() { - 30 -
mbluetoothstreaminghandler.onerror(e); ); misconnection.set(false); try { mbluetoothsocket.close(); catch (Exception ec) { ec.printstacktrace(); ); private void manageconnectedsocket(bluetoothsocket socket) throws IOException { minputstream = socket.getinputstream(); moutputstream = socket.getoutputstream(); private void callconnectedhandlerevent() { mmainhandler.post(new Runnable() { public void run() { mbluetoothstreaminghandler.onconnected(); ); public boolean write(final byte[] buffer) { if(!misconnection.get()) return false; mwriteexecutor.execute(new Runnable() { public void run() { try { moutputstream.write(buffer); catch (Exception e) { close(); e.printstacktrace(); mbluetoothstreaminghandler.onerror(e); ); return true; private boolean close() { mconnecteddevice = null; if(misconnection.get()) { misconnection.set(false); try { - 31 -
; ; mbluetoothsocket.close(); catch (IOException e) { e.printstacktrace(); mmainhandler.post(mcloserunable); return true; return false; private Runnable mcloserunable = new Runnable() { public void run() { if(mbluetoothstreaminghandler!= null) { mbluetoothstreaminghandler.ondisconnected(); private Runnable mreadrunnable = new Runnable() { public void run() { try { final byte[] buffer = new byte[256]; final int readbytes = minputstream.read(buffer); mmainhandler.post(new Runnable() { public void run() { if(mbluetoothstreaminghandler!= null) { mbluetoothstreaminghandler.ondata(buffer,readbytes); ); mreadexecutor.execute(mreadrunnable); catch (Exception e) { close(); e.printstacktrace(); private BroadcastReceiver mdiscoveryreceiver = new BroadcastReceiver() { public void onreceive(context context, Intent intent) { String action = intent.getaction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { BluetoothDevice device = intent.getparcelableextra(bluetoothdevice.extra_device); if(monscanlistener!= null) monscanlistener.onfounddevice(device); - 32 -
; else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { if(monscanlistener!= null) monscanlistener.onfinish(); try { context.unregisterreceiver(mdiscoveryreceiver); catch(illegalargumentexception e) { e.printstacktrace(); else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) { if(monscanlistener!= null) monscanlistener.onstart(); public static class BluetoothUpActivity extends Activity { private static int REQUEST_ENABLE_BT = 2; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getwindow().getdecorview().postdelayed(new Runnable() { public void run() { upbluetoothdevice();, 100); private void upbluetoothdevice() { BluetoothAdapter btadapter = BluetoothAdapter.getDefaultAdapter(); if (!btadapter.isenabled()) { Intent enablebtintent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); overridependingtransition(android.r.anim.fade_in, android.r.anim.fade_out); startactivityforresult(enablebtintent, REQUEST_ENABLE_BT) ; protected void onactivityresult(int requestcode, int resultcode, Intent data) { super.onactivityresult(requestcode, resultcode, data); if(requestcode == REQUEST_ENABLE_BT) { OnBluetoothEnabledListener onbluetoothenabledlistener = getinstance().monbluetoothuplistener; if (resultcode == Activity.RESULT_OK) { if(onbluetoothenabledlistener!= null) onbluetoothenabledlistener.onbluetoothenabled(true); finish(); else { if(onbluetoothenabledlistener!= null) onbluetoothenabledlistener.onbluetoothenabled(false); - 33 -
finish(); // End BluetoothUpActivity public static interface OnBluetoothEnabledListener { public void onbluetoothenabled(boolean success); public static interface OnScanListener { public void onstart(); public void onfounddevice(bluetoothdevice bluetoothdevice); public void onfinish(); public abstract static class BluetoothStreamingHandler { public abstract void onerror(exception e); public abstract void onconnected(); public abstract void ondisconnected(); public abstract void ondata(byte[] buffer, int length); public final boolean close() { BluetoothSerialClient btset = getinstance(); if(btset!= null) return btset.close(); return false; public final boolean write(byte[] buffer) { BluetoothSerialClient btset = getinstance(); if(btset!= null) return btset.write(buffer); return false; public void ondata(int i, int length) { // TODO Auto-generated method stub public void Rock(String string) { // TODO Auto-generated method stub public void Unrock(String string) { // TODO Auto-generated method stub public static String getaddress() { return address; public static void setaddress(string address) { BluetoothSerialClient.address = address; - 34 -
<androidmanifest.xml> <?xml version="1.0" encoding="utf-8" <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="kr.re.dev.bluetoothecho" android:versioncode="1" android:versionname="1.0" > <uses-permission android:name="android.permission.bluetooth" /> <uses-permission android:name="android.permission.bluetooth_admin" /> <uses-sdk android:minsdkversion="14" android:targetsdkversion="19" /> <application android:allowbackup="true" android:icon="@drawable/dsd" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="kr.re.dev.arduinoecho.mainactivity" android:label="@string/action_back" android:configchanges="screensize orientation keyboard" android:windowsoftinputmode="adjustresize"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="kr.re.dev.bluetooth.bluetoothserialclient$bluetoothupactivity" android:theme="@android:style/theme.translucent.notitlebar" android:configchanges="orientation screensize keyboard"></activity> </application> </manifest> - 35 -
<activity_main.xml> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="kr.re.dev.arduinoecho.mainactivity" tools:ignore="mergerootframe" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textviewterminal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#f0f8ff" android:scrollbars="vertical" android:textsize="12sp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/edittextinput" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="2" android:ems="4" android:inputtype="textpersonname" > <requestfocus /> </EditText> <Button android:id="@+id/buttonsend" style="?android:attr/buttonstylesmall" android:layout_width="80dp" android:layout_height="wrap_content" - 36 -
android:text="send" /> <Button android:id="@+id/rock" android:onclick="rock" android:layout_width="0px" android:layout_weight="2" android:layout_height="wrap_content" android:text="rock" android:textsize="12sp" /> <Button android:id="@+id/unrock" android:onclick="unrock" android:layout_width="0px" android:layout_weight="2" android:layout_height="wrap_content" android:text="unrock" android:textsize="12sp" /> </LinearLayout> </LinearLayout> </FrameLayout> <strings.xml> <?xml version="1.0" encoding="utf-8" <resources> <string name="app_name">5pen </string> <string name="action_connect">connect</string> <string name="action_arduinocode">arduino code</string> <string name="action_back">rock 5pen(feat., ) </string> <string name="action_disconnect">disconnect</string> <string name="action_settings"> </string> </resources> - 37 -