Class: TimexDatalinkClient::Protocol7::Eeprom::Calendar

Inherits:
Object
  • Object
show all
Includes:
Helpers::FourByteFormatter, Helpers::LsbMsbFormatter
Defined in:
lib/timex_datalink_client/protocol_7/eeprom/calendar.rb,
lib/timex_datalink_client/protocol_7/eeprom/calendar/event.rb

Defined Under Namespace

Classes: Event

Constant Summary collapse

DAY_START_TIME =
Time.new(2000)
DAY_SECONDS =
86400
EVENTS_BYTES_BASE =
2
EVENTS_BYTES_EVENT =
4
EVENTS_BYTES_PHRASE_PACKET =
5
PACKETS_TERMINATOR =
0x01

Constants included from Helpers::FourByteFormatter

Helpers::FourByteFormatter::BYTE_NULL, Helpers::FourByteFormatter::BYTE_TERMINATOR_ENDF, Helpers::FourByteFormatter::BYTE_TERMINATOR_ENDR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::LsbMsbFormatter

#lsb_msb_format_for

Methods included from Helpers::FourByteFormatter

#four_byte_format_for

Constructor Details

#initialize(time:, events: []) ⇒ Calendar

Create a Calendar instance.

Parameters:

  • time (::Time)

    Time to set device to.

  • events (Array<Event>) (defaults to: [])

    Event instances to add to the calendar.



29
30
31
32
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar.rb', line 29

def initialize(time:, events: [])
  @time = time
  @events = events
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



22
23
24
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar.rb', line 22

def events
  @events
end

#timeObject

Returns the value of attribute time.



22
23
24
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar.rb', line 22

def time
  @time
end

Instance Method Details

#packetArray<Integer>

Compile data for calendar.

Returns:

  • (Array<Integer>)

    Compiled data for calendar.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/timex_datalink_client/protocol_7/eeprom/calendar.rb', line 37

def packet
  [
    events_count,
    event_packets,
    event_phrases,
    time.hour,
    time.min,
    days_from_2000,
    time_formatted,
    PACKETS_TERMINATOR
  ].flatten
end