Class: TimexDatalinkClient::Protocol9::Timer

Inherits:
Object
  • Object
show all
Includes:
Helpers::CharEncoders, Helpers::CrcPacketsWrapper
Defined in:
lib/timex_datalink_client/protocol_9/timer.rb

Constant Summary collapse

CPACKET_TIMER =
[0x43]
ACTION_AT_END_MAP =
{
  stop_timer: 0,
  repeat_timer: 1,
  start_chrono: 2
}.freeze

Constants included from Helpers::CharEncoders

Helpers::CharEncoders::CHARS, Helpers::CharEncoders::CHARS_PROTOCOL_6, Helpers::CharEncoders::EEPROM_CHARS, Helpers::CharEncoders::EEPROM_TERMINATOR, Helpers::CharEncoders::INVALID_CHAR, Helpers::CharEncoders::PHONE_CHARS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CharEncoders

#chars_for, #eeprom_chars_for, #phone_chars_for, #protocol_6_chars_for

Constructor Details

#initialize(number:, label:, time:, action_at_end:) ⇒ Timer

Create a Timer instance.

Parameters:

  • number (Integer)

    Entry number for timer.

  • label (String)

    Label for timer.

  • time (Time)

    Time of timer.

  • action_at_end (:stop_timer, :repeat_timer, :start_chrono)

    Action at end of timer.



29
30
31
32
33
34
# File 'lib/timex_datalink_client/protocol_9/timer.rb', line 29

def initialize(number:, label:, time:, action_at_end:)
  @number = number
  @label = label
  @time = time
  @action_at_end = action_at_end
end

Instance Attribute Details

#action_at_endObject

Returns the value of attribute action_at_end.



20
21
22
# File 'lib/timex_datalink_client/protocol_9/timer.rb', line 20

def action_at_end
  @action_at_end
end

#labelObject

Returns the value of attribute label.



20
21
22
# File 'lib/timex_datalink_client/protocol_9/timer.rb', line 20

def label
  @label
end

#numberObject

Returns the value of attribute number.



20
21
22
# File 'lib/timex_datalink_client/protocol_9/timer.rb', line 20

def number
  @number
end

#timeObject

Returns the value of attribute time.



20
21
22
# File 'lib/timex_datalink_client/protocol_9/timer.rb', line 20

def time
  @time
end

Instance Method Details

#packetsArray<Array<Integer>>

Compile packets for a timer.

Returns:

  • (Array<Array<Integer>>)

    Two-dimensional array of integers that represent bytes.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/timex_datalink_client/protocol_9/timer.rb', line 39

def packets
  [
    [
      CPACKET_TIMER,
      number,
      time.hour,
      time.min,
      time.sec,
      action_at_end_value,
      label_characters
    ].flatten
  ]
end