football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
17:d8b901d791fd
Parent:
16:3c873f2c8a27
Child:
18:affef3a7db2a
--- a/main.cpp	Sat Jul 11 01:57:40 2015 +0000
+++ b/main.cpp	Tue Nov 03 07:05:15 2015 +0000
@@ -57,6 +57,22 @@
 #define DEBUG(...) /* nothing */
 #endif /* #if NEED_CONSOLE_OUTPUT */
 
+void loop();
+void setup();
+void getRadioInput(char *ibuffer, int size);
+
+Timer tmr;
+
+unsigned long millis()
+{
+    return tmr.read_ms();
+}
+
+unsigned long micros()
+{
+    return tmr.read_us();    
+}
+
 extern "C"
 {
 #include "softdevice_handler.h"  // Attempt to get pstorage enqueued cmd callbacks.
@@ -157,6 +173,16 @@
     return  (err != BLE_ERROR_NONE);
 }
 
+void writeToPhone(char *data)
+{
+    pcfc.write(data, strlen(data));
+    if (phoneP != NULL)
+    {
+        //phoneP->puts(data);
+            
+    }
+}
+
 void onDataWritten( const GattCharacteristicWriteCBParams *params )
 {
     if( phoneP != NULL )
@@ -165,7 +191,7 @@
         if( 0 != bytesRead )
         {
             DEBUG( "received %u bytes\n\r", bytesRead );
-
+            getRadioInput((char*)txPayload, bytesRead );
             // Also write to serial port...
 //            pcfc.printf( "From app: " );
             pcfc.write( (char *)txPayload, bytesRead );
@@ -329,8 +355,8 @@
 
 void periodicCallback( void )
 {
-    led0 = !led0;
-    led1 = !led1;
+    //led0 = !led0;
+    //led1 = !led1;
 //    rts  = !rts;
 }
 
@@ -352,7 +378,7 @@
     // NVIC_SetVector( UART0_IRQn, (uint32_t)My_UART0_IRQHandler );  // TODO maybe try before instantiating pcfc.
 
     Ticker ticker;
-    ticker.attach( periodicCallback, 1 );
+    ticker.attach( periodicCallback, .01 );
     // Thread thread( led_thread );
 
     pcfc.baud( 57600 );
@@ -430,20 +456,23 @@
     phone.loopbackMode = LOOPBACK_MODE;
     phoneP = ☎
 
-    Timer tmr;
+    setup();
+
     tmr.start();
 
     // Main Loop
-    for( uint32_t loop=1; ;loop++ )
+    while( true)
     {
         ble.waitForEvent();
-
+    
         toPhoneChk();  // Write any pending data to phone.
 
         while( 0 <= phone.getchar() );  // Eat input.
 
 //        if( !(loop % 50) )  phone.printf( "Post: %d\r\n", tmr.read_ms() );
 
+        loop();
+
         app_sched_execute();  // Attempt to get pstorage enqueued cmd callbacks.
 
         // Update persistent storage if ready...