Changeset 1596 for trunk

Show
Ignore:
Timestamp:
01/22/12 00:23:42 (4 months ago)
Author:
reyalp
Message:

usb remote update from waterwingz in  http://chdk.setepontos.com/index.php?topic=650.msg80306#msg80306
1) Modified get_usb_power for uBasic - now act as if passed parameter = 0 if none is specified.
2) Deleted unnecessary input modules P.Width and P.Count. Values are maintained by usb_remote_key().
3) Changed code in remote_key() to only calculate USB remote information when conf.remote is true. (Can still get USB state though).
4) General clean-up of some hard coded constants using enums.

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/core/gui.c

    r1593 r1596  
    230230//------------------------------------------------------------------- 
    231231 
    232 const char* gui_USB_switch_types[] = { "None","OnePush", "TwoPush", "CA-1", "P Width", "P Count" }; 
    233 const char* gui_USB_control_modes[] = { "None", "Normal", "Quick", "Burst", "Bracket","Zoom", "Video" };  
     232const char* gui_USB_switch_types[] = { "None","OnePush", "TwoPush", "CA-1" };                                                           // note : make sure # of entries less than NUM_USB_INPUT_DRV in usb_remote.c 
     233const char* gui_USB_control_modes[] = { "None", "Normal", "Quick", "Burst", "Bracket","Zoom", "Video" };        // note : make sure # of entries less than NUM_USB_MODULES in usb_remote.c 
    234234   
    235235 
  • trunk/core/usb_input.c

    r1585 r1596  
    2626 
    2727extern int usb_remote_active ; 
    28 extern int virtual_remote_pulse_count ; 
    29 extern int virtual_remote_pulse_width ; 
    3028extern int stime_stamp ; 
    3129extern int sync_counter; 
     
    343341} ; 
    344342 
    345 /*--------------------------------------------------------------------------------------------------- 
    346         Device Driver : pulse width modulation device 
    347                 - gets the width of USB power pulses 
    348                 - does not set virtual switch states 
    349                 - hand shake mechanism with control modules is simply them clearing the report pulse width value 
    350                 - might be useful for gentles modules or some custom microcontroller device 
    351   ---------------------------------------------------------------------------------------------------*/ 
    352 void usb_pwm_device(int usb_state) 
    353 { 
    354         int pw ; 
    355  
    356         switch( driver_state ) 
    357         { 
    358                 case SW_RESET : 
    359                         virtual_remote_state = REMOTE_RESET ; 
    360                         driver_state = SW_IDLE ; 
    361                         break ; 
    362  
    363                 case SW_IDLE : 
    364                         pw = get_usb_power(2) ; 
    365                         if ( pw != 0) virtual_remote_pulse_width  = pw ; 
    366                         break ; 
    367  
    368                 default : 
    369                         debug_error(INVALID_STATE) ; 
    370                         break ; 
    371         } 
    372 } ; 
    373  
    374 /*--------------------------------------------------------------------------------------------------- 
    375         Device Driver :  pulse counting device 
    376                 - counts USB pulses (off-on-off) 
    377                 - ignores short pulses less that 100 mSec ( CA-1 reset and half shoot pulses ) 
    378                 - does not set virtual switch states 
    379                 - hand shake mechanism with control modules is simply them clearing the report pulse width value 
    380                 - might be useful for gentles modules or some custom microcontroller device 
    381   ---------------------------------------------------------------------------------------------------*/ 
    382 void usb_pulse_count_device(int usb_state) 
    383 { 
    384         int pc ; 
    385  
    386         switch( driver_state ) 
    387         { 
    388                 case SW_RESET : 
    389                         virtual_remote_state = REMOTE_RESET ; 
    390                         driver_state = SW_IDLE ; 
    391                         break ; 
    392  
    393                 case SW_IDLE : 
    394                         pc = get_usb_power(3) ; 
    395                         if ( pc != 0) virtual_remote_pulse_count  = pc ; 
    396                         break ; 
    397  
    398                 default : 
    399                         debug_error(INVALID_STATE) ; 
    400                         break ; 
    401         } 
    402  
    403 } ; 
    404343 
    405344 /*=================================================================================================== 
     
    418357                        usb_two_press_switch , 
    419358                        usb_ricoh_ca1_switch , 
    420                         usb_pwm_device , 
    421                         usb_pulse_count_device , 
    422                         usb_null_driver , 
    423                         usb_null_driver , 
    424                         usb_null_driver , 
    425                         usb_null_driver 
     359                        usb_null_driver                                                                         // <- insert new devices here - update NUM_USB_INPUT_DRV if necessary 
    426360        }; 
  • trunk/core/usb_module.c

    r1593 r1596  
    2727extern int usb_sync_wait ; 
    2828extern int usb_remote_active ; 
    29 extern int virtual_remote_pulse_count ; 
    30 extern int virtual_remote_pulse_width ; 
    3129extern int stime_stamp ; 
    3230extern int sync_counter; 
    3331extern int usb_sync_wait ; 
     32 
     33extern int get_usb_power(int) ; 
    3434 
    3535extern enum SWITCH_TYPE  switch_type ; 
     
    7878 
    7979                case LM_RELEASE : 
    80                         i =  get_usb_power(3) ; 
     80                        i =  get_usb_power(PULSE_COUNT) ; 
    8181                        switch( i ) 
    8282                        { 
     
    469469 
    470470                case LM_RELEASE : 
    471                         switch( virtual_remote_pulse_count ) 
     471                        switch( get_usb_power(PULSE_COUNT) ) 
    472472                        { 
    473473                                case ZOOM_STEP_OUT : 
     
    507507                        break ; 
    508508        } 
    509  
    510         virtual_remote_pulse_count =  0; 
    511  
    512509}; 
    513510 
     
    737734                                usb_playback_module ,                   // [  gWIRE] 
    738735                                usb_playback_module ,                   // [ Script] 
    739                                 usb_null_module                                 // -- 
     736                                usb_null_module                                 // <- insert new playback module here - update NUM_USB_MODULES if necessary 
    740737        }; 
    741738 
     
    752749                                usb_shoot_module_zoom ,                 // [   Zoom] 
    753750                                usb_null_module ,                               // [  Video] 
    754                                 usb_null_module,                                // -- 
     751                                usb_null_module,                                // <- insert new shoot module here - update NUM_USB_MODULES if necessary 
    755752                                usb_null_module,                                // -- 
    756753                                usb_null_module                                 // -- 
     
    769766                                usb_null_module ,                               // [   Zoom] 
    770767                                usb_video_module_normal ,               // [  Video] 
    771                                 usb_null_module ,                               // -- 
     768                                usb_null_module ,                               // <- insert new video module here - update NUM_USB_MODULES if necessary 
    772769                                usb_null_module ,                               // -- 
    773770                                usb_null_module                                 // -- 
  • trunk/core/usb_remote.c

    r1593 r1596  
    3737int usb_sync_wait = 0 ; 
    3838int usb_remote_active=0 ; 
    39 int virtual_remote_pulse_count = 0 ; 
    40 int virtual_remote_pulse_width = 0 ; 
    4139int stime_stamp = 0 ; 
    4240int usb_power=0; 
     
    228226        remote_key = get_usb_bit() ; 
    229227 
    230         if (remote_key) remote_count++ ;                                                                        // track how long the USB power is on 
    231         else if(remote_space_count<3000) remote_space_count++ ;                         // track how long the USB power is off 
    232          
    233         if ( remote_space_count > 50 )                                                                  // pulse counting done if no activity for 500mSec 
    234         { 
    235                 if( pulse_count > 0 ) 
    236                 { 
    237                         usb_count = pulse_count ; 
    238                         pulse_count = 0 ; 
    239                 } 
    240         } 
    241  
    242         if (( remote_key == 0) && (remote_count > 0)  )                                                                                         //  1 -> 0 transistion ? 
    243         { 
    244                 if( remote_count > 10 ) pulse_count++ ;                                                                                                 // count pulses longer than 100 msec 
    245  
    246                 usb_power = remote_count;                                                                                                                               // transfer most recent pulse length to variable read by scripts 
     228        if(conf.remote_enable) 
     229        { 
     230                if (remote_key) remote_count++ ;                                                                        // track how long the USB power is on 
     231                else if(remote_space_count<3000) remote_space_count++ ;                         // track how long the USB power is off 
    247232                 
    248                 if ( ++usb_buffer_in > &usb_buffer[USB_BUFFER_SIZE-1] ) usb_buffer_in = usb_buffer ;    // insert power pulse width into the buffer 
    249                 if ( usb_buffer_in == usb_buffer_out ) 
    250                 { 
    251                         if ( ++usb_buffer_out > &usb_buffer[USB_BUFFER_SIZE-1] ) usb_buffer_out = usb_buffer ; 
    252                 } 
    253                 *usb_buffer_in = remote_count ; 
    254                 remote_count = 0; 
    255         } 
    256  
    257         if (( remote_key == 1) && (remote_space_count > 0)  )                                                                           // 0 -> 1 transistion ? 
    258         { 
    259                 if ( ++usb_buffer_in > &usb_buffer[USB_BUFFER_SIZE-1] ) usb_buffer_in = usb_buffer ;    // insert space pulse width into the buffer as a negative number 
    260                 if ( usb_buffer_in == usb_buffer_out ) 
    261                 { 
    262                         if ( ++usb_buffer_out > &usb_buffer[USB_BUFFER_SIZE-1] ) usb_buffer_out = usb_buffer ; 
    263                 } 
    264                 *usb_buffer_in = 0-remote_space_count ; 
    265                 remote_space_count = 0 ; 
     233                if ( remote_space_count > 50 )                                                                  // pulse counting done if no activity for 500mSec 
     234                { 
     235                        if( pulse_count > 0 ) 
     236                        { 
     237                                usb_count = pulse_count ; 
     238                                pulse_count = 0 ; 
     239                        } 
     240                } 
     241 
     242                if (( remote_key == 0) && (remote_count > 0)  )                                                                                         //  1 -> 0 transistion ? 
     243                { 
     244                        if( remote_count > 10 ) pulse_count++ ;                                                                                                 // count pulses longer than 100 msec 
     245 
     246                        usb_power = remote_count;                                                                                                                               // transfer most recent pulse length to variable read by scripts 
     247                         
     248                        if ( ++usb_buffer_in > &usb_buffer[USB_BUFFER_SIZE-1] ) usb_buffer_in = usb_buffer ;    // insert power pulse width into the buffer 
     249                        if ( usb_buffer_in == usb_buffer_out ) 
     250                        { 
     251                                if ( ++usb_buffer_out > &usb_buffer[USB_BUFFER_SIZE-1] ) usb_buffer_out = usb_buffer ; 
     252                        } 
     253                        *usb_buffer_in = remote_count ; 
     254                        remote_count = 0; 
     255                } 
     256 
     257                if (( remote_key == 1) && (remote_space_count > 0)  )                                                                           // 0 -> 1 transistion ? 
     258                { 
     259                        if ( ++usb_buffer_in > &usb_buffer[USB_BUFFER_SIZE-1] ) usb_buffer_in = usb_buffer ;    // insert space pulse width into the buffer as a negative number 
     260                        if ( usb_buffer_in == usb_buffer_out ) 
     261                        { 
     262                                if ( ++usb_buffer_out > &usb_buffer[USB_BUFFER_SIZE-1] ) usb_buffer_out = usb_buffer ; 
     263                        } 
     264                        *usb_buffer_in = 0-remote_space_count ; 
     265                        remote_space_count = 0 ; 
     266                } 
    266267        } 
    267268} 
     
    280281        switch( mode) 
    281282        { 
    282                 case 0 : 
     283                case SINGLE_PULSE : 
    283284                        x = usb_power; 
    284285                        usb_power = 0; 
    285286                        break ; 
    286287 
    287                 case 1 : 
     288                case USB_STATE : 
    288289                        x=remote_key; 
    289290                        break ; 
    290291 
    291                 case 2 : 
     292                case BUFFERED_PULSE : 
    292293                        if ( usb_buffer_out == usb_buffer_in ) 
    293294                        { 
     
    301302                        break ; 
    302303 
    303                 case 3 : 
     304                case PULSE_COUNT : 
    304305                        x = usb_count; 
    305306                        usb_count = 0; 
     
    346347                else camera_mode = MODE_IS_VIDEO(m1&MODE_SHOOTING_MASK) ? CAMERA_MODE_VIDEO : CAMERA_MODE_SHOOTING ; 
    347348 
    348                 (*usb_driver[switch_type])(get_usb_power(1));                           // jump to driver state machine 
     349                (*usb_driver[switch_type])(get_usb_power(USB_STATE));                           // jump to driver state machine 
    349350 
    350351                switch( camera_mode ) 
     
    425426                                                sprintf(buf,"switch=%s logic=%s sync=%s ", gui_USB_switch_types[switch_type], gui_USB_control_modes[control_module], conf.synch_enable?"yes":"no") ; 
    426427                                                draw_string(2,32,buf,MAKE_COLOR(COLOR_YELLOW,COLOR_BLACK)); 
    427                                                 sprintf(buf,"sync count=%d, pulse count=%d width=%d  b=%d  ", sync_counter, usb_count /*virtual_remote_pulse_count*/, virtual_remote_pulse_width,  bracketing.shoot_counter); 
     428                                                sprintf(buf,"sync count=%d, pulse count=%d width=%d  b=%d  ", sync_counter, usb_count, usb_power,   bracketing.shoot_counter); 
    428429                                                draw_string(2,64,buf,MAKE_COLOR(COLOR_BLACK,COLOR_YELLOW)); 
    429430                                                sprintf(buf,"physw=%d err=%d %d %d  ", physw_status[0]&0x03, debug_errors[0],  debug_errors[1],  debug_errors[2] ); 
     
    447448                                                        if ( buff_ptr-- == usb_buffer )  buff_ptr = &usb_buffer[15] ; 
    448449                                                } 
    449                                                 draw_string(2,112,buf,MAKE_COLOR(COLOR_BLACK,COLOR_YELLOW)); 
     450                                                draw_string(2,96,buf,MAKE_COLOR(COLOR_BLACK,COLOR_YELLOW)); 
    450451                                        } 
    451452 
  • trunk/core/usb_remote.h

    r1585 r1596  
    66//#define USB_REMOTE_DEBUGGING 1 
    77 
    8 #define NUM_USB_INPUT_DRV 10 
     8#define NUM_USB_INPUT_DRV 5 
    99#define NUM_USB_MODULES 10 
    1010 
     
    2020        SW_ONE_PRESS , 
    2121        SW_TWO_PRESS , 
    22         SW_RICOH_CA1 , 
    23         SW_PWN 
     22        SW_RICOH_CA1  
    2423}  ; 
    2524 
     
    3130        RMT_CONTINUOUS , 
    3231        RMT_ZOOM , 
    33         RMT_BRACKETING, 
    34         RMT_SCRIPT 
     32        RMT_BRACKETING 
    3533} ; 
    3634 
     
    7068} ; 
    7169 
    72 enum USB_STATE {                                                                // values returned from get_usb_power(1) 
     70enum USB_STATE {                                                                // values returned from get_usb_power(USB_STATE) 
    7371        USB_POWER_OFF, 
    7472        USB_POWER_ON 
     
    9694} ; 
    9795 
     96 
     97enum GET_USB_PWR {                                              // input parameter for get_usb_power()  
     98        SINGLE_PULSE, 
     99        USB_STATE , 
     100        BUFFERED_PULSE , 
     101        PULSE_COUNT 
     102} ; 
     103 
    98104// USB remote processing status 
    99105 
  • trunk/lib/ubasic/ubasic.c

    r1593 r1596  
    298298case TOKENIZER_GET_USB_POWER: 
    299299    accept(TOKENIZER_GET_USB_POWER); 
    300     r = get_usb_power( expr() ); 
     300        int usbpwr = 0 ; 
     301        if (tokenizer_token() != TOKENIZER_CR && 
     302        tokenizer_token() != TOKENIZER_ELSE ) { 
     303        usbpwr = expr(); 
     304    } 
     305    r = get_usb_power(usbpwr); 
    301306    break; 
    302307case TOKENIZER_GET_EXP_COUNT: