lib/postrunner/DeviceList.rb in postrunner-0.0.10 vs lib/postrunner/DeviceList.rb in postrunner-0.0.11
- old
+ new
@@ -18,10 +18,29 @@
class DeviceList
include Fit4Ruby::Converters
+ DeviceTypeNames = {
+ 'acceleration' => 'Accelerometer',
+ 'antfs' => 'Main Unit',
+ 'barometric_pressure' => 'Barometer',
+ 'bike_cadence' => 'Bike Cadence',
+ 'bike_power' => 'Bike Power Meter',
+ 'bike_speed' => 'Bike Speed',
+ 'bike_speed_cadence' => 'Bike Speed + Cadence',
+ 'environment_sensor_legacy' => 'GPS',
+ 'gps' => 'GPS',
+ 'heart_rate' => 'Heart Rate Sensor',
+ 'running_dynamics' => 'Running Dynamics',
+ 'stride_speed_distance' => 'Footpod'
+ }
+ ProductNames = {
+ 'hrm_run_single_byte_product_id' => 'HRM Run',
+ 'hrm_run' => 'HRM Run'
+ }
+
def initialize(fit_activity)
@fit_activity = fit_activity
end
def to_html(doc)
@@ -36,66 +55,70 @@
def devices
tables = []
seen_indexes = []
@fit_activity.device_infos.reverse_each do |device|
- next if seen_indexes.include?(device.device_index) ||
- device.manufacturer.nil? ||
- device.manufacturer == 'Undocumented value 0' ||
- device.device_type == 'Undocumented value 0'
+ next if seen_indexes.include?(device.device_index)
tables << (t = FlexiTable.new)
t.set_html_attrs(:style, 'margin-bottom: 15px') if tables.length != 1
t.body
- t.cell('Manufacturer:', { :width => '40%' })
- t.cell(device.manufacturer.upcase, { :width => '60%' })
+ t.cell('Index:', { :width => '40%' })
+ t.cell(device.device_index.to_s, { :width => '60%' })
t.new_row
+ if (manufacturer = device.manufacturer)
+ t.cell('Manufacturer:', { :width => '40%' })
+ t.cell(manufacturer.upcase, { :width => '60%' })
+ t.new_row
+ end
+
if (product = %w( garmin dynastream dynastream_oem ).include?(
- device.manufacturer) ?
- device.garmin_product : device.product)
+ device.manufacturer) ? device.garmin_product : device.product) &&
+ product != 0xFFFF
# For unknown products the numerical ID will be returned.
product = product.to_s unless product.is_a?(String)
t.cell('Product:')
# Beautify some product names. The others will just be upcased.
- rename = { 'hrm_run_single_byte_product_id' => 'HRM Run',
- 'hrm_run' => 'HRM Run' }
- product = rename.include?(product) ? rename[product] : product.upcase
+ product = ProductNames.include?(product) ?
+ ProductNames[product] : product.upcase
t.cell(product)
t.new_row
end
+
if (type = device.device_type)
- rename = { 'heart_rate' => 'Heart Rate Sensor',
- 'barometric_pressure' => 'Barometer',
- 'position' => 'GPS',
- 'stride_speed_distance' => 'Footpod',
- 'running_dynamics' => 'Running Dynamics' }
- type = rename[type] if rename.include?(type)
+ # Beautify some device type names.
+ type = DeviceTypeNames[type] if DeviceTypeNames.include?(type)
t.cell('Device Type:')
t.cell(type)
t.new_row
end
+
if device.serial_number
t.cell('Serial Number:')
t.cell(device.serial_number)
t.new_row
end
+
if device.software_version
t.cell('Software Version:')
t.cell(device.software_version)
t.new_row
end
+
if (rx_ok = device.rx_packets_ok) && (rx_err = device.rx_packets_err)
t.cell('Packet Errors:')
t.cell('%d%%' % ((rx_err.to_f / (rx_ok + rx_err)) * 100).to_i)
t.new_row
end
+
if device.battery_status
t.cell('Battery Status:')
t.cell(device.battery_status)
t.new_row
end
+
if device.cum_operating_time
t.cell('Cumulated Operating Time:')
t.cell(secsToDHMS(device.cum_operating_time))
t.new_row
end