X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosBluetooth.java;h=484efaf833a6ee4ad2e41ddc13e771d60473e82f;hb=59dfe661fcb504f390d9726378c676f2b5b005f3;hp=0aea06f1cf22a242cf89489768070522caafdf15;hpb=8d1d8d2a3c129cdbd55427bcda0f26715b02f1ee;p=fw%2Faltos diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java index 0aea06f1..484efaf8 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java @@ -31,7 +31,7 @@ import android.os.Handler; //import android.os.Message; import android.util.Log; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_5.*; public class AltosBluetooth extends AltosLink { @@ -162,16 +162,41 @@ public class AltosBluetooth extends AltosLink { } } - public int getchar() { + public void putchar(byte c) { + byte[] bytes = { c }; + if (D) Log.d(TAG, "print(): begin"); try { wait_connected(); - return input.read(); + output.write(bytes); + if (D) Log.d(TAG, "print(): Wrote byte: '" + c + "'"); } catch (IOException e) { connection_lost(); - } catch (java.lang.InterruptedException e) { + } catch (InterruptedException e) { connection_lost(); } - return AltosLink.ERROR; + } + + private static final int buffer_size = 1024; + + private byte[] buffer = new byte[buffer_size]; + private int buffer_len = 0; + private int buffer_off = 0; + + public int getchar() { + while (buffer_off == buffer_len) { + try { + wait_connected(); + buffer_len = input.read(buffer); + buffer_off = 0; + } catch (IOException e) { + connection_lost(); + return AltosLink.ERROR; + } catch (java.lang.InterruptedException e) { + connection_lost(); + return AltosLink.ERROR; + } + } + return buffer[buffer_off++]; } public void close() {