Check-in [1ae81b7c1b]

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

Overview
Comment:Reorganize prohect directories.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:1ae81b7c1b24268647aa24020bd6118d2edfdaf38f5ab99ebe493a29c1214bcf
User & Date: gwlester 2018-02-07 21:53:17
Context
2018-02-08
05:50
Correct several bugs. check-in: a2782097ce user: gwlester tags: trunk
2018-02-07
21:53
Reorganize prohect directories. check-in: 1ae81b7c1b user: gwlester tags: trunk
02:15
Added package require Tcl 6.6 check-in: c732f97210 user: gwlester tags: trunk
Changes

Deleted Accelerometer_Calibrate.tcl.

1
2
3
4
5
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

package require piio
<
<
<
<
<










Deleted Accelerometer_Example.tcl.

1
2
3
4
5
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

package require piio
<
<
<
<
<










Added Makefile.



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
default: build

build: clean
	tclsh make.tcl build

install:
	tclsh make.tcl install

test:
	@( cd tests ; tclsh all.tcl )
	
checkall:
	@tclchecker $(OPTIONS) $(shell find . -name '*.tcl')

clean:
	-rm -f -- *.tm
	-rm -f -- ci-comment-*

Name change from Gyro_Example.tcl to examples/Gyro_Example.tcl.

Name change from Multisensor_Example.tcl to examples/Multisensor_Example.tcl.

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
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





























88


89
90



91
92
93
94
95
96
97
98
99
100
101

102
103
104



105
106
107
108
109
110
111
112


113
114

115
116
117
118
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
149
150
151
152


153
154
155
156
157
158
159

160
161
162
163
164
165
166
167






168
169

170
171
172


173
174
175
176
177
178
179
180


181
182


183



184
185
186


187












188
189


190
191
192







193
194
195
196
197
198
199






200
201

202
203
204
205




206
207
208
209

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332

333
334
335
336
337
338
339
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
...
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
...
763
764
765
766
767
768
769
770



771





















## It utilizes the low leve bno055 package.
##

lappend atuo_path [file dirname [info script]] [pwd]
::tcl::tm::path add [file dirname [info script]] [pwd]

#package require dimu


##
## These bytes set the full scale range of the gyroscope.
## it is important to define full_scale_range.  Values are:
##      0x00 - 250 dps.  Full scale range.
##      0x10 - 500 dps.  Full scale range.
##      0x30 - 2000 dps.  Full scale range.
##
array set GyroValues {
    250dps  0x00
    500dps  0x10
    2000dps 0x30
    250dps,divisor 128.0
    500dps,divisor 64.0
    2000dps,divisor 16.0
    divisor 16.0
    full_scale_range 0x30
    gyro,x,axis 0x14
    gyro,y,axis 0x16
    gyro,z,axis 0x18
    rate 50
    digits 5
    decimals 1
    minChange 0.1

}

array set AccelValues {
    250dps  0x00
    500dps  0x10
    2000dps 0x30
    250dps,divisor 128.0
    500dps,divisor 64.0
    2000dps,divisor 16.0
    divisor 16.0
    full_scale_range 0x30
    gyro,x,axis 0x14
    gyro,y,axis 0x16
    gyro,z,axis 0x18
    rate 50
    digits 5
    decimals 1
    minChange 0.1

}

array set MagValues {
    250dps  0x00
    500dps  0x10
    2000dps 0x30
    250dps,divisor 128.0
    500dps,divisor 64.0
    2000dps,divisor 16.0
    divisor 16.0
    full_scale_range 0x30
    gyro,x,axis 0x14
    gyro,y,axis 0x16
    gyro,z,axis 0x18
    rate 50
    digits 5
    decimals 1
    minChange 0.1

}


set i2cbus 1
set dIMUaddress 0x28





























set range 2000dps







foreach type {gyroscope accelerometer magnetometer gravity linearAcceleration quaternion prh} {
    set CurrentValue($type,x) {0}
    set CurrentValue($type,y) {0}
    set CurrentValue($type,z) {0}
}

proc StartGyro {handle range} {
    global GyroValues

    ##
    ## Place the dIMU in configuration mode

    ##
    bno055 writeRegister $handle operMode [bno055 getValue OPER_MODE_CONFIGMODE]
    piio usleep 20




    ##
    ## Disable power down.
    ##
    bno055 writeRegister $handle powerMode [bno055 getValue PWR_MODE_NORMAL]
    piio usleep 10

    ##


    ## No High Pass Filter, Enable Any Motion
    ##

    bno055 writeRegisterBlock $handle \
        gyr,am,x,enab   1 \
        gyr,am,y,enab   1 \
        gyr,am,z,enab   1 \
        gyr,am,filter   0 \



        gyr,hr,filter   0
    piio usleep 10



    ##
    ## No interrupts.
    ##

    bno055 writeRegisterBlock $handle \
        gyr,am,intEnab  0 \
        gyr,hiR,intEnab \
    piio usleep 10

    ##
    ## Specified scale range, power mode and bandwidth.
    ##



    bno055 writeRegisterBlock $handle \
        gyr,range       [bno055 getValue2 GRY_RANGE [string toupper $range]] \
        gyr,bandwidth   [bno055 getValue GRY_BANDWIDTH_32HZ] \
        gyr,pwrMode     [bno055 getValue GRY_POWER_MODE_NORMAL]
    piio usleep 10

    ##
    ## Switch to IMU mode so autocalibration happens.
    ##
    bno055 writeRegister $handle operMode [bno055 getValue OPER_MODE_IMU]
    piio usleep 20




    ##
    ## Set divisor so that the output of our gyro axis readings can be turned
    ## into scaled values.
    ##
    set GyroValues(divisor) $GyroValues($range,divisor)

    return;


}

##
## Gyro: gets a full axis reading, scaled to the full scale reading.  Returns
## in degrees per second.
##
proc GyroAxisReading {axis oldValue} {

    global GyroValues

    set handle $GyroValues(handle)
    set intValue [bno055 readRegister $handle gyr,data,$axis]
    set digits $GyroValues(digits)
    set decimals $GyroValues(decimals)
    incr digits $decimals
    if {$decimals} {






        ##
        ## Account for the decimal point

        ##
        incr digits
    }


    
    ##
    ## Account for the sign
    ##
    incr digits
    set newValue [format "%${digits}.${decimals}f" [expr {$intValue / $GyroValues(divisor)}]]
    if {$newValue != $oldValue && abs($newValue - $oldValue) < $GyroValues(minChange)} {
        set newValue $oldValue


    }
    return $newValue


}




proc ReadGyro {} {
    global GyroValues CurrentValue















    if {[info exists GyroValues(afterId)]} {
        after cancel $GyroValues(afterId)


    }
    set GyroValues(afterId) [after [expr {$GyroValues(rate) * 10}] ReadGyro]








    ##
    ## Read the GYROSCOPE
    ##
    set x [GyroAxisReading x $CurrentValue(x)]
    set y [GyroAxisReading y $CurrentValue(y)]
    set z [GyroAxisReading z $CurrentValue(z)]
    if {$x != $CurrentValue(x) ||






        $y != $CurrentValue(y) ||
        $z != $CurrentValue(z)

    } {
        LogValues $x $y $z
    }





    set CurrentValue(x) $x
    set CurrentValue(y) $y
    set CurrentValue(z) $z


    return
}

proc LogValues {type} {
    variable WidgetData
    variable CurrentValue

    #if {[info exists GyroValues(logId)]} {
    #    after cancel $GyroValues(logId)
    #}
    #set GyroValues(logId) [after [expr {$GyroValues(freq) * 100}] LogValues]

    set timeStamp [clock format [clock seconds]]
    set x $CurrentValue($type,x)
    set y $CurrentValue($type,y)
    set z $CurrentValue($type,z)
    $WidgetData($type,history) insert {} end -values [list $timeStamp $x $y $z]
}

proc StartReading {} {
    global i2cbus dIMUaddress range GyroValues

    if {$dIMUaddress eq {}} {
        return
    }

    .main.controls.buttons.start configure -state disabled
    .main.controls.buttons.stop configure -state normal
    set GyroValues(handle) [::twowire twowire $i2cbus $dIMUaddress]
    StartGyro $GyroValues(handle) $range
    ReadGyro

}

proc StopReading {} {
    global GyroValues

    if {[info exists GyroValues(afterId)]} {
        after cancel $GyroValues(afterId)
    }
    if {[info exists GyroValues(logId)]} {
        after cancel $GyroValues(logId)
    }
    
    .main.controls.buttons.start configure -state normal 
    .main.controls.buttons.stop configure -state disabled
}

proc CreateGui {} {


    wm title . "dIMU Gyroscope Example"

    ttk::notebook .main
    grid configure .main -sticky nsew
    grid columnconfigure . .main -weight 1
    grid rowconfigure . .main -weight 1
    
    ttk::frame .main.configuration
    .main add .main.configuration -text {Configuration}
    ttk::frame .main.gyroscope
    .main add .main.gyroscope -text {Gyroscope}
    ttk::frame .main.accelerometer
    .main add .main.accelerometer -text {Accelerometer}
    ttk::frame .main.magnetometer
    .main add .main.magnetometer -text {Magnetometer}
    ttk::frame .main.gravity
    .main add .main.gravity -text {Gravity}
    ttk::frame .main.linearAcceleration
    .main add .main.linearAcceleration -text {Linear Acceleration}
    ttk::frame .main.quaternion
    .main add .main.quaternion -text {Quaternion}
    ttk::frame .main.prh
    .main add .main.prh -text {Pitch, Roll and Heading}

    CreateConfigurationFrame .main.configuration
    CreateGyroFrame .main.gyroscope
    CreateAccelerometerFrame .main.accelerometer
    CreateMagnetometerFrame .main.magnetometer
    CreateGravityFrame .main.gravity
................................................................................
proc CreateGeneralConfigFrame {general} {
    ##
    ## General Configuration group
    ##
    ttk::label $general.busLbl \
        -text {I2C Bus:}
    ttk::combobox $general.busCMB \
        -textvariable ::i2cbus \
        -values [list 1] \
        -state readonly
    ttk::label $general.addrLbl \
        -text {iDMU Address:}
    ttk::entry $general.addrEnt \
        -width 5 \
        -textvariable ::dIMUaddress \
        -state readonly
    ttk::label $general.rateLbl1 \
        -text {Refresh Rate:}
    ttk::spinbox $general.rateEnt \
        -from 50.0 \
        -to 500.0 \
        -increment 10.0 \
        -format {%3.0f} \
        -wrap no \
        -command [format {set ::GyroValues(rate) [expr {entier([%1$s get])}]}  $general.rateEnt]
    ttk::label $general.rateLbl2 \
        -text { in microseconds}
    ttk::label $general.operLbl1 \
        -text {Operational Mode}
    # change values to be human readable
    ttk::combobox $general.operCMB \
        -textvariable ::Configuration(operMode) \
        -values {configmode acconly magonly gyroonly accmag accgyro maggyro amg imu compass m4g ndof_fmc_off ndof} \

        -state readonly
    # put a trace on opermode to 
    ttk::label $general.pwrLbl1 \
        -text {Power Mode}
    ttk::combobox $general.pwrCMB \
        -textvariable ::Configuration(pwrMode) \
        -values {normal low suspend} \

        -state readonly
    # Add axis remap and axis sign
    # Add self test results
    # Add clock select if sys_clk_status is true
    # Reset interupt
    # Reset system
    # Add self test trigger
................................................................................
    ttk::combobox $gyro.rangeCMB \
        -textvariable ::range \
        -values [list 250dps 500dps 2000dps] \
        -state readonly
    ttk::label $gyro.numDigitsLbl \
        -text {Digits before decimal}
    ttk::combobox $gyro.numDigitsCMB \
        -textvariable ::GyroValues(digits) \
        -values [list 3 4] \
        -state readonly
    ttk::label $gyro.numDecimalsLbl \
        -text {Digits after decimal}
    ttk::combobox $gyro.numDecimalsCMB \
        -textvariable ::GyroValues(decimals) \
        -values [list 1 2 3 4] \
        -state readonly
    ttk::label $gyro.minChangeLbl1 \
        -text {Ignore less than}
    ttk::spinbox $gyro.minChangeEnt \
        -from 0.1 \
        -to 200.0 \
        -increment 0.1 \
        -format {%5.1f} \
        -wrap no \
        -textvariable ::GyroValues(minChange)
    ttk::label $gyro.minChangeLbl2 \
        -text {dps change}
    # Add Self Test status
    # Add Calibration status
    # Add Unit Select
    # Add offsets
    # Add Gyro High Rate Interrupt Status
................................................................................
    # Add Gyro Sleep Duration
    grid configure $gyro.rangeLbl $gyro.rangeCMB x x -padx 2 -sticky ew
    grid configure $gyro.numDigitsLbl $gyro.numDigitsCMB x x -padx 2 -sticky ew
    grid configure $gyro.numDecimalsLbl $gyro.numDecimalsCMB x x -padx 2 -sticky ew
    grid configure $gyro.minChangeLbl1 $gyro.minChangeEnt $gyro.minChangeLbl2 x -padx 2 -sticky ew
    grid columnconfigure $gyro 3 -weight 1

    $gyro.minChangeEnt set $::GyroValues(minChange)

}

proc CreateMagConfigFrame {mag} {
    ##
    ## Magnetometer group
    ##
................................................................................
        -textvariable ::CurrentValue($type,$z) \
        -state readonly
    grid configure $w.xLabel $w.xValue $w.yLabel $w.yValue $w.zLabel $w.zValue x -sticky ew -padx 2 -pady 1
    grid columnconfigure $w [list $w.xLabel $w.yLabel $w.zLabel] -uniform labels -weight 0
    grid columnconfigure $w [list $w.xValue $w.yValue $w.zValue] -uniform values -weight 0
}

CreateGui
































>








|
<
<
|
<
<
<
<
<
<
<
<
<



>



<
<
|
<
<
<
<
<
<
<
<
<



>



<
<
|
<
<
<
<
<
<
<
<
<



>


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






<
<
<
|
<
>
|
<
<
>
>
>

<
<
<
|
<

<
>
>
|
<
>
|
|
<
<
<
>
>
>
|
|
>
>

<
<
<
>
|
|
|
|
|
<
<
<
>
>
>
|
|
<
<
<

<
<
<
<
<
>
>
>
|
<
<
<
<
<

<
>
>


<
<
<
<
<
>
|

<
<
<
<
<
<
>
>
>
>
>
>
|
<
>
|
<
|
>
>
|
<
<
<
<
<
<
<
>
>
|
<
>
>
|
>
>
>
|
|
<
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
|
<
|
>
>
>
>
>
>
>

|

<
<
<
<
>
>
>
>
>
>
|
|
>


|
<
>
>
>
>
|
|
|
|
>







|
|

|









|







<
|





|

|
|

|
|







>
>


|




|

|

|

|

|

|

|

|







 







|






|









|






|
|
>

<



|
|
>







 







|





|










|







 







|







 







|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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


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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102



103

104
105


106
107
108
109



110

111

112
113
114

115
116
117



118
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
149






150
151
152
153
154
155
156

157
158

159
160
161
162







163
164
165

166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204




205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
...
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352
353
354
355
356
357
...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
...
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
...
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
## It utilizes the low leve bno055 package.
##

lappend atuo_path [file dirname [info script]] [pwd]
::tcl::tm::path add [file dirname [info script]] [pwd]

#package require dimu
proc dimu {args} {return}

##
## These bytes set the full scale range of the gyroscope.
## it is important to define full_scale_range.  Values are:
##      0x00 - 250 dps.  Full scale range.
##      0x10 - 500 dps.  Full scale range.
##      0x30 - 2000 dps.  Full scale range.
##
array set CurrentValue {


    range 2000dps









    digits 5
    decimals 1
    minChange 0.1
    formatStr {%7.1}
}

array set AccelValues {


    range 2000dps









    digits 5
    decimals 1
    minChange 0.1
    formatStr {%7.1}
}

array set MagValues {


    range 2000dps









    digits 5
    decimals 1
    minChange 0.1
    formatStr {%7.1}
}

array set Configuration {
    i2cbus 1
    dIMUaddress 0x28
}

array set UI {
    operation,map,label {
        configmode      "Configuration Mode"
        acconly         "Accelerometer Only"
        magonly         "Magnetometer Only"
        gyroonly        "Gyroscope Only"
        accmag          "Accelerometer and Magnetometer Only"
        accgyro         "Accelerometer and Gyroscope Only"
        maggyro         "Gyroscope and Magnetometer Only"
        amg             "Accelerometer, Gyroscope and Magnetometer Only"
        imu             "Inertial Measurement Unit"
        compass         "Compass"
        m4g             "Magnet for Gyroscope"
        ndof_fmc_off    "9 Degrees of Freedom -- Fast Magnetometer Calibration Off"
        ndof            "9 Degrees of Freedom -- Fast Magnetometer Calibration On"
    }
    power,map,labelframe {
        normal          "Normal"
        low             "Low"
        suspend         "Suspend"
    }
}

foreach key [array names UI "*,map,label"] {
    lassign [split $key ","] option
    set maxLabelSize -1
    foreach {symbol label} $UI($key) {
        dict set UI($option,map,symbol) $label $symbol
        if {$maxLabelSize < [string length $label]} {
            set maxLabelSize [string length $label]
        }
    }
    set UI($option,maxLabelSize) $maxLabelSize
}

foreach type {gyroscope accelerometer magnetometer gravity linearAcceleration quaternion prh} {
    set CurrentValue($type,x) {0}
    set CurrentValue($type,y) {0}
    set CurrentValue($type,z) {0}
}




##

## Begin procedure definition section
##


proc ChangeOperationMode {varName index op} {
    global UI
    global Configuration




    set mode [dict get $UI(operation,map,symbol) $Configuration(operation]



    if {$mode ne "configmode"} {
        DisableConfigurationWidgets
        EnableTabs $mode

    } else {
        EnableConfigurationWidgets
        DisableTabs



    }
}

proc ConfigurationChange {varName index op} {
    global UI
    global CurrentValue
    upvar #0 $varName configuration




    set value $configuration($index)
    if  {$index eq refreshRate} {
        return
    } elseif {[info exists UI($index,map,symbol)]} {
        set value [dict get $UI($index,map,symbol) $value]
    }



    $CurrentValue(handle) configure -$index $value
}

proc DisableTabs {} {
    global UI









    set notebook $UI(mainNotebook)
    foreach {tab widget} [array get UI {main,*}] {
        $nodebook tab $widget -state disabled
    }







    $nodebook tab $UI(main,configuration) -state normal
    $nodebook select $UI(main,configuration)
}






proc EnableTags {mode} {
    global UI







    DisableTabs

    set notebook $UI(mainNotebook)
    switch -exact -- $mode {
        configmode -
        default {
            ##

            ## Do nothing
            ##

        }
        acconly {
            $notebook tab $UI(main,accelerometer) -state normal
        }







        magonly {
            $notebook tab $UI(main,magnetometer) -state normal
        }

        gyroonly {
            $notebook tab $UI(main,gyroscope) -state normal
        }
        accmag {
            $notebook tab $UI(main,accelerometer) -state normal
            $notebook tab $UI(main,magnetometer) -state normal
        }
        accgyro {

            $notebook tab $UI(main,accelerometer) -state normal
            $notebook tab $UI(main,gyroscope) -state normal
        }
        maggyro {
            $notebook tab $UI(main,magnetometer) -state normal
            $notebook tab $UI(main,gyroscope) -state normal
        }
        amg {
            $notebook tab $UI(main,accelerometer) -state normal
            $notebook tab $UI(main,magnetometer) -state normal
            $notebook tab $UI(main,gyroscope) -state normal
        }
        imu -
        compass -
        m4g -
        ndof_fmc_off -
        ndof {
            foreach {tab widget} [array get UI {main,*}] {
                $nodebook tab $widget -state normal
            }

        }
    }
}

proc ReadGyro {} {
    global CurrentValue
    global GryoValues

    ##
    ## Read the gyroscope
    ##




    set currentReadings [$CurrentValue(handle) readGyro]
    set formatStr $GryoValues(formatStr)
    set x [format $formatStr [dict get $currentReadings x]]
    set y [format $formatStr [dict get $currentReadings z]]
    set z [format $formatStr [dict get $currentReadings z]]
    set minChange $GryoValues(minChange
    if {abs($x - $CurrentValue(gyroscope,x)) > $minChange ||
        abs($y - $CurrentValue(gyroscope,y)) > $minChange ||
        abs($z - $CurrentValue(gyroscope,z)) > $minChange
    } {
        LogValues $x $y $z
        

        ##
        ## Only change if delta exceed, otherwise a slow drift will never get
        ## logged.
        ##
        set CurrentValue(gyroscope,x) $x
        set CurrentValue(gyroscope,y) $y
        set CurrentValue(gyroscope,z) $z
    }

    return
}

proc LogValues {type} {
    variable WidgetData
    variable CurrentValue

    #if {[info exists CurrentValue(logId)]} {
    #    after cancel $CurrentValue(logId)
    #}
    #set CurrentValue(logId) [after [expr {$CurrentValue(freq) * 100}] LogValues]

    set timeStamp [clock format [clock seconds]]
    set x $CurrentValue($type,x)
    set y $CurrentValue($type,y)
    set z $CurrentValue($type,z)
    $WidgetData($type,history) insert {} end -values [list $timeStamp $x $y $z]
}

proc StartReading {} {
    global i2cbus dIMUaddress range CurrentValue

    if {$dIMUaddress eq {}} {
        return
    }

    .main.controls.buttons.start configure -state disabled
    .main.controls.buttons.stop configure -state normal

    StartGyro $CurrentValue(handle) $range
    ReadGyro

}

proc StopReading {} {
    global CurrentValue

    if {[info exists CurrentValue(afterId)]} {
        after cancel $CurrentValue(afterId)
    }
    if {[info exists CurrentValue(logId)]} {
        after cancel $CurrentValue(logId)
    }
    
    .main.controls.buttons.start configure -state normal 
    .main.controls.buttons.stop configure -state disabled
}

proc CreateGui {} {
    global UI
    
    wm title . "dIMU Gyroscope Example"

    set UI(mainNotebook) [ttk::notebook .main]
    grid configure .main -sticky nsew
    grid columnconfigure . .main -weight 1
    grid rowconfigure . .main -weight 1
    
    set UI(main,configuration) [ttk::frame .main.configuration]
    .main add .main.configuration -text {Configuration}
    set UI(main,gyroscope) [ttk::frame .main.gyroscope]
    .main add .main.gyroscope -text {Gyroscope}
    set UI(main,accelerometer) [ttk::frame .main.accelerometer]
    .main add .main.accelerometer -text {Accelerometer}
    set UI(main,magnetometer) [ttk::frame .main.magnetometer]
    .main add .main.magnetometer -text {Magnetometer}
    set UI(main,gravity) [ttk::frame .main.gravity]
    .main add .main.gravity -text {Gravity}
    set UI(main,linearAcceleration) [ttk::frame .main.linearAcceleration]
    .main add .main.linearAcceleration -text {Linear Acceleration}
    set UI(main,quaternion) [ttk::frame .main.quaternion]
    .main add .main.quaternion -text {Quaternion}
    set UI(main,prh) [ttk::frame .main.prh]
    .main add .main.prh -text {Pitch, Roll and Heading}

    CreateConfigurationFrame .main.configuration
    CreateGyroFrame .main.gyroscope
    CreateAccelerometerFrame .main.accelerometer
    CreateMagnetometerFrame .main.magnetometer
    CreateGravityFrame .main.gravity
................................................................................
proc CreateGeneralConfigFrame {general} {
    ##
    ## General Configuration group
    ##
    ttk::label $general.busLbl \
        -text {I2C Bus:}
    ttk::combobox $general.busCMB \
        -textvariable ::Configuration(i2cbus) \
        -values [list 1] \
        -state readonly
    ttk::label $general.addrLbl \
        -text {iDMU Address:}
    ttk::entry $general.addrEnt \
        -width 5 \
        -textvariable ::Configuration(dIMUaddress) \
        -state readonly
    ttk::label $general.rateLbl1 \
        -text {Refresh Rate:}
    ttk::spinbox $general.rateEnt \
        -from 50.0 \
        -to 500.0 \
        -increment 10.0 \
        -format {%3.0f} \
        -wrap no \
        -command [format {set ::Configuration(refreshRate) [expr {entier([%1$s get])}]}  $general.rateEnt]
    ttk::label $general.rateLbl2 \
        -text { in microseconds}
    ttk::label $general.operLbl1 \
        -text {Operational Mode}
    # change values to be human readable
    ttk::combobox $general.operCMB \
        -textvariable ::Configuration(operation) \
        -values [dict keys $::UI(operation,map,symbol)] \
        -width $::UI(operation,maxLabelSize) \
        -state readonly

    ttk::label $general.pwrLbl1 \
        -text {Power Mode}
    ttk::combobox $general.pwrCMB \
        -textvariable ::Configuration(power) \
        -values [dict keys $::UI(power,map,symbol)] \
        -width $::UI(power,maxLabelSize) \
        -state readonly
    # Add axis remap and axis sign
    # Add self test results
    # Add clock select if sys_clk_status is true
    # Reset interupt
    # Reset system
    # Add self test trigger
................................................................................
    ttk::combobox $gyro.rangeCMB \
        -textvariable ::range \
        -values [list 250dps 500dps 2000dps] \
        -state readonly
    ttk::label $gyro.numDigitsLbl \
        -text {Digits before decimal}
    ttk::combobox $gyro.numDigitsCMB \
        -textvariable ::GryoValues(digits) \
        -values [list 3 4] \
        -state readonly
    ttk::label $gyro.numDecimalsLbl \
        -text {Digits after decimal}
    ttk::combobox $gyro.numDecimalsCMB \
        -textvariable ::GryoValues(decimals) \
        -values [list 1 2 3 4] \
        -state readonly
    ttk::label $gyro.minChangeLbl1 \
        -text {Ignore less than}
    ttk::spinbox $gyro.minChangeEnt \
        -from 0.1 \
        -to 200.0 \
        -increment 0.1 \
        -format {%5.1f} \
        -wrap no \
        -textvariable ::GryoValues(minChange)
    ttk::label $gyro.minChangeLbl2 \
        -text {dps change}
    # Add Self Test status
    # Add Calibration status
    # Add Unit Select
    # Add offsets
    # Add Gyro High Rate Interrupt Status
................................................................................
    # Add Gyro Sleep Duration
    grid configure $gyro.rangeLbl $gyro.rangeCMB x x -padx 2 -sticky ew
    grid configure $gyro.numDigitsLbl $gyro.numDigitsCMB x x -padx 2 -sticky ew
    grid configure $gyro.numDecimalsLbl $gyro.numDecimalsCMB x x -padx 2 -sticky ew
    grid configure $gyro.minChangeLbl1 $gyro.minChangeEnt $gyro.minChangeLbl2 x -padx 2 -sticky ew
    grid columnconfigure $gyro 3 -weight 1

    $gyro.minChangeEnt set $::CurrentValue(minChange)

}

proc CreateMagConfigFrame {mag} {
    ##
    ## Magnetometer group
    ##
................................................................................
        -textvariable ::CurrentValue($type,$z) \
        -state readonly
    grid configure $w.xLabel $w.xValue $w.yLabel $w.yValue $w.zLabel $w.zValue x -sticky ew -padx 2 -pady 1
    grid columnconfigure $w [list $w.xLabel $w.yLabel $w.zLabel] -uniform labels -weight 0
    grid columnconfigure $w [list $w.xValue $w.yValue $w.zValue] -uniform values -weight 0
}

proc LoadCurrentConfiguration {} {
    global UI
    global Configuration
    global CurrentValue
    
    foreach optionValue [$CurrentValue(handle) configure] {
        lassign $optionalValue option default value
        ##
        ## Remove the leading -
        ##
        set index [string range $option 1 end]
        if {[info exists UI($index,map,label)]} {
            set value $UI($index,map,label)
        }
        set Configuration($index) $value
    }
}

##
## Main Body
##
set CurrentValue(handle) [dimu new]
LoadCurrentConfiguration
CreateGui
trace add variable Configuration write ConfigurationChange
trace add variable ::Configuration(operation) write ChangeMode

Added make.tcl.





























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
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
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" ${1+"$@"}

proc install {location} {
    global baseDir

    foreach tm [glob [file join $baseDir *.tm]] {
        set baseName [file tail $tm]
        file copy -force -- $tm [file join $location $baseName]
    }

    return
}

proc build {} {
    global baseDir

    foreach dir [glob -types d [file join $baseDir src *]] {
        set tm [file tail $dir]
        set ifd [open [file join $dir version.txt] r]
        array unset versionInfo
        array set versionInfo [read $ifd]
        close $ifd

        set outputName [file join $baseDir $tm-]
        set version [format {%d.%d} $versionInfo(major) $versionInfo(minor)]
        if {[info exists versionInfo(patch)]} {
            append version "." $versionInfo(patch)
        }
        append outputName $version ".tm"
        set ofd [open $outputName w]
        set ifd [open [file join $dir $tm.tcl] r]
        fcopy $ifd $ofd
        puts $ofd {}
        puts $ofd "package provide $tm $version"
        puts $ofd {}
        close $ofd
    }

    return
}

set baseDir [file dirname [info script]]
lassign $argv function location

switch -exact -- $function {
    build {
        build
    }
    install {
        if {$location eq {}} {
            set pattern "*[info tclversion]*"
            foreach dir [::tcl::tm::path list] {
                if {[string match -nocase $pattern $dir]} {
                    set location $dir
                }
            }
        }
        install $location
    }
}

Name change from bno055-1.0.0.tm to src/bno055/bno055.tcl.

Added src/bno055/version.txt.







>
>
>
1
2
3
major 1
minor 0
patch 0

Name change from dimu-1.0.0.tm to src/dimu/dimu.tcl.

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
			GRY_RANGE_1000DPS {
				set divisor 32.0
			}
			GRY_RANGE_2000DPS {
				set divisor 16.0
			}
		}
		set units bno055 getSymbol GRY_UNIT [dict get $currentConfiguration gyr,units]]
		if {units eq "GRY_UNIT_DPS" } {
			dict set results units dps
		} else {
			dict set results units rps
			set divisor [expr {$divsor * 900 / 16}]
		}
		dict set results x [expr {[dict get $readings gyr,data,x] / $divisor}]
		dict set results y [expr {[dict get $readings gyr,data,y] / $divisor}]
		dict set results z [expr {[dict get $readings gyr,data,z] / $divisor}]
	}

}

dimu init







|
|













355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
			GRY_RANGE_1000DPS {
				set divisor 32.0
			}
			GRY_RANGE_2000DPS {
				set divisor 16.0
			}
		}
		set units [bno055 getSymbol GRY_UNIT [dict get $currentConfiguration gyr,units]]
		if {$units eq "GRY_UNIT_DPS" } {
			dict set results units dps
		} else {
			dict set results units rps
			set divisor [expr {$divsor * 900 / 16}]
		}
		dict set results x [expr {[dict get $readings gyr,data,x] / $divisor}]
		dict set results y [expr {[dict get $readings gyr,data,y] / $divisor}]
		dict set results z [expr {[dict get $readings gyr,data,z] / $divisor}]
	}

}

dimu init

Added src/dimu/version.txt.







>
>
>
1
2
3
major 1
minor 0
patch 0