HOWTO, API Reference for SegLED

segled-api

segled.rb - SegLED class

Basic usage

Display H, E, L, L, and O in order for every second.

require 'segled'

SegLED.open { |led|
  led.print "HELLO"
}

API Reference(SegLED class)

Constants

segled.png

SegLED::Constants
  • SegLED::Constants::L - LEFT
  • SegLED::Constants::R - RIGHT
  • SegLED::Constants::C - CENTER
  • SegLED::Constants::TL - TOP-LEFT
  • SegLED::Constants::TR - TOP-RIGHT
  • SegLED::Constants::BL - BOTTOM-LEFT
  • SegLED::Constants::BR - BOTTOM-RIGHT
  • SegLED::Constants::DOT - DOT
  • SegLED::Constants::TOP - TOP(TR + TL)
  • SegLED::Constants::BTM - BOTTOM(BR + BL)
  • SegLED::Constants::ALL - ALL
  • SegLED::Constants::NONE - NONE

You can access both SegLED::FOO and SegLED::Constants::FOO. They are same meaning.

Class Methods

SegLED.open
SegLED.open {|led| block}
With no associated block, open retun instance of SegLED. If the optional code block is given, it will be passed SegLED instance as an argument, and the SegLED will automatically be closed when the block terminates. In this instance, SegLED::open retuns nil.
SegLED.new(io)
Create instance of SegLED with io that is File object of /dev/segled. Usually, This method is not used.

Instance Methods

close
Closes SegLED and flushes any pending writes to the operating system. stream is unavailable for any further data operations; an IOError is raised if such an attempt is made. I/O streams are automatically closed when they are claimed by the garbage collector.
closed?
Retuns true if SegLED is completely closed, false otherwise.
print(val, interval = 0, flush_interval = 0)
val is Array of SegLED::Constants or String.
  • Array of SegLED::Constants The elements of Array are SegLED::Constants. print() calls write() with each element. An element is displayed and sleep for interval, and flushed for flush_interval.
  • String Display each character, sleep for interval and flush for flush_interval. You can set ASCII characters.
write(n, interval = 0)

Display LED and sleep for interval. n is a value of SegLED::Constants. If you want to some LED, you can use "+", "-" operator.

led.write(SegLED::L + SegLED::R + SegLED::BTM)

write_val(val, interval = 0)
Display LED and sleep for interval. val is a value of 0-9, A-F.
putc(c, interval = 0)
Display LED and sleep for interval. c is ASCII code (String#chr).
clear(interval = 0)
Clear LED and sleep for interval.
test
Test mode of SegLED. This method is used purpose of Test only. If you call this method, You have to terminate it compulsorily.

segled-utils.rb - SegLEDUtils module

Basic usage

Display H, E, L, L, and O in order for every second.

require 'segled-utils'

SegLEDUtils.init
SegLEDUtils.run "HELLO"

That's all. Only that, you can make LED clear when SIGINT,SIGTERM,SIGHUP traps are occured. (First SegLED's example does not have trap handling)

API Reference(SegLEDUtils module)

SegLEDUtils.init(signal = ["SIGINT", "SIGTERM", "SIGHUP"])
Initial trap handling. signal is array of SIGNAL what you catch.
SegLEDUtils.init_d(signal = ["SIGINT", "SIGTERM", "SIGHUP"])
Initial your script as daemon then call SegLEDUtils.init.
SegLEDUtils.run(val, interval = 0.1, flush_interval = 0)
Run LED(infinite loop). val is array of SegLED::Constants or String.
  • Array of SegLED::Constants The elements of Array are SegLED::Constants. print() calls write() with each element. An element is displayed and sleep for interval, and flushed for flush_interval.
  • String Display each character, sleep for interval and flush for flush_interval. You can set ASCII characters.

samples/runled

This is yet another /etc/init.d/runled. You can run your script like runled(standard version for OpenBlockSS). Check header part of this script, and revise it for your environment.

Last modified:2003/07/21 19:34:03
Keyword(s):
References:[SegLED]