Update of /cvsroot/playerstage/code/player/client_libs/libplayerc/test
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15262/client_libs/libplayerc/test

Modified Files:
        Makefile.am test.c 
Added Files:
        test_blinkenlight.c 
Log Message:
added chatterbox driver, fixed build bug in libplayerc/dev_vectormap.c, fixed 
shallow copy bug in libplayerc/dev_ir.c

--- NEW FILE: test_blinkenlight.c ---
/***************************************************************************
 * Desc: Tests for the dio device
 * Author: Alexis Maldonado
 * Date: 3 May 2007
 **************************************************************************/

#include <unistd.h>

#include "test.h"
#include "playerc.h"

const uint32_t LIGHTCOUNT = 5;

// Basic test for an dio device.
int test_blinkenlight(playerc_client_t *client, int index) {
    int t;
    void *rdevice;
    playerc_blinkenlight_t *device;

    printf("device [blinkenlight] index [%d]\n", index);

    device = playerc_blinkenlight_create(client, index);

    TEST("subscribing (read/write)");
    if (playerc_blinkenlight_subscribe(device, PLAYER_OPEN_MODE) < 0) {
        FAIL();
        return -1;
    }
    PASS();
    
/*     for (t = 0; t < 5; t++) { */
/*       TEST1("reading light state (attempt %d)", t); */
      
/*       do */
/*      rdevice = playerc_client_read(client); */
/*       while (rdevice == client); */
      
/*       if (rdevice == device)  */
/*      { */
/*        PASS(); */
          
/*        printf("blinkenlight: enable %u color (%hhX,%hhX,%hhX) period %.3f 
duty %.3f\n", */
/*               device->enable, */
/*               device->red, */
/*             device->green, */
/*               device->blue, */
/*               device->period, */
/*               device->duty ); */
          
/*      } */
/*       else { */
/*      //printf("error: %s", playerc_error_str()); */
/*      FAIL(); */
/*      break; */
/*       } */
/*     } */
    
    unsigned long shortsleep = 200000L;
    unsigned long longsleep = 500000L;
    
    TEST("Turning light on");
    if (playerc_blinkenlight_enable( device, 1 )  != 0) 
        FAIL();
    PASS();
    usleep( longsleep );
    
    TEST("Turning light off");
    if (playerc_blinkenlight_enable( device, 0 )  != 0) 
        FAIL();
    PASS();
    usleep( longsleep );

    TEST("Turning light on");
    if (playerc_blinkenlight_enable( device, 1 )  != 0) 
      FAIL();
    PASS();
    usleep( longsleep );
            
    int u;

    TEST( "Setting colors RED");
    for( u=5; u<256; u+=50 )
      {     
        for( index=0; index<LIGHTCOUNT; index++ )
          {
            if (playerc_blinkenlight_color(device, index, u,0,0 )  != 0) 
              {
                FAIL();
                break;
            }
            usleep( shortsleep );
          }
      }
    PASS();

    int lightnum;

    TEST( "Setting colors GREEN");
    for( u=5; u<256; u+=50 )
      {     
        for( lightnum=0; lightnum<LIGHTCOUNT; lightnum++ )
          {
            if (playerc_blinkenlight_color(device, lightnum, 0,u,0 )  != 0) 
              {
                FAIL();
                break;
              }
            usleep( shortsleep );
          }
      }
    PASS();
    
    TEST( "Setting colors BLUE");
    for( u=5; u<256; u+=50 )
      {     
        for( lightnum=0; lightnum<LIGHTCOUNT; lightnum++ )
          {
            if (playerc_blinkenlight_color(device, lightnum, 0,0,u )  != 0) 
              {
                FAIL();
                break;
              }
            usleep( shortsleep );
          }
      }
    PASS();
    
    TEST( "Setting colors R+G+B");
    for( u=5; u<256; u+=50 )
      {     
        for( lightnum=0; lightnum<LIGHTCOUNT; lightnum++ )
        {
          if (playerc_blinkenlight_color(device, lightnum, u,u,u )  != 0) 
            {
              FAIL();
              break;
            }
          usleep( shortsleep );
        }
      }
    PASS();

    TEST( "Setting colors randomly");
    for( u=0; u<10; u++ )
      {     
        for( lightnum=0; lightnum<LIGHTCOUNT; lightnum++ )
          {
            if (playerc_blinkenlight_color(device, 
                                           lightnum,
                                           random()%255,
                                           random()%255,
                                           random()%255) != 0) 
              {
                FAIL();
                break;
              }
            usleep( shortsleep );
          }
      }
    PASS();
    usleep(longsleep);  //some time to see the effect

    TEST("Varying blink rate");
    
    double rate;
    double duty;
    
    for( rate=3; rate<=10; rate++ )
      for( duty=0.1; rate<=1.0; rate+=0.1 )
        for( lightnum=0; lightnum<6; lightnum++ )
          if (playerc_blinkenlight_blink( device, lightnum, rate, duty  )  != 
0) 
            {
              FAIL();
              break;
            }
    PASS();

    TEST("Turning light off");
    if (playerc_blinkenlight_enable( device, 0 )  != 0) 
        FAIL();
    PASS();
    
    TEST("unsubscribing");
    if (playerc_blinkenlight_unsubscribe(device) != 0)
      FAIL();
    PASS();
    
    playerc_blinkenlight_destroy(device);
    
    return 0;
}


Index: test.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/test/test.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** test.c      19 Jun 2007 02:01:08 -0000      1.49
--- test.c      7 Feb 2008 02:22:59 -0000       1.50
***************
*** 179,182 ****
--- 179,186 ----
          break;
  
+       // Blobfinder device
+       case PLAYER_BLINKENLIGHT_CODE:
+         test_blinkenlight(client, client->devinfos[i].addr.index);
+         break;
  
        // Camera device

Index: Makefile.am
===================================================================
RCS file: 
/cvsroot/playerstage/code/player/client_libs/libplayerc/test/Makefile.am,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** Makefile.am 21 Aug 2007 23:16:23 -0000      1.46
--- Makefile.am 7 Feb 2008 02:22:59 -0000       1.47
***************
*** 15,18 ****
--- 15,19 ----
        test.c \
        test.h \
+       test_blinkenlight.c \
        test_blobfinder.c \
        test_camera.c \


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to