w1_temperature_parser 0.1.0.2 → 0.1.1

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: 57c3c39ef982f93f100ceddffe1d3421b7f265df
4
- data.tar.gz: 0d70b3f3e7e14f78dcff22e0987815572d237ded
3
+ metadata.gz: 17c48737fadd45fc6fd1fd645ad15f704a9617e7
4
+ data.tar.gz: 8ba9d9ac4389f10f32c05208bfaa00558128b8dd
5
5
  SHA512:
6
- metadata.gz: 2c600449a5fcd58cc501c77c6289dcce621b9d8f5e62e37d3445c7642975413e91a3e94f924dd494b5750fee3c4b9b39447e152f75c9e07d941c994a4696fc3b
7
- data.tar.gz: 36a7d24754db88edbd21b462b1d5b075e08442bdf4c54ed71d287b158e7c31b10df7f85470a4c072373877dc184aaae9da8d53078a3fa85baf89fd8566604800
6
+ metadata.gz: 4a0620efa65b94d5331e0e69e62f09cb7d86f449981c364cd7f7aeae4c5c93692f97d384dd4bfe3d7892d3fd2a112ceff8b9e736a68302c158baad75862996c8
7
+ data.tar.gz: 2ed71e89cff334de86dc580907bdec3d0e73c1dc3cfe782286ff241518c9051ac8d360f43548314c49a80e7b82a4a7ba53161c6fd751bde74113221e9ea28d57
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # W1TemperatureParser
2
2
 
3
- Some utils to ease parsing results of DS18B20 temperature sensor. Retries a defined amount of times, if the sensor returns non-temperature values like 85000(initial state) and 127687(signed int - wrong communication)
3
+ Some utils to ease parsing results of DS18B20 temperature sensor in use on the GPIO of the Raspberry PI. Retries a defined amount of times, if the sensor returns non-temperature values like 85000 (initial state) and 127687 (signed int - wrong communication). Also revert the result to fahrenheit.
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,7 +22,14 @@ Or install it yourself as:
22
22
 
23
23
  Just call the binary with the sensor virtual file:
24
24
  ```
25
- bundle exec bin/parse_temperature -i /sys/bus/w1/devices/w1_bus_master1/10-[replace-with-correct-id]/w1_slave
25
+ parse_temperature -i /sys/bus/w1/devices/w1_bus_master1/10-[replace-with-correct-id]/w1_slave
26
+ 22.762
27
+ ```
28
+
29
+ Result in fahrenheit
30
+ ```
31
+ parse_temperature -u F -i /sys/bus/w1/devices/w1_bus_master1/10-[replace-with-correct-id]/w1_slave
32
+ 73.762
26
33
  ```
27
34
 
28
35
  ## Development
@@ -1,7 +1,8 @@
1
- require 'w1_temperature_parser/opts_parser'
1
+ require "w1_temperature_parser/version"
2
2
  require 'w1_temperature_parser/cli'
3
+ require 'w1_temperature_parser/converter'
4
+ require 'w1_temperature_parser/opts_parser'
3
5
  require 'w1_temperature_parser/parser'
4
- require "w1_temperature_parser/version"
5
6
 
6
7
  module W1TemperatureParser
7
8
  end
@@ -9,10 +9,21 @@ class W1TemperatureParser::CLI
9
9
  options = W1TemperatureParser::OptsParser.parse params
10
10
 
11
11
  input_file = options.input_file
12
+
13
+ unit = options.unit || 'c'
14
+ unless ['c', 'f'].include?(unit.to_s.downcase)
15
+ puts "Unknown unit #{unit}"
16
+ end
17
+
12
18
  if !input_file.nil?
13
19
  puts "#{input_file} does not exist" if !File.exists? input_file
20
+ temperature = W1TemperatureParser::Parser.new(input_file).call
21
+
22
+ if unit.downcase == 'f'
23
+ temperature = W1TemperatureParser::Converter.new(BigDecimal(temperature.to_s)).to_fahrenheit.to_f
24
+ end
14
25
 
15
- puts W1TemperatureParser::Parser.new(input_file).call
26
+ puts temperature
16
27
  end
17
28
  end
18
29
  end
@@ -0,0 +1,17 @@
1
+ require 'bigdecimal'
2
+
3
+ module W1TemperatureParser
4
+ class Converter
5
+ attr_reader :temperature
6
+
7
+ def initialize(temperature)
8
+ @temperature = temperature
9
+ end
10
+
11
+ def to_fahrenheit
12
+ return nil if temperature.nil? || !temperature.is_a?(Numeric)
13
+
14
+ (temperature * BigDecimal('1.8')) + 32
15
+ end
16
+ end
17
+ end
@@ -11,9 +11,14 @@ module W1TemperatureParser
11
11
  result.input_file = n
12
12
  end
13
13
 
14
+ opts.on('-uUNIT', '--unitUNIT', 'Choose unit of output (standard celsius)') do |n|
15
+ result.unit = n
16
+ end
17
+
14
18
  opts.on('-h', '--help', 'Prints this help') do
15
19
  puts opts
16
20
  end
21
+
17
22
  end
18
23
 
19
24
  opt_parser.parse!(options)
@@ -21,6 +26,6 @@ module W1TemperatureParser
21
26
  end
22
27
  end
23
28
 
24
- class Options < Struct.new(:input_file)
29
+ class Options < Struct.new(:input_file, :unit)
25
30
  end
26
31
  end
@@ -1,3 +1,3 @@
1
1
  module W1TemperatureParser
2
- VERSION = '0.1.0.2'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: w1_temperature_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Noack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-21 00:00:00.000000000 Z
11
+ date: 2016-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,6 +68,7 @@ files:
68
68
  - bin/parse_temperature
69
69
  - lib/w1_temperature_parser.rb
70
70
  - lib/w1_temperature_parser/cli.rb
71
+ - lib/w1_temperature_parser/converter.rb
71
72
  - lib/w1_temperature_parser/opts_parser.rb
72
73
  - lib/w1_temperature_parser/parser.rb
73
74
  - lib/w1_temperature_parser/version.rb