green_eye_monitor 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cb9382f227f92a98dcc439bc7176ef5c4003147
4
- data.tar.gz: 0f4d9dc2d207d4553a535670a3b0fc9f7ee80366
3
+ metadata.gz: 7663ce5a7fac9acec62f26da6736257acd048c09
4
+ data.tar.gz: bdf2c0843106306a6fb8ea85750028fdf18a95f6
5
5
  SHA512:
6
- metadata.gz: 695e3d2ea31df523c48057939184afd5abd2382fae5d3ac22f145ef34c26fb1111ce3f6c555dfbbccc3655a612bde5bd542d611164c063b4140d97f6170dcd5d
7
- data.tar.gz: 31d1778a2c5977ea7da9858fdcecf3949fd5ff5556298e53de48a085553b8f64d218749e4d9e488137ab7225ede4fbd4f5f80a1c9141a97139e9662e0c936c67
6
+ metadata.gz: 2d037172e610ae30773832c2a7d3d31da14e1765626a3d908ea3fab3187c8d931526323ce7f221d935c9fb1ab64a5ab5faa05d63617497072e01bfeab983af59
7
+ data.tar.gz: e7d7a2748ffbd88b8f94843da8007d71672ddf10d6b18476e277fc562d4e9cb7e7165dd1ddc52cf4b9240eda7348562011d1a28bc970e8f4a31f0e49cc4d21a4
@@ -30,7 +30,13 @@ Style/ModuleFunction:
30
30
  Enabled: false
31
31
 
32
32
  Metrics/AbcSize:
33
- Max: 20
33
+ Max: 25
34
+
35
+ Metrics/CyclomaticComplexity:
36
+ Max: 7
37
+
38
+ Metrics/PerceivedComplexity:
39
+ Max: 8
34
40
 
35
41
  AlignHash:
36
42
  EnforcedHashRocketStyle: table
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ # 0.0.4 (20160518)
4
+
5
+ * Don't wait on serial port forever (@johnf)
6
+
3
7
  # 0.0.3 (20160515)
4
8
 
5
9
  * Add functionality to derive watts based on previous packet (@johnf)
@@ -10,7 +10,7 @@ require 'terminal-table'
10
10
 
11
11
  opts = Slop.parse do |o|
12
12
  o.bool '-d', '--debug', 'enable debug mode'
13
- o.string '--port', 'serial port', default: '/dev/ttyUSB1'
13
+ o.string '--port', 'serial port', :default => '/dev/ttyUSB1'
14
14
  o.on '--version', 'print the version' do
15
15
  puts Slop::VERSION
16
16
  exit
@@ -54,13 +54,13 @@ rows << ['ABS Watts'] + data.abs_watts
54
54
  rows << ['VA'] + data.va
55
55
  rows << ['Polarised Watts'] + data.polarised_watts
56
56
  rows << ['Current'] + data.current
57
- rows.each {|row| row.slice!(15..28)}
57
+ rows.each { |row| row.slice!(15..28) }
58
58
  headings = [''] + (1..15).to_a + (30..32).to_a
59
59
  puts Terminal::Table.new(:rows => rows, :headings => headings)
60
60
  puts
61
61
 
62
62
  puts "ABS Total: #{data.abs_watts.to_a[0..14].inject(:+)} vs #{data.abs_watts.to_a[28..31].inject(:+)}"
63
- puts "Polarised Total: #{data.polarised_watts.to_a[0..24].inject(:+)} vs #{data.polarised_watts.to_a[28..31].inject(:+)}"
63
+ puts "Polar Total: #{data.polarised_watts.to_a[0..24].inject(:+)} vs #{data.polarised_watts.to_a[28..31].inject(:+)}"
64
64
  puts "VA Total: #{data.va.to_a[0..14].inject(:+)} vs #{data.va.to_a[28..31].inject(:+)}"
65
65
  puts "Current Total: #{data.current.to_a[0..14].inject(:+)} vs #{data.current.to_a[28..31].inject(:+)}"
66
66
 
@@ -192,7 +192,7 @@ module GreenEyeMonitor
192
192
  read(:expect => /VAL.*END\r\n$/)
193
193
  end
194
194
 
195
- # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
195
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
196
196
  def send_one_packet(old_packet = nil)
197
197
  pf = packet_format
198
198
  raise(Errors::NotImplemented, "Unimplemented packet format: #{pf}") unless IMPLEMENTED_FORMATS.include?(pf)
@@ -219,7 +219,7 @@ module GreenEyeMonitor
219
219
  Packet::Bin32Abs.read(StringIO.new(packet), old_packet)
220
220
  end
221
221
  end
222
- # rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
222
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/MethodLength
223
223
 
224
224
  private
225
225
 
@@ -248,7 +248,6 @@ module GreenEyeMonitor
248
248
  def read(options = {})
249
249
  wait if options[:wait]
250
250
 
251
- # TODO: Make :expect an arg if w never need anything else
252
251
  if options[:expect]
253
252
  data = read_expect(options[:expect])
254
253
  elsif options[:length]
@@ -267,7 +266,17 @@ module GreenEyeMonitor
267
266
  end
268
267
 
269
268
  def wait
270
- byte = @serial.getbyte while byte.nil?
269
+ iterations = 5 * 1_000 / @serial.read_timeout
270
+
271
+ i = 0
272
+ loop do
273
+ byte = @serial.getbyte
274
+ break if byte.nil?
275
+
276
+ i += 1
277
+ raise(Errors::Timeout, 'Waited too long for data') if i > iterations
278
+ end
279
+
271
280
  @serial.ungetbyte(byte)
272
281
  end
273
282
  end
@@ -4,5 +4,6 @@ module GreenEyeMonitor
4
4
  class BadData < StandardError; end
5
5
  class TooShort < StandardError; end
6
6
  class NotImplemented < StandardError; end
7
+ class Timeout < StandardError; end
7
8
  end
8
9
  end
@@ -93,20 +93,18 @@ module GreenEyeMonitor
93
93
  end
94
94
 
95
95
  def derive_watts(prev_ws_values, curr_ws_values, prev_sec, cur_sec)
96
- if prev_sec > cur_sec
97
- sec_diff = 256^3 - prev_sec
98
- sec_diff += cur_sec
99
- else
100
- sec_diff = cur_sec - prev_sec
101
- end
96
+ sec_diff = if prev_sec > cur_sec
97
+ 256 ^ 3 - prev_sec + cur_sec
98
+ else
99
+ cur_sec - prev_sec
100
+ end
102
101
 
103
102
  prev_ws_values.zip(curr_ws_values).map do |prev_ws, curr_ws|
104
- if prev_ws > curr_ws
105
- ws_diff = 256^5 - prev_ws
106
- ws_diff += curr_ws
107
- else
108
- ws_diff = curr_ws - prev_ws
109
- end
103
+ ws_diff = if prev_ws > curr_ws
104
+ 256 ^ 5 - prev_ws + curr_ws
105
+ else
106
+ curr_ws - prev_ws
107
+ end
110
108
 
111
109
  watts = ws_diff / sec_diff
112
110
 
@@ -1,3 +1,3 @@
1
1
  module GreenEyeMonitor
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: green_eye_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ferlito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serialport