Class: BWA::Messages::SetTemperatureScale

Inherits:
BWA::Message show all
Defined in:
lib/bwa/messages/set_temperature_scale.rb

Constant Summary collapse

MESSAGE_TYPE =
"\xbf\x27".b
MESSAGE_LENGTH =
2

Instance Attribute Summary collapse

Attributes inherited from BWA::Message

#raw_data, #src

Instance Method Summary collapse

Methods inherited from BWA::Message

format_duration, format_time, inherited, #log?, parse

Constructor Details

#initialize(scale = nil) ⇒ SetTemperatureScale

Returns a new instance of SetTemperatureScale.



11
12
13
14
# File 'lib/bwa/messages/set_temperature_scale.rb', line 11

def initialize(scale = nil)
  super()
  self.scale = scale
end

Instance Attribute Details

#scaleObject

Returns the value of attribute scale.



9
10
11
# File 'lib/bwa/messages/set_temperature_scale.rb', line 9

def scale
  @scale
end

Instance Method Details

#inspectObject



26
27
28
# File 'lib/bwa/messages/set_temperature_scale.rb', line 26

def inspect
  "#<BWA::Messages::SetTemperatureScale °#{scale.to_s[0].upcase}>"
end

#parse(data) ⇒ Object



16
17
18
# File 'lib/bwa/messages/set_temperature_scale.rb', line 16

def parse(data)
  self.scale = data[1].ord.zero? ? :fahrenheit : :celsius
end

#serializeObject



20
21
22
23
24
# File 'lib/bwa/messages/set_temperature_scale.rb', line 20

def serialize
  data = +"\x01\x00"
  data[1] = ((scale == :fahrenheit) ? 0x00 : 0x01).chr
  super(data)
end