Class: RSMP::TLC::InputStates
- Inherits:
-
Object
- Object
- RSMP::TLC::InputStates
- Defined in:
- lib/rsmp/tlc/input_states.rb
Overview
class that maintains the state of TLC inputs indexing is 1-based since that’s how the RSMP messages are specified
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #actual?(input) ⇒ Boolean
- #actual_string ⇒ Object
- #force(input, forced_value: true) ⇒ Object
- #forced?(input) ⇒ Boolean
- #forced_string ⇒ Object
- #forced_value?(input) ⇒ Boolean
- #forced_value_string ⇒ Object
-
#initialize(size) ⇒ InputStates
constructor
A new instance of InputStates.
- #release(input) ⇒ Object
- #report(input) ⇒ Object
- #reset ⇒ Object
- #set(input, value) ⇒ Object
- #set_forcing(input, force: true, forced_value: true) ⇒ Object
- #value?(input) ⇒ Boolean
- #value_string ⇒ Object
Constructor Details
#initialize(size) ⇒ InputStates
Returns a new instance of InputStates.
8 9 10 11 |
# File 'lib/rsmp/tlc/input_states.rb', line 8 def initialize(size) @size = size reset end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'lib/rsmp/tlc/input_states.rb', line 6 def size @size end |
Instance Method Details
#actual?(input) ⇒ Boolean
65 66 67 68 |
# File 'lib/rsmp/tlc/input_states.rb', line 65 def actual?(input) check_input input from_digit? @actual[input] end |
#actual_string ⇒ Object
91 92 93 |
# File 'lib/rsmp/tlc/input_states.rb', line 91 def actual_string @actual[1..] end |
#force(input, forced_value: true) ⇒ Object
38 39 40 41 42 |
# File 'lib/rsmp/tlc/input_states.rb', line 38 def force(input, forced_value: true) report_change(input) do set_forcing input, force: true, forced_value: forced_value end end |
#forced?(input) ⇒ Boolean
55 56 57 58 |
# File 'lib/rsmp/tlc/input_states.rb', line 55 def forced?(input) check_input input from_digit? @forced[input] end |
#forced_string ⇒ Object
83 84 85 |
# File 'lib/rsmp/tlc/input_states.rb', line 83 def forced_string @forced[1..] end |
#forced_value?(input) ⇒ Boolean
60 61 62 63 |
# File 'lib/rsmp/tlc/input_states.rb', line 60 def forced_value?(input) check_input input from_digit? @forced_value[input] end |
#forced_value_string ⇒ Object
87 88 89 |
# File 'lib/rsmp/tlc/input_states.rb', line 87 def forced_value_string @forced[1..] end |
#release(input) ⇒ Object
44 45 46 47 48 |
# File 'lib/rsmp/tlc/input_states.rb', line 44 def release(input) report_change(input) do set_forcing input, force: false, forced_value: false end end |
#report(input) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/rsmp/tlc/input_states.rb', line 70 def report(input) { value: value?(input), forced: forced?(input), forced_value: forced_value?(input), actual: actual?(input) } end |
#reset ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rsmp/tlc/input_states.rb', line 13 def reset string_size = @size + 1 @value = '0' * string_size @forced = '0' * string_size @forced_value = '0' * string_size @actual = '0' * string_size end |
#set(input, value) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rsmp/tlc/input_states.rb', line 21 def set(input, value) check_input input report_change(input) do @value[input] = to_digit value update_actual input end end |
#set_forcing(input, force: true, forced_value: true) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/rsmp/tlc/input_states.rb', line 29 def set_forcing(input, force: true, forced_value: true) check_input input report_change(input) do @forced[input] = to_digit force @forced_value[input] = to_digit forced_value update_actual input end end |
#value?(input) ⇒ Boolean
50 51 52 53 |
# File 'lib/rsmp/tlc/input_states.rb', line 50 def value?(input) check_input input from_digit? @value[input] end |
#value_string ⇒ Object
79 80 81 |
# File 'lib/rsmp/tlc/input_states.rb', line 79 def value_string @value[1..] end |