Ifos Hardware Check
October 12, 2008 | 6 Minute Read
H ere's a short video of Ifos running a hardware check. The LEDs are intensely bright, so it probably would have been better not to shoot them straight-on, but the basic operation is still obvious.
Here’s the code used to generate the test patterns:
#!/usr/bin/ruby
## ---------------------------------------------------------------------------
##
## Ifos
##
## Copyright © 2006-8 Peter Heinrich
## All Rights Reserved
##
## $URL: svn://saphum.com/PIC/ifos/trunk/test.rb $
## $Revision: 371 $
##
## ---------------------------------------------------------------------------
## $Author: Peter $
## $Date: 2008-10-12 21:47:56 +0000 (Sun, 12 Oct 2008) $
## ---------------------------------------------------------------------------
require "modbus.rb"
# Create a Modbus connection on COM port 4 (ASCII mode, for testing)
@mb = Modbus . new 3 , false
# Use the Modbus Write Registers command to blast a bunch of values
# to device 4 (the device under test).
def on ( index , values )
values = [ values ] unless values . kind_of? Array
@mb . writeRegisters 4 , index , values
end
# Turn off one or more LEDs by writing 0 to them.
def off ( index , length = 1 )
values = Array . new ( length , 0 )
on index , values
end
# Light one component of all RGB LEDs simultaneously,
# progressing sequentially through all possible intensities.
def test_rgb_leds ( shift )
( 0 . . 16 ). each do | s |
# These LEDs take a 1-5-5-5 RGB color, so the shift selects
# which color component receives the intensity value.
values = Array . new ( 8 , s << shift )
on 0 , values
end
# Turn off all the RGB LEDs.
( 0 . . 7 ). each do | i |
off i
end
end
# Light all of the white LEDs simultaneously at each of the
# possible intensities.
def test_white_leds
( 0 . . 16 ). each do | s |
values = Array . new ( 16 , s )
on 8 , values
end
# Turn off all the white LEDs.
( 8 . . 23 ). each do | i |
off i
end
end
# The RGB LEDs can be controlled with a single register (0-7),
# but each component may also be accessed individually at a
# register "alias" (24-47).
def test_virtual_leds
( 24 . . 47 ). each do | i |
on i , 8
end
( 24 . . 47 ). each do | i |
off i
end
end
# Bring up a color wash between two primary components.
def test_color_fade ( start_shift , end_shift )
# Fade up the color wash over all intensities.
( 0 . . 16 ). each do | s |
values = Array . new ( 8 , 0 )
( 0 . . 7 ). each do | i |
values [ i ] = (( i * s / 7 ) << end_shift ) + ((( 7 - i ) * s / 7 ) << start_shift )
end
on 0 , values
end
# Fade down the color wash.
( 0 . . 16 ). each do | s |
values = Array . new ( 8 , 0 )
( 0 . . 7 ). each do | i |
values [ i ] = (( i * ( 16 - s ) / 7 ) << end_shift ) + ((( 7 - i ) * ( 16 - s ) / 7 ) << start_shift )
end
on 0 , values
end
end
# Randomly light a selection of single LEDs, then do the same
# in combinations of 2, 3, 4, etc., up to 8 simultaneously.
def test_random ( first , count )
( 1 . . 8 ). each do | s |
16 . times do
values = Array . new ( count , 0 )
s . times { | c | values [ rand ( count ) ] = 1 + rand ( 16 ) }
on first , count
off first , count
end
end
end
# Randomly light the white LEDs only.
def test_random_white
test_random ( 8 , 16 )
end
# Randomly light the individual RGB components only.
def test_random_virtual
test_random ( 24 , 24 )
end
# Randomly light any white or individual RGB component LEDs.
def test_random_all
test_random ( 8 , 40 )
end
# Execute the tests.
test_rgb_leds 0 # red
test_rgb_leds 5 # green
test_rgb_leds 10 # blue
test_white_leds
test_virtual_leds
test_color_fade 0 , 5 # red -> green
test_color_fade 5 , 0 # green -> red
test_color_fade 5 , 10 # green -> blue
test_color_fade 10 , 5 # blue -> green
test_color_fade 10 , 0 # blue -> red
test_color_fade 0 , 10 # red -> blue
test_random_white
test_random_virtual
test_random_all