Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
5:1b9734e68327
Child:
11:d3aa5fca2330
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PhoneAppIO.cpp	Fri Apr 17 04:20:07 2015 +0000
@@ -0,0 +1,63 @@
+/*
+ *  Buffered IO of pending CharacteristicWrites meant to Nofify
+ *   the phone/tablet application.   ALS  20150416
+ *
+ */
+
+#include "PhoneAppIO.h"
+
+PhoneAppIO::PhoneAppIO( BLEDevice *ble, int txBufferSize, int rxBufferSize )
+            : mts::MTSBufferedIO( txBufferSize, rxBufferSize )
+{
+    PhoneAppIO::ble = ble;
+    data            = NULL;
+    bytesRead       = 0;
+}
+
+PhoneAppIO::~PhoneAppIO()
+{
+}
+
+
+void PhoneAppIO::toPhoneBuf( uint8_t *data, uint16_t bytesRead )
+{
+    PhoneAppIO::data      = data;
+    PhoneAppIO::bytesRead = bytesRead;
+    handleRead();
+}
+
+void PhoneAppIO::handleRead()
+{
+    int charsToBuf = rxBuffer.write( (char *)data, bytesRead );
+    if( charsToBuf != bytesRead )
+    {
+        printf( "[ERROR] ToPhoneCharacteristic Data Lost, tried %d, got %d\r\n", bytesRead, charsToBuf );
+    }
+}
+
+void PhoneAppIO::handleWrite()
+{
+    /** This method should be used to transfer
+    * data from the internal write buffer (txBuffer) to the physical interface.
+    * Note that this function is called everytime new data is written to the
+    * txBuffer though one of the write calls.
+    */
+
+    while( txBuffer.size() != 0 )
+    {
+        if( 1 /* ble. writeable() */ )
+        {
+            char byte;
+            if( txBuffer.read( byte ) == 1 )
+            {
+                // Write Characteristic
+            }
+
+        } else
+          {
+              return;
+          }
+    }
+}
+
+/* EOF */