diff options
| author | Keith Packard <keithp@keithp.com> | 2014-08-17 20:48:23 -0700 |
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2014-08-17 20:48:23 -0700 |
| commit | 59dfe661fcb504f390d9726378c676f2b5b005f3 (patch) | |
| tree | 3b04fce1f5365ba7f98768dcaa3b29bfbb0afcb4 /altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java | |
| parent | b1f1844aa514893228080704da3b3ccf855bda1e (diff) | |
altosdroid: Skip updating hidden UI elements
Instead of updating everything in the UI, only update the visible UI
elements to save a bunch of computation.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java')
| -rw-r--r-- | altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java index a599698f..484efaf8 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java @@ -174,18 +174,29 @@ public class AltosBluetooth extends AltosLink { } catch (InterruptedException e) { connection_lost(); } - } + } + + 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() { - try { - wait_connected(); - return input.read(); - } catch (IOException e) { - connection_lost(); - } catch (java.lang.InterruptedException e) { - connection_lost(); + 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 AltosLink.ERROR; + return buffer[buffer_off++]; } public void close() { |
