Module Ledgrid (.ml)


module Ledgrid: sig .. end

Constants

Some global constant definitions, for fine-tuning.


Constants

Some global constant definitions, for fine-tuning.
val flash_duration : int
The duration of a LED light "flash", in milliseconds:
val blink_duration : int
The duration of a LED light "blink", in milliseconds. The time is measured from the first to the last state change:
val blink_toggles_no : int
How many times a LED light changes state during a blink. This includes both on->off and off->on transitions:

Exception

The ways this brick can fail.
exception Non_existing_led_light of int * int
An exception raised whenever the user refers a non-existing LED light: in a LED grid
exception Non_existing_port of int
An exception raised whenever the user refers a non-existing port in a device LED grid:

Utility stuff


val tooltips : GData.tooltips
val make_pixmap_from_xpm_file : file_name:string -> GDraw.pixmap
Make a pixmap data structure (not a widget) from the given file:

A single LED light

Gtk+ simulation of just one LED light. Particularly useful when arranged in a grid.
class led_light : ?default:bool -> ?x:int -> ?y:int -> off_pixmap:#GDraw.pixmap -> on_pixmap:#GDraw.pixmap -> packing:(GObj.widget -> unit) -> unit -> object .. end
A LED light is a widget mimicking a single physical LED light, whose state at any given moment can be on or off: its state is represented as a boolean value, and by convention 'true' means 'on'.
val useless_array_of_led_light_options : led_light option array
These variables are just used as parameters to Array.make so that types can be correctly inferred. useless_label's widget is never displayed:
val useless_label : GMisc.label

LED grid

Gtk+ simulation of a grid of LED lights.
class led_grid : ?default:bool -> on_xpm_file_name:string -> off_xpm_file_name:string -> nothing_xpm_file_name:string -> columns:int -> rows:int -> packing:(GObj.widget -> unit) -> ?angle:float -> ?no_leds_at:(int * int) list -> unit -> object .. end
A LED grid visually represents a matrix of LED lights, where each light is independently controllable.
val range : int -> int -> int list
To do: recycle this from Jean's library

Device LED Grid

A matrix of LED lights simulating the control panel of a phisical network device such as a switch or a router.
class device_led_grid : on_xpm_file_name:string -> off_xpm_file_name:string -> nothing_xpm_file_name:string -> ?show_100_mbs:bool -> ports:int -> packing:(GObj.widget -> unit) -> ?angle:float -> ?lines:int -> unit -> object .. end
A 'device LED grid' is a LED grid specialized as a realistic simulation of the control panel of a physical device such as a switch, a hub or a router.

Example

A trivial usage example.

let main ports () =
  let window = GWindow.window ~title:"Switch n.2" ~border_width:0 () in
  window#connect#destroy ~callback:GMain.Main.quit;
  let grid =
    new device_led_grid ~packing:window#add ~ports ~show_100_mbs:true ~lines:2
      ~off_xpm_file_name:"sample-files/off.xpm"
      ~on_xpm_file_name:"sample-files/on.xpm"
      ~nothing_xpm_file_name:"sample-files/nothing.xpm"
      () in  
  for i = 1 to ports / 3 do
    grid#connect ((Random.int ports) + 1);
  done;

  (** Simulate a distinct communication between two ports every 50 milliseconds: *)
  GMain.Timeout.add 50 (function () -> grid#blink (grid#random_connected_port); 
                                       grid#blink (grid#random_connected_port);
                                       true);
  window#show ();
  Main.main ()
let _ = main 64 ()