changeset 137:468faf23535b main

Integrate recent changes from upstream.
author Bob Cook <bob@bobcookdev.com>
date Thu, 12 Jan 2012 21:29:18 -0800
parents 6a258aafc9d7 (current diff) 4da44007d8cb (diff)
children a832a6908d9e
files
diffstat 2 files changed, 205 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/main/projects/robocam/data.cpp	Thu Jan 12 21:28:39 2012 -0800
+++ b/main/projects/robocam/data.cpp	Thu Jan 12 21:29:18 2012 -0800
@@ -1,6 +1,6 @@
 // ----------------------------------------------------------------------------------------
 //
-//  Copyright (C) 2010 Bob Cook
+//  Copyright (C) 2011 Bob Cook
 //    
 //  Bob Cook Development, Robotics Library
 //  http://www.bobcookdev.com/rl/
@@ -47,6 +47,9 @@
 
 // ----------------------------------------------------------------------------------------
 
+#define ROBOCAM_DATA_ID "ROBOCAMERA 1.0"
+
+// ----------------------------------------------------------------------------------------
 uint8_t g_data_buf_1[ 512 ];
 uint8_t g_data_buf_2[ 512 ];
 
@@ -226,7 +229,7 @@
     }
 
     memset( g_data_buf_1, 0x00, sizeof( g_data_buf_1 ) );
-    strcpy_P( reinterpret_cast< char* >( g_data_buf_1 ), PSTR("ROBOCAMERA 1.0") );
+    strcpy_P( reinterpret_cast< char* >( g_data_buf_1 ), PSTR( ROBOCAM_DATA_ID ) );
     strcpy_P( reinterpret_cast< char* >( &g_data_buf_1[ 16 ] ),
               PSTR("Robotic Camera Platform by Bob Cook, bob@bobcookdev.com") );
 
@@ -341,14 +344,11 @@
         return false;
     }
 
-#if 0
-    if ( ! strcmp_P( reinterpret_cast< char* >( g_data_buf_1 ), PSTR("ROBOCAMERA 1.0") ) )
+    if ( ! strcmp_P( PSTR( ROBOCAM_DATA_ID ), reinterpret_cast< char* >( g_data_buf_1 ) ) )
     {
         error_report( error_playback_card_not_recognized );
-        printf_P( PSTR("failed to compare string\n") );
         return false;
     }
-#endif
 
     uint32_t* tval_ptr = reinterpret_cast< uint32_t* >( &g_data_buf_1[ 128 ] );
     g_total_values = *tval_ptr;
@@ -443,14 +443,11 @@
         return false;
     }
 
-#if 0
-    if ( ! strcmp_P( reinterpret_cast< char* >( g_data_buf_1 ), PSTR("ROBOCAMERA 1.0") ) )
+    if ( ! strcmp_P( PSTR( ROBOCAM_DATA_ID ), reinterpret_cast< char* >( g_data_buf_1 ) ) )
     {
         error_report( error_reverse_card_not_recognized );
-        printf_P( PSTR("failed to compare string\n") );
         return false;
     }
-#endif
 
     uint32_t* tval_ptr = reinterpret_cast< uint32_t* >( &g_data_buf_1[ 128 ] );
     g_total_values = *tval_ptr;
@@ -466,9 +463,6 @@
 
     g_data_count = g_total_values % 170;
     g_next_sdcard_block = ( g_total_values / 170 ) + 1;
-printf_P( PSTR("g_total_values = %ld \n"), g_total_values );
-printf_P( PSTR("    g_next_sdcard_block = %d \n"), g_next_sdcard_block );
-printf_P( PSTR("    g_data_count        = %d \n"), g_data_count );
 
     //--    Read the first two blocks of recorded data, and set up the data structures.
 
@@ -480,7 +474,7 @@
     --g_next_sdcard_block;
     g_data_buf_1_full = true;
 
-    if ( g_next_sdcard_block > 1 )
+    if ( g_next_sdcard_block > 0 )
     {
         if ( ! sdcard_read_block( g_next_sdcard_block, g_data_buf_2 ) )
         {
@@ -506,7 +500,7 @@
     //      one empty buffer at any given time; if that was not true, this function
     //      could potentially fill the buffers out of order.
 
-    if ( g_next_sdcard_block == 1 )
+    if ( g_next_sdcard_block == 0 )
     {
         return true; // well, nothing more to read, but not an error
     }
--- a/main/projects/robocam/diag.cpp	Thu Jan 12 21:28:39 2012 -0800
+++ b/main/projects/robocam/diag.cpp	Thu Jan 12 21:29:18 2012 -0800
@@ -1,6 +1,6 @@
 // ----------------------------------------------------------------------------------------
 //
-//  Copyright (C) 2010 Bob Cook
+//  Copyright (C) 2011 Bob Cook
 //    
 //  Bob Cook Development, Robotics Library
 //  http://www.bobcookdev.com/rl/
@@ -34,6 +34,7 @@
 #include <string.h>
 
 #include "controls.h"
+#include "data.h"
 #include "steppers.h"
 #include "project_defs.h"
 
@@ -355,6 +356,174 @@
 
 // ----------------------------------------------------------------------------------------
 
+void data_playback()
+{
+    printf_P( PSTR("data playback (q to abort)\n") );
+
+    if ( ! data_prepare_to_playback() )
+    {
+        printf_P( PSTR("error: data_prepare_to_playback() failed\n\n") );
+        return;
+    }
+
+    printf_P( PSTR("-----------------------------\n") );
+
+    uint32_t count = 0;
+
+    while ( ! data_is_playback_complete() )
+    {
+        uint8_t stepper_x;
+        uint8_t stepper_y;
+        uint8_t stepper_z;
+
+        if ( data_read_values( &stepper_x, &stepper_y, &stepper_z ) )
+        {
+            printf_P( PSTR("%08ld %04d %04d %04d\n"), count, stepper_x, stepper_y, stepper_z );
+            ++count;
+        }
+        else
+        {
+            printf_P( PSTR("-----------------------------\n") );
+            printf_P( PSTR("playback complete\n\n") );
+            return;
+        }
+
+        if ( ! data_playback_update() )
+        {
+            printf_P( PSTR("error: data_playback_update() failed\n\n") );
+            return;
+        }
+
+        int  c = getchar();
+        if ( c == 'q' ) break;
+    }
+
+    putchar( '\n' );
+}
+
+// ----------------------------------------------------------------------------------------
+
+void data_playback_reverse()
+{
+    printf_P( PSTR("data playback reverse (q to abort)\n") );
+
+    if ( ! data_prepare_to_reverse() )
+    {
+        printf_P( PSTR("error: data_prepare_to_reverse() failed\n\n") );
+        return;
+    }
+
+    printf_P( PSTR("-----------------------------\n") );
+
+    uint32_t count = 0;
+
+    while ( ! data_is_reverse_complete() )
+    {
+        uint8_t stepper_x;
+        uint8_t stepper_y;
+        uint8_t stepper_z;
+
+        if ( data_read_reverse_values( &stepper_x, &stepper_y, &stepper_z ) )
+        {
+            printf_P( PSTR("%08ld %04d %04d %04d\n"), count, stepper_x, stepper_y, stepper_z );
+            ++count;
+        }
+        else
+        {
+            printf_P( PSTR("-----------------------------\n") );
+            printf_P( PSTR("playback reverse complete\n\n") );
+            break;
+        }
+
+        if ( ! data_reverse_update() )
+        {
+            printf_P( PSTR("error: data_reverse_update() failed\n\n") );
+            return;
+        }
+
+        int  c = getchar();
+        if ( c == 'q' ) break;
+    }
+
+    putchar( '\n' );
+}
+
+// ----------------------------------------------------------------------------------------
+
+void data_record_test_pattern_1()
+{
+    printf_P( PSTR("data record test pattern #1\n") );
+
+    if ( ! data_prepare_to_record() )
+    {
+        printf_P( PSTR("error: data_prepare_to_record() failed\n\n") );
+        return;
+    }
+
+    uint8_t v = 0;
+
+    for ( uint32_t i = 0; i < 163; ++i )
+    {
+        uint8_t stepper_x = v++;
+        uint8_t stepper_y = v++;
+        uint8_t stepper_z = v++;
+
+        data_save_values( stepper_x, stepper_y, stepper_z );
+
+        if ( ! data_recording_update() )
+        {
+            printf_P( PSTR("error: data_recording_update() failed\n\n") );
+            return;
+        }
+    }
+
+    if ( ! data_complete_recording() )
+    {
+        printf_P( PSTR("error: data_recording_complete() failed\n\n") );
+    }
+
+    putchar( '\n' );
+}
+
+// ----------------------------------------------------------------------------------------
+
+void data_record_test_pattern_2()
+{
+    printf_P( PSTR("data record test pattern #2\n") );
+
+    if ( ! data_prepare_to_record() )
+    {
+        printf_P( PSTR("error: data_prepare_to_record() failed\n\n") );
+        return;
+    }
+
+    uint8_t v = 0;
+
+    for ( uint32_t i = 0; i < 523; ++i )
+    {
+        uint8_t stepper_x = v++;
+        uint8_t stepper_y = v++;
+        uint8_t stepper_z = v++;
+
+        data_save_values( stepper_x, stepper_y, stepper_z );
+
+        if ( ! data_recording_update() )
+        {
+            printf_P( PSTR("error: data_recording_update() failed\n\n") );
+            return;
+        }
+    }
+
+    if ( ! data_complete_recording() )
+    {
+        printf_P( PSTR("error: data_recording_complete() failed\n\n") );
+    }
+
+    putchar( '\n' );
+}
+
+// ----------------------------------------------------------------------------------------
+
 void do_diagnostics()
 {
     for ( ;; )
@@ -366,6 +535,10 @@
         printf_P( PSTR("5. test leds\n") );
         printf_P( PSTR("6. test the button\n") );
         printf_P( PSTR("7. test steppers\n") );
+        printf_P( PSTR("8. data playback\n") );
+        printf_P( PSTR("9. data playback (reverse)\n") );
+        printf_P( PSTR("A. data record test pattern #1\n") );
+        printf_P( PSTR("B. data record test pattern #2\n") );
         
         bool did_cmd = false;
 
@@ -410,6 +583,28 @@
                     did_cmd = true;
                     break;
 
+                case '8':
+                    data_playback();
+                    did_cmd = true;
+                    break;
+
+                case '9':
+                    data_playback_reverse();
+                    did_cmd = true;
+                    break;
+
+                case 'a':
+                case 'A':
+                    data_record_test_pattern_1();
+                    did_cmd = true;
+                    break;
+
+                case 'b':
+                case 'B':
+                    data_record_test_pattern_2();
+                    did_cmd = true;
+                    break;
+
                 default:
                     break;
             }