Class: HackyHAL::DeviceControllers::EpsonProjector

Inherits:
GenericSerialPort show all
Defined in:
lib/hacky_hal/device_controllers/epson_projector.rb

Constant Summary collapse

SERIAL_PORT_OPTIONS =
{
  baud_rate: 9600,
  data_bits: 8,
  stop_bits: 1,
  parity: SerialPort::NONE,
  flow_control: SerialPort::NONE
}
SOURCE_COMMAND_TIMEOUT =
5
POWER_STATUS_TO_SYMBOL =
{
  "00" => :standby, # standby, network off
  "01" => :on,
  "02" => :warming_up,
  "03" => :cooling_down,
  "04" => :standby, # standby, network on
  "05" => :standby # standby, abnormal
}
DEVICE_SOURCE_ID_TO_NAME =
{
  "HC8350" => {
    "30" => "HDMI1",
    "A0" => "HDMI2",
    "14" => "Component (YCbCr)",
    "15" => "Component (YPbPr)",
    "21" => "PC",
    "41" => "Video (RCA)",
    "42" => "S-Video"
  }
}
DEVICE_CMODE_ID_TO_NAME =
{
  "HC8350" => {
    "06" => "Dynamic",
    "0C" => "Living Room",
    "07" => "Natural",
    "15" => "Cinema",
    "0B" => "x.v.Color"
  }
}
DEVICE_ASPECT_RATIO_ID_TO_NAME =
{
  "HC8350" => {
    "00" => "Normal"
  }
}
ERROR_CODE_TO_MESSAGE =
{
  "00" => "There is no error or the error is recovered",
  "01" => "Fan error",
  "03" => "Lamp failure at power on",
  "04" => "High internal temperature error",
  "06" => "Lamp error",
  "07" => "Open Lamp cover door error",
  "08" => "Cinema filter error",
  "09" => "Electric dual-layered capacitor is disconnected",
  "0A" => "Auto iris error",
  "0B" => "Subsystem Error",
  "0C" => "Low air flow error",
  "0D" => "Air filter air flow sensor error",
  "0E" => "Power supply unit error (Ballast)",
  "0F" => "Shutter error",
  "10" => "Cooling system error (peltiert element)",
  "11" => "Cooling system error (Pump)"
}

Constants inherited from GenericSerialPort

GenericSerialPort::DEFAULT_COMMAND_TIMEOUT, GenericSerialPort::DEFAULT_OPTIONS, GenericSerialPort::MAX_READ_WRITE_RETRIES

Instance Attribute Summary collapse

Attributes inherited from GenericSerialPort

#serial_device_path, #serial_options

Attributes included from Options

#options

Instance Method Summary collapse

Methods inherited from GenericSerialPort

#disconnect, #read_command, #serial_port, #write_command

Methods inherited from Base

#log

Methods included from Options

#[]

Constructor Details

#initialize(options = {}) ⇒ EpsonProjector

Returns a new instance of EpsonProjector.



75
76
77
78
79
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 75

def initialize(options = {})
  options[:serial_options] = SERIAL_PORT_OPTIONS
  super(options)
  @model = options[:model]
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



73
74
75
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 73

def model
  @model
end

Instance Method Details

#aspect_ratioObject



132
133
134
135
136
137
138
139
140
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 132

def aspect_ratio
  write_command("ASPECT?")
  aspect_ratio_id = get_command_output(read_command)
  
  aspect_ratio_hash = DEVICE_ASPECT_RATIO_ID_TO_NAME[model]
  aspect_ratio_name = aspect_ratio_hash[aspect_ratio_id] || "Unknown"

  {id: aspect_ratio_id, name: aspect_ratio_name}
end

#color_modeObject



117
118
119
120
121
122
123
124
125
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 117

def color_mode
  write_command("CMODE?")
  color_mode_id = get_command_output(read_command)

  color_mode_hash = DEVICE_CMODE_ID_TO_NAME[model]
  color_mode_name = color_mode_hash[color_mode_id] || "Unknown"

  {id: color_mode_id, name: color_mode_name}
end

#errorObject



147
148
149
150
151
152
153
154
155
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 147

def error
  write_command("ERR?")
  set_read_timeout(DEFAULT_COMMAND_TIMEOUT)
  error_code = get_command_output(read_line)
  if error_code
    error_message = ERROR_CODE_TO_MESSAGE[error_code] || "Unknown"
    {code: error_code, message: error_message}
  end
end

#lamp_hoursObject



97
98
99
100
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 97

def lamp_hours
  write_command("LAMP?")
  get_command_output(read_command).to_i
end

#powerObject



81
82
83
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 81

def power
  power_status == :on
end

#power_statusObject



91
92
93
94
95
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 91

def power_status
  write_command("PWR?")
  status_code = get_command_output(read_command)
  POWER_STATUS_TO_SYMBOL[status_code] || :unknown
end

#set_aspect_ratio(aspect_ratio_id) ⇒ Object



142
143
144
145
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 142

def set_aspect_ratio(aspect_ratio_id)
  write_command("ASPECT #{aspect_ratio_id}")
  read_command
end

#set_color_mode(color_mode_id) ⇒ Object



127
128
129
130
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 127

def set_color_mode(color_mode_id)
  write_command("CMODE #{color_mode_id}")
  read_command
end

#set_power(value) ⇒ Object



85
86
87
88
89
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 85

def set_power(value)
  value = value ? "ON" : "OFF"
  write_command("PWR #{value}")
  read_command(1)
end

#set_source(source_id) ⇒ Object



112
113
114
115
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 112

def set_source(source_id)
  write_command("SOURCE #{source_id}")
  read_command(SOURCE_COMMAND_TIMEOUT)
end

#sourceObject



102
103
104
105
106
107
108
109
110
# File 'lib/hacky_hal/device_controllers/epson_projector.rb', line 102

def source
  write_command("SOURCE?")
  source_id = get_command_output(read_command)

  source_name_hash = DEVICE_SOURCE_ID_TO_NAME[model]
  source_name = source_name_hash[source_id] || "Unknown"

  {id: source_id, name: source_name}
end