Class: RSMP::TLC::Inputs

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/tlc/inputs.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

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ Inputs

Returns a new instance of Inputs.



8
9
10
11
# File 'lib/rsmp/tlc/inputs.rb', line 8

def initialize size
  @size = size
  reset
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/rsmp/tlc/inputs.rb', line 6

def size
  @size
end

Instance Method Details

#actual(input) ⇒ Object



65
66
67
68
# File 'lib/rsmp/tlc/inputs.rb', line 65

def actual input
  check_input input
  from_digit @actual[input]
end

#actual_stringObject



95
96
97
# File 'lib/rsmp/tlc/inputs.rb', line 95

def actual_string
  @actual[1..-1]
end

#force(input, forced_value = true) ⇒ Object



38
39
40
41
42
# File 'lib/rsmp/tlc/inputs.rb', line 38

def force input, forced_value=true
  report_change(input) do
    set_forcing input, true, forced_value
  end
end

#forced?(input) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/rsmp/tlc/inputs.rb', line 55

def forced? input
  check_input input
  from_digit @forced[input]
end

#forced_stringObject



87
88
89
# File 'lib/rsmp/tlc/inputs.rb', line 87

def forced_string
  @forced[1..-1]
end

#forced_value(input) ⇒ Object



60
61
62
63
# File 'lib/rsmp/tlc/inputs.rb', line 60

def forced_value input
  check_input input
  from_digit @forced_value[input]
end

#forced_value_stringObject



91
92
93
# File 'lib/rsmp/tlc/inputs.rb', line 91

def forced_value_string
  @forced[1..-1]
end

#release(input) ⇒ Object



44
45
46
47
48
# File 'lib/rsmp/tlc/inputs.rb', line 44

def release input
  report_change(input) do
    set_forcing input, false, false
  end
end

#report(input) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/rsmp/tlc/inputs.rb', line 70

def report input
  {
    value: value(input),
    forced: forced?(input),
    forced_value: forced_value(input),
    actual:actual(input)
  }
end

#resetObject



13
14
15
16
17
18
19
# File 'lib/rsmp/tlc/inputs.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/inputs.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/inputs.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) ⇒ Object



50
51
52
53
# File 'lib/rsmp/tlc/inputs.rb', line 50

def value input
  check_input input
  from_digit @value[input]
end

#value_stringObject



79
80
81
# File 'lib/rsmp/tlc/inputs.rb', line 79

def value_string
  @value[1..-1]
end