Sha256: 3687b82416e8cbba40db1e9f48f2ddad04875a7179a27586c46a21630babea2c

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib')

require 'green_eye_monitor/client'

require 'slop'
require 'awesome_print'
require 'terminal-table'

opts = Slop.parse do |o|
  o.bool '-d', '--debug', 'enable debug mode'
  o.string '--port', 'serial port', default: '/dev/ttyUSB1'
  o.on '--version', 'print the version' do
    puts Slop::VERSION
    exit
  end
end

client = GreenEyeMonitor::Client.new(:baud => 115_200, :serial_port => opts[:port], :debug => opts[:debug])

puts '# Direct'
puts "Serial: #{client.serial}"
puts "Hertz: #{client.hertz}"
puts "Temp: #{client.temperature(1)}"
# puts "Recent: #{client.recent_values}"
puts

puts '# List Format'
client.packet_format = :list
puts client.send_one_packet

puts
puts

puts '# Bin32 Net Format'
client.packet_format = :bin32_net
data = client.send_one_packet
sleep(2)
data = client.send_one_packet(data)

# ap data.snapshot
puts "Serial: #{data.serial_number}"
puts "Voltage: #{data.voltage}"
puts "Seconds: #{data.seconds}"
puts "Pulse: #{data.pulse}"
puts "Temperature: #{data.temperature}"
puts

rows = []
# rows << ['ABS Watt Seconds'] + data.abs_watt_seconds
# rows << ['Polarised Watt Seconds'] + data.polarised_watt_seconds
rows << ['ABS Watts'] + data.abs_watts
rows << ['VA'] + data.va
rows << ['Polarised Watts'] + data.polarised_watts
rows << ['Current'] + data.current
rows.each {|row| row.slice!(15..28)}
headings = [''] + (1..15).to_a + (30..32).to_a
puts Terminal::Table.new(:rows => rows, :headings => headings)
puts

puts "ABS Total: #{data.abs_watts.to_a[0..14].inject(:+)} vs #{data.abs_watts.to_a[28..31].inject(:+)}"
puts "Polarised Total: #{data.polarised_watts.to_a[0..24].inject(:+)} vs #{data.polarised_watts.to_a[28..31].inject(:+)}"
puts "VA Total: #{data.va.to_a[0..14].inject(:+)} vs #{data.va.to_a[28..31].inject(:+)}"
puts "Current Total: #{data.current.to_a[0..14].inject(:+)} vs #{data.current.to_a[28..31].inject(:+)}"

# client.shell

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
green_eye_monitor-0.0.3 exe/green_eye_monitor