Programming Reference
Reference for the Ruby API available on Harucom.
Harucom API
Harucom comes with libraries for screen drawing and keyboard input.
DVI Module
A low-level API for controlling DVI output and drawing on screen. It has two display modes: text mode (106 columns x 37 rows) and graphics mode (640x480 / 320x240).
DVI.set_mode(DVI::GRAPHICS_MODE)
DVI::Graphics.fill_circle(160, 120, 50, 0xE0)
DVI::Graphics.commit
For complex screen drawing, the P5 Drawing Library provides a convenient wrapper.
P5 Drawing Library
A drawing library that provides a Processing-like interface. It wraps DVI::Graphics and offers an easy-to-use API for fill and stroke colors, coordinate transforms, blend modes, and more.
require "p5"
p5 = P5.new
p5.fill(p5.color(255, 0, 0))
p5.circle(160, 120, 50)
p5.commit
Keyboard
An API for handling input from a USB keyboard.
You can get key input through the global variable $keyboard.
key = $keyboard.read_char
case key
when Keyboard::CTRL_Q then break
when Keyboard::ENTER then puts "Enter"
end
PicoRuby Libraries
Harucom runs on PicoRuby.
The following PicoRuby libraries are available. For detailed usage, refer to the PicoRuby reference at each link.
Filesystem
| Class | Description |
|---|---|
| File | File reading and writing |
| Dir | Directory operations |
File.open("/data.txt", "r") { |f| f.read(256) }
File.open("/data.txt", "w") { |f| f.write("hello") }
Dir.mkdir("/mydir")
Data Formats
| Class | Description |
|---|---|
| JSON | JSON reading and writing |
| YAML | YAML reading and writing |
| Marshal | Ruby object serialization |
| Base64 | Base64 encoding and decoding |
| Base16 | Hex string conversion |
Hardware & System
| Class | Description |
|---|---|
| GPIO | GPIO pin control |
| Time | Time retrieval and manipulation |
| Watchdog | Watchdog timer |
| Math | Math functions |
Built-in Classes
| Class | Description |
|---|---|
| String | Strings |
| Array | Arrays |
| Hash | Hashes |
| Integer | Integers |
| Float | Floating-point numbers |
| Kernel | Basic methods like puts, sleep |
require
require "p5" # Searches $LOAD_PATH (default: ["/lib"])