Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of football_project by
Diff: PhoneAppIO.h
- Revision:
- 5:1b9734e68327
- Child:
- 11:d3aa5fca2330
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PhoneAppIO.h Fri Apr 17 04:20:07 2015 +0000
@@ -0,0 +1,88 @@
+/*
+ * Buffered IO of pending CharacteristicWrites meant to Nofify
+ * the phone/tablet application. ALS 20150416
+ *
+ */
+
+#ifndef PHONEAPPIO_H
+#define PHONEAPPIO_H
+
+#include "mbed.h"
+#include "BLEDevice.h"
+#include <cstdarg>
+#include "MTSBufferedIO.h"
+
+#define STRING_STACK_LIMIT 120
+
+// namespace moo
+// {
+
+class PhoneAppIO : public mts::MTSBufferedIO
+{
+ public:
+ PhoneAppIO( BLEDevice *ble, int txBufferSize=1280, int rxBufferSize=1280 );
+
+ /** Destructs an MTSSerial object and frees all related resources, including
+ * internal buffers.
+ */
+ ~PhoneAppIO();
+
+ /** Write a string to the buffer
+ *
+ * @param str The string to write
+ *
+ * @returns 0 if the write succeeds, EOF for error
+ */
+ int puts( const char *str )
+ {
+ return write( str, strlen( str ) );
+ }
+
+ int printf( const char *format, ... )
+ {
+ va_list arg;
+ va_start( arg, format );
+
+ int len = PhoneAppIO::vprintf( format, arg );
+
+ va_end( arg );
+
+ return len;
+ }
+ int vprintf( const char *format, va_list arg )
+ {
+ int len = vsnprintf( NULL, 0, format, arg );
+ if( len < STRING_STACK_LIMIT )
+ {
+ char temp[STRING_STACK_LIMIT];
+ vsprintf( temp, format, arg );
+ puts( temp );
+
+ } else
+ {
+ char *temp = new char[len + 1];
+ vsprintf( temp, format, arg );
+ puts( temp );
+ delete[] temp;
+ }
+
+ return len;
+ }
+
+ void toPhoneBuf( uint8_t *data, uint16_t bytesRead );
+
+ protected:
+ BLEDevice *ble;
+ uint8_t *data;
+ uint16_t bytesRead;
+
+ private:
+ virtual void handleWrite(); // Method for handling data to be written
+ virtual void handleRead(); // Method for handling data to be read
+};
+
+// }
+
+#endif /* PHONEAPPIO_H */
+
+/* EOF */
