LDVmouse

Check-in [c9b348bc6d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Minor edits to comments.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c9b348bc6d628cd1a8721683b664898066472f3f
User & Date: ezaron 2016-01-28 07:41:29
Context
2016-06-24
17:23
incorportated new changes, prior to submission to APS check-in: 50535ad2f6 user: ezaron tags: trunk
2016-01-28
07:41
Minor edits to comments. check-in: c9b348bc6d user: ezaron tags: trunk
2015-12-18
00:41
Initial import check-in: 21c26838c4 user: ezaron tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Software/LDVconf.tcl.

8
9
10
11
12
13
14
15
16

17


















18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Before you run this script, you should run "sudo ./evhz" to find out the
# device's polling rate.
# If the polling rate isn't high enough, 1 kHz seems to be max, then you can
# try:
#   sudo modprobe -r usbhid && sudo modprobe usbhid mousepoll=1
# AND THEN UNPLUG AND RE-PLUG IN THE MOUSE.
# See https://wiki.archlinux.org/index.php/Mouse_Polling_Rate for other settings.

# Set some global values:




















# The polling rate and number of samples used to average:
set ::LDVrate   1000 ; # Polling rate. Only used in the output file header.
set ::LDVnavg   5000 ; # Number of samples for computing time-average in LDVtransect.tcl.
set ::LDVnsamp  5000 ; # Number of samples in time series by LDVts.tcl. 5 sec
#set ::LDVnsamp  300000 ; # Number of samples in time series by LDVts.tcl. 5 minutes


# Once you know the dev number and node, you may hardwire these values:
set ::LDVname "Catz"
set ::LDVdev  14
set ::LDVnode /dev/input/event16

# Note that "sudo ./evhz" will output the list of nodes and their associated
# devices.

###########################################################
# You should not need to modify anything below this line. #
###########################################################








|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|





<
<
<
<
<
<







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42






43
44
45
46
47
48
49
# Before you run this script, you should run "sudo ./evhz" to find out the
# device's polling rate.
# If the polling rate isn't high enough, 1 kHz seems to be max, then you can
# try:
#   sudo modprobe -r usbhid && sudo modprobe usbhid mousepoll=1
# AND THEN UNPLUG AND RE-PLUG IN THE MOUSE.
# See https://wiki.archlinux.org/index.php/Mouse_Polling_Rate for other settings.
#

# INSTRUCTIONS FOR USE:
#
#  If necessary, replace "Catz" with a unique fragment of your mouse's name, below.
#  Then, run this script, e.g.,
#     sudo tclsh ./LDVconf.tcl
#  If all goes well, this script will identify the device number and the device node
#  name associated with your mouse.
#  Once you know these values, edit this file so that it sets ::LDVdev and ::LDVnode
#  to the correct values.
#

# Once you know the dev number and node, you may hardwire these values:
set ::LDVname "Catz"              ; # This is part of the vendor name of the mouse, just enough to be unique.
set ::LDVdev  0
set ::LDVnode /dev/null

#set ::LDVdev  14                  ; # This is the numeric device id as returned by "xinput --list".
#set ::LDVnode /dev/input/event16  ; # This is the device node, i.e., the pseudo-file where mouse events are reported.

# SET THE FOLLOWING TO SUITABLE VALUES, WHICH WILL DEPEND ON THE MOUSE POLLING RATE:
#   The polling rate and number of samples used to compute average instrument values:
set ::LDVrate   1000 ; # Polling rate. Only used in the output file header.
set ::LDVnavg   5000 ; # Number of samples for computing time-average in LDVtransect.tcl.
set ::LDVnsamp  5000 ; # Number of samples in time series by LDVts.tcl. 5 sec
#set ::LDVnsamp  300000 ; # Number of samples in time series by LDVts.tcl. 5 minutes







# Note that "sudo ./evhz" will output the list of nodes and their associated
# devices.

###########################################################
# You should not need to modify anything below this line. #
###########################################################

46
47
48
49
50
51
52
53
54
55


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    regexp {id=(\d+?)\s} $retstr -> dev
    puts "Found \"$mousename\" mouse on dev=$dev"
    return $dev
}

# Determine the file name for accessing the mouse:
proc getnode dev {
    # On puppy linux, the mouse seems to show up at
    #	return /dev/sudo modprobe -r usbhid && sudo modprobe usbhid mousepoll=1
    # THEN UN-PLUG AND RE-PLUG MOUSE.


    # 	Mad CAT:
    #	return /dev/input/event8
    # Titanium:
    #	return /dev/input/event3
    #    return /dev/input/event2
    # red button is here:
    #	return /dev/input/event2
    #	return /dev/input/event12

    # Not all linux's seem to have the list-props option for xinput.
    # Execute xinput and grab the line containing "Device Node"
    if { [ catch {exec xinput list-props $dev | grep "Device Node"} retstr ]
     } {
	puts "Could not find device node for dev= $dev."
	puts "Returning devnode=0."
	#	puts "retstr = $retstr"
	return 0
    }
    # Parse the result to pull out the file name which is within quotes
    regexp {\"(.+?)\"} $retstr -> match
    puts "Found dev=$dev on node=$match"
    return $match
}

# Find the active device node just by grabbing output from everything
# /dev/input/event* until something shows up.
# Use this as a last resort in case xinput list-props fails.
set ::state 0
set ::ms 0
proc getnode_alt dev {
    puts "Searching for the device node corresponding to dev=$dev."
    puts "   Please move the mouse or sensor ...."







|
|
|
>
>
|



|









|

|







|







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    regexp {id=(\d+?)\s} $retstr -> dev
    puts "Found \"$mousename\" mouse on dev=$dev"
    return $dev
}

# Determine the file name for accessing the mouse:
proc getnode dev {
    # For testing a specific device, it can be helpful to just return
    # a literal device name. Uncomment the appropriate return statement
    # if you are just debugging this code. The following are examples of
    # mice and corresponding node names I have encountered:
    #
    # Mad CAT:
    #	return /dev/input/event8
    # Titanium:
    #	return /dev/input/event3
    #   return /dev/input/event2
    # red button is here:
    #	return /dev/input/event2
    #	return /dev/input/event12

    # Not all linux's seem to have the list-props option for xinput.
    # Execute xinput and grab the line containing "Device Node"
    if { [ catch {exec xinput list-props $dev | grep "Device Node"} retstr ]
     } {
	puts "Could not find device node for dev= $dev."
	puts "Returning LDVnode=/dev/null."
	#	puts "retstr = $retstr"
	return "/dev/null"
    }
    # Parse the result to pull out the file name which is within quotes
    regexp {\"(.+?)\"} $retstr -> match
    puts "Found dev=$dev on node=$match"
    return $match
}

# Find the active device node just by grabbing output from everything in
# /dev/input/event* until something shows up.
# Use this as a last resort in case xinput list-props fails.
set ::state 0
set ::ms 0
proc getnode_alt dev {
    puts "Searching for the device node corresponding to dev=$dev."
    puts "   Please move the mouse or sensor ...."
104
105
106
107
108
109
110








111
112
113
114
115
116
117
118
119




120

    }
}


if {$::LDVnode == 0} {
    # Find the device number from the device name:
    set ::LDVdev  [finddev $::LDVname]








    
    # Try to find the node, e.g., /dev/input/event12:
    set ::LDVnode [getnode $::LDVdev]
    
    if {$::LDVnode == 0} {
	# If the above command fails because the linux does not have
	# full xinput command, then we search all active nodes.
	set ::LDVnode [getnode_alt $::LDVdev]
    }




}








>
>
>
>
>
>
>
>









>
>
>
>

>
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    }
}


if {$::LDVnode == 0} {
    # Find the device number from the device name:
    set ::LDVdev  [finddev $::LDVname]

    if {$::LDVnode == 0} {
	puts "ERROR:"
	puts "  LDVconf.tcl failed to identify the mouse device number."
	puts "  Does the xinput command work correctly?"
	puts "  Have you set the mouse name, ::LDVname, in LDVconf.tcl?"
	exit
    }
    
    # Try to find the node, e.g., /dev/input/event12:
    set ::LDVnode [getnode $::LDVdev]
    
    if {$::LDVnode == 0} {
	# If the above command fails because the linux does not have
	# full xinput command, then we search all active nodes.
	set ::LDVnode [getnode_alt $::LDVdev]
    }
    puts "Successful exit of the LDVconf.tcl script."
    puts "Edit the LDVconf.tcl script to set the following values:"
    puts "  set ::LDVdev   $::LDVdev"
    puts "  set ::LDVnode  $::LDVnode"
}

Changes to Software/LDVlib.tcl.

1
2
3
4
5
6
7
8
9

# You should source MouseConf.tcl before calling any of the procs
# defined here. They all need to know either the global ::LDVdev or
# ::LDVnode variables.

# At this point all the procs take a dummy input, LDV,
# which is unused.

# Disable the mouse:

|







1
2
3
4
5
6
7
8
9

# You should source LDVconf.tcl before calling any of the procs
# defined here. They all need to know either the global ::LDVdev or
# ::LDVnode variables.

# At this point all the procs take a dummy input, LDV,
# which is unused.

# Disable the mouse:
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

    # Close the channel:
    close $ms

    return
}


# Initialize vectors
set nsamp 250 ;  # nominally, 1 second of data
#set nsamp 1000 ;  # nominally, 1 second of data
set nsamp 6000 ;  # nominally, 3 second of data at 500Hz

set nsamp $::LDVnavg
vector create utvec($nsamp) vtvec($nsamp) uvec($nsamp) vvec($nsamp)
vector create vzero($nsamp)

# Read the device and compute instantaneous and average velocity in device units.
# Note that the vectors utvec, vtvec, uvec, and vvec are global variables.
proc rawvel {devnode nsamp} {
#    set devnode [getnode $dev]







|
<
<
<
<
<
|







61
62
63
64
65
66
67
68





69
70
71
72
73
74
75
76

    # Close the channel:
    close $ms

    return
}

# Set local nsamp equal to the global ::LDVnsamp





set nsamp $::LDVsamp
vector create utvec($nsamp) vtvec($nsamp) uvec($nsamp) vvec($nsamp)
vector create vzero($nsamp)

# Read the device and compute instantaneous and average velocity in device units.
# Note that the vectors utvec, vtvec, uvec, and vvec are global variables.
proc rawvel {devnode nsamp} {
#    set devnode [getnode $dev]