Revert mode activated.

This commit is contained in:
Tobias Bora 2013-12-07 19:51:40 +01:00
parent 2a7ca76e15
commit 76be9195ee
3 changed files with 16 additions and 13 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@ let _ =
setupPhys (); setupPhys ();
(* reg : pin_value = p_v, pin_shift = p_s, pin_apply = p_a *) (* reg : pin_value = p_v, pin_shift = p_s, pin_apply = p_a *)
(* On crée le register *) (* On crée le register *)
let reg = (11,13,15) in let reg = genReg 11 13 15 ~invert:true in
(* On initialise *) (* On initialise *)
let leds = initReg reg ~nb_reg:1 in let leds = initReg reg ~nb_reg:1 in
(* On boucle pour afficher les leds unes par unes *) (* On boucle pour afficher les leds unes par unes *)

View File

@ -6,30 +6,33 @@
*) *)
open WiringPiOcaml open WiringPiOcaml
(** reg : (pin_value = p_v, pin_shift = p_s, pin_apply = p_a). It is (** reg : (pin_value = p_v, pin_shift = p_s, pin_apply = p_a). It is
used to contain the needed input **) used to contain the informations about connections. The invert
type reg = int * int * int;; variable is used in order to revert the mode (false = lighted,
true = not lighted) **)
type reg = {p_v : int; p_s : int; p_a : int; invert : bool}
(** The first thing to do is setupPhys (). This function put in OUTPUT (** The first thing to do is setupPhys (). This function put in OUTPUT
mode the outputs and return back a bool array which represent the output of registers (begining with the first LED of the first shift register) **) mode the outputs and return back a bool array which represent the output of registers (begining with the first LED of the first shift register) **)
let initReg ?nb_reg:(nb_reg = 1) reg = let initReg ?nb_reg:(nb_reg = 1) reg =
let (p_v, p_s, p_a) = reg in pinMode reg.p_v 1; (* mode output *)
pinMode p_v 1; (* mode output *) pinMode reg.p_s 1;
pinMode p_s 1; pinMode reg.p_a 1;
pinMode p_a 1;
Array.make (8*nb_reg) false (* return back an array for all pieces *) Array.make (8*nb_reg) false (* return back an array for all pieces *)
let write pin value = digitalWrite pin (if value then 1 else 0) let write pin value = digitalWrite pin (if value then 1 else 0)
let genReg ?invert:(invert = false) pin_value pin_shift pin_apply =
{p_v = pin_value; p_s = pin_shift; p_a = pin_apply; invert = invert}
(** This function apply all modifications to the register **) (** This function apply all modifications to the register **)
let applyReg reg leds = let applyReg reg leds =
let (p_v, p_s, p_a) = reg in write reg.p_a false;
write p_a false;
for i = (Array.length leds) - 1 downto 0 do for i = (Array.length leds) - 1 downto 0 do
write p_s false; write reg.p_s false;
write p_v leds.(i); write reg.p_v (leds.(i) <> reg.invert); (* On inverse si besoin *)
write p_s true; write reg.p_s true;
done; done;
write p_a true write reg.p_a true
(** Don't forget to apply it with applyReg after **) (** Don't forget to apply it with applyReg after **)