Useful Procs
proc sleep {time} {
after $time set end 1
vwait end
}
proc timestamp { } {
return "\[[clock format [clock seconds] -format {%m/%d %H:%M:%S}]\] "
}
Raspberry Pi - HDMI off/on with xscreensaver
set debug FALSE
set verbose FALSE
proc verbose:puts { args } {
if {$::verbose} {
puts {*}$args
}
}
proc debug:puts { args } {
if {$::debug} {
puts {*}$args
}
}
proc cmd:run { args } {
set cmd [eval concat $args]
if { [catch {open |$cmd r+} pipe] } {
verbose:puts "cmd:run\[$pipe\]<<ERROR \[$::errorCode\]"
} else {
verbose:puts "cmd:run\[$pipe\]>>\[$cmd\]"
fconfigure $pipe -buffering none -blocking 1
fileevent $pipe readable [list cmd:read $pipe]
}
}
proc cmd:read { pipe } {
set chars [gets $pipe line]
if { [eof $pipe] || $chars == -1} {
fileevent $pipe readable {}
if { [catch {close $pipe} code] } {
puts "cmd:read\[$pipe\]>>Error \[$::errorCode\] $code"
} else {
debug:puts "cmd:read\[$pipe\]>>pipe closed."
}
set _(done) 1
return
} else {
verbose:puts "cmd:read\[$pipe\]<<\[$line\] ($chars chars)"
}
if {[string first "BLANK" $line] == 0 } {
puts "cmd:read\[$pipe\]>>Turning off HDMI"
cmd:run [list "/opt/vc/bin/tvservice" "-o"]
} elseif {[string first "UNBLANK" $line] == 0 } {
puts "cmd:read\[$pipe\]>>Turning on HDMI"
cmd:run [list "/opt/vc/bin/tvservice" "-p"]
}
}
cmd:run "xscreensaver-command -watch"
vwait forever