##############################################################################
# Copyright 2003 MBARI.                                                      #
# Monterey Bay Aquarium Research Institute Proprietary Information.          #
# All rights reserved.                                                       #
##############################################################################

set dist 5.0
set slew_rate 0.2

set small_inc(dist) 0.2
set big_inc(dist) 2.0

set small_inc(slew_rate) 0.01
set big_inc(slew_rate) 0.1

set inc_var dist

#
# disable commands
#
proc disable_jog { all } { 
    .pilot_interface.jog_frm.ctrlr_frm.arrow_nw_btn configure -state disabled
    .pilot_interface.jog_frm.ctrlr_frm.arrow_n_btn configure -state disabled
    .pilot_interface.jog_frm.ctrlr_frm.arrow_ne_btn configure -state disabled

    .pilot_interface.jog_frm.ctrlr_frm.arrow_w_btn configure -state disabled
    .pilot_interface.jog_frm.ctrlr_frm.arrow_e_btn configure -state disabled

    .pilot_interface.jog_frm.ctrlr_frm.arrow_sw_btn configure -state disabled
    .pilot_interface.jog_frm.ctrlr_frm.arrow_s_btn configure -state disabled
    .pilot_interface.jog_frm.ctrlr_frm.arrow_se_btn configure -state disabled

    if { $all == 1 } {
        .pilot_interface.jog_frm.ctrlr_frm.stop_btn  configure -state disabled
        
        .pilot_interface.jog_frm.scale_frm.apply_btn configure -state disabled
        .pilot_interface.jog_frm.scale_frm.decr_big_btn configure -state disabled
        .pilot_interface.jog_frm.scale_frm.decr_small_btn configure -state disabled
        .pilot_interface.jog_frm.scale_frm.incr_small_btn configure -state disabled
        .pilot_interface.jog_frm.scale_frm.incr_big_btn configure -state disabled

        .pilot_interface.jog_frm.scale_frm.dist_rb configure -state disabled
        .pilot_interface.jog_frm.scale_frm.rate_rb configure -state disabled

        .pilot_interface.jog_frm.scale_frm.dist_scale configure -state disabled
        .pilot_interface.jog_frm.scale_frm.rate_scale configure -state disabled
    }
}

proc enable_jog { } { 
    .pilot_interface.jog_frm.ctrlr_frm.arrow_nw_btn configure -state normal
    .pilot_interface.jog_frm.ctrlr_frm.arrow_n_btn configure -state normal
    .pilot_interface.jog_frm.ctrlr_frm.arrow_ne_btn configure -state normal

    .pilot_interface.jog_frm.ctrlr_frm.arrow_w_btn configure -state normal
    .pilot_interface.jog_frm.ctrlr_frm.arrow_e_btn configure -state normal

    .pilot_interface.jog_frm.ctrlr_frm.arrow_sw_btn configure -state normal
    .pilot_interface.jog_frm.ctrlr_frm.arrow_s_btn configure -state normal
    .pilot_interface.jog_frm.ctrlr_frm.arrow_se_btn configure -state normal

    .pilot_interface.jog_frm.ctrlr_frm.stop_btn  configure -state normal
    
    .pilot_interface.jog_frm.scale_frm.apply_btn configure -state normal
    .pilot_interface.jog_frm.scale_frm.decr_big_btn configure -state normal
    .pilot_interface.jog_frm.scale_frm.decr_small_btn configure -state normal
    .pilot_interface.jog_frm.scale_frm.incr_small_btn configure -state normal
    .pilot_interface.jog_frm.scale_frm.incr_big_btn configure -state normal

    .pilot_interface.jog_frm.scale_frm.dist_rb configure -state normal
    .pilot_interface.jog_frm.scale_frm.rate_rb configure -state normal

    .pilot_interface.jog_frm.scale_frm.dist_scale configure -state normal
    .pilot_interface.jog_frm.scale_frm.rate_scale configure -state normal
    
}

#
# controller commands
#

proc jog_cmd {head dist rate} { send_auto_rov_cmd "MOVE $head, $dist, $rate" }       
proc stop_cmd {} { send_auto_rov_cmd "STOP" }
proc rate_cmd {} {
    global slew_rate

    send_auto_rov_cmd "RATE $slew_rate" 
}

#
# button commands
#

proc jog_nw {} { 
    global dist slew_rate 
    jog_cmd 315.0 $dist $slew_rate
}
proc jog_n {} { 
    global dist slew_rate
    jog_cmd 0.0 $dist $slew_rate
}
proc jog_ne {} { 
    global dist slew_rate 
    jog_cmd 45.0 $dist $slew_rate
}
proc jog_w {} { 
    global dist slew_rate 
    jog_cmd 270.0 $dist $slew_rate
}
proc jog_e {} { 
    global dist slew_rate 
    jog_cmd 90.0 $dist $slew_rate
}
proc jog_sw {} { 
    global dist slew_rate 
    jog_cmd 225.0 $dist $slew_rate
}
proc jog_s {} { 
    global dist slew_rate 
    jog_cmd 180.0 $dist $slew_rate
}
proc jog_se {} { 
    global dist slew_rate 
    jog_cmd 135.0 $dist $slew_rate
}

#
# increment/decrement button 
#

proc dec_big {varname} {
    global big_inc
    upvar #0 $varname var
    set var [expr {$var - $big_inc($varname)}]
}

proc dec_small {varname} {
    global small_inc
    upvar #0 $varname var
    set var [expr {$var - $small_inc($varname)}]
}

proc inc_small {varname} {
    global small_inc
    upvar #0 $varname var
    set var [expr {$var + $small_inc($varname)}]
}

proc inc_big {varname} {
    global big_inc
    upvar #0 $varname var
    set var [expr {$var + $big_inc($varname)}]
}

#
# create images for the buttons
#

image create photo arrow_nw -file [file join images arrow_nw.gif] -format gif
image create photo arrow_n -file [file join images arrow_n.gif] -format gif
image create photo arrow_ne -file [file join images arrow_ne.gif] -format gif

image create photo arrow_w -file [file join images arrow_w.gif] -format gif
image create photo stop_sign -file [file join images stop.gif] -format gif
image create photo arrow_e -file [file join images arrow_e.gif] -format gif

image create photo arrow_sw -file [file join images arrow_sw.gif] -format gif
image create photo arrow_s -file [file join images arrow_s.gif] -format gif
image create photo arrow_se -file [file join images arrow_se.gif] -format gif

image create photo decr_small -file [file join images decr_small.gif] -format gif
image create photo decr_big -file [file join images decr_big.gif] -format gif
image create photo incr_small -file [file join images incr_small.gif] -format gif
image create photo incr_big -file [file join images incr_big.gif] -format gif


