phidget_rfid 0.1.0 → 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: 4bd085dc7bff0f4795a65b3b782dfb73425f836d
4
- data.tar.gz: 13a7a824e52d5cf517b1c9ca79ec9ecf83f87fc3
3
+ metadata.gz: 5f540fa42d23fb177b3bae2479ac9f6db647d572
4
+ data.tar.gz: 9d7565c710aa1af6e6158e61057ce9a6f3c77566
5
5
  SHA512:
6
- metadata.gz: bc6543af66cf7bbbca5c4d7904c637f2ce1c03e35c0062d2190789b6d5b4becf38434b7c5fea69ec1fc23f0792541cb3d30bba18d5a7d1671f6d5827278bf0a1
7
- data.tar.gz: 0a89a8eeb24ff464ec5dbae77654085f136b4bbbcb31062091d512d86cd0dfef0df1d116dc8fa722a8eb1c177c2b9be921406d936d497c2bf66da7eedff99ee8
6
+ metadata.gz: 2fabdf786486dc5fcf1df49407946a520c01c4b1db00c2d11e707af712569b032e1bfb98fef2be438b8caed70ff8d2822882287287ee08b4aac1bdab4237b889
7
+ data.tar.gz: c4c8b6ea576635b6493231ce0f8e149220695449b96ccde98f338cf67c8924b037634aee4db36de66aff87480b3dc319538d2bf416240af6a6811f52b17274ff
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/README.md CHANGED
@@ -4,12 +4,12 @@ This is a simple ruby program to work with the Phidget RFID in the console
4
4
 
5
5
  ## Installation:
6
6
 
7
- gem install phitdget_rfid
7
+ gem install phidget_rfid
8
8
 
9
9
 
10
10
  ## Usage:
11
11
  ```
12
- phitdget_rfid
12
+ phidget_rfid
13
13
  ```
14
14
 
15
15
  And then you can use the help command
@@ -27,4 +27,4 @@ RFID> help
27
27
  exit - Exit from program
28
28
  You can type "help <command>" for more info
29
29
  ------------------------------
30
- ```
30
+ ```
@@ -7,12 +7,12 @@ module PhidgetRfid
7
7
  private
8
8
  extend CLI::Task
9
9
 
10
- @rfid
10
+
11
11
 
12
12
  public
13
13
 
14
- def initialize (rfid)
15
- @rfid = rfid
14
+ def initialize (r)
15
+ @rfid_handler = r
16
16
  end
17
17
 
18
18
 
@@ -20,16 +20,25 @@ module PhidgetRfid
20
20
  desc 'Reads the value from the connected RFID tag'
21
21
 
22
22
  def read(params)
23
- puts @rfid.read
23
+ puts @rfid_handler.read
24
24
  end
25
25
 
26
26
 
27
27
 
28
28
  usage 'Usage: write "string to write" <protocol> <lock>'
29
- desc 'Writes the provided text into the RFID tag. Protocols: EM4100, ISO11785_FDX_B, PhidgetTAG, 1'
29
+ desc 'Writes the provided text into the RFID tag. Protocols: EM4100, ISO11785_FDX_B, PhidgetTAG, 1.\nHave in mind that if the TAG is blank you need to write it for the first time with the PhidgetTAG protocol'
30
+
30
31
 
31
32
  def write(params)
32
- puts @rfid.write params[0] unless params.empty?
33
+
34
+ if params.size == 1
35
+ puts @rfid_handler.write params[0]
36
+ elsif params.size == 2
37
+ puts @rfid_handler.write params[0], params[1]
38
+ elsif params.size == 3
39
+
40
+ puts @rfid_handler.write params[0], params[2], params[3]
41
+ end
33
42
  end
34
43
 
35
44
 
@@ -38,7 +47,7 @@ module PhidgetRfid
38
47
  desc 'Displays the current tag protocol'
39
48
 
40
49
  def protocol(params)
41
- puts @rfid.protocol
50
+ puts @rfid_handler.protocol
42
51
  end
43
52
 
44
53
 
@@ -54,14 +63,14 @@ module PhidgetRfid
54
63
  desc 'Displays: reader id, serial number and state, Antenna and Led state. Library API version'
55
64
 
56
65
  def device(params)
57
- puts @rfid.device
66
+ puts @rfid_handler.device
58
67
  end
59
68
 
60
69
  usage 'Usage: log'
61
70
  desc 'Shows the event log'
62
71
 
63
72
  def log(params)
64
- puts @rfid.log
73
+ puts @rfid_handler.log
65
74
  end
66
75
 
67
76
 
@@ -1,36 +1,36 @@
1
1
  module PhidgetRfid
2
2
  class RfidHandler
3
- @rfid
3
+ @phidget
4
4
  @prompt
5
5
  @time
6
6
  attr_accessor :log
7
7
 
8
8
  def initialize()
9
- @rfid = Phidgets::RFID.new
9
+ @phidget = Phidgets::RFID.new
10
10
  @time = Time.new
11
11
  @prompt = "at #{@time.strftime("%Y-%m-%d %H:%M:%S")} \033[0m"
12
12
  @log = ""
13
13
 
14
- @rfid.on_detach do |device, obj|
14
+ @phidget.on_detach do |device, obj|
15
15
  @log.append "\n#{device.attributes.inspect} removed"
16
16
  end
17
17
 
18
- @rfid.on_attach do |device, obj|
19
- @rfid.antenna = true
20
- @rfid.led = false
18
+ @phidget.on_attach do |device, obj|
19
+ @phidget.antenna = true
20
+ @phidget.led = false
21
21
  end
22
22
 
23
- @rfid.on_error do |device, obj, code, description|
23
+ @phidget.on_error do |device, obj, code, description|
24
24
  @log << "\033[31m\nError #{code}: #{description} #{@prompt}"
25
25
  end
26
26
 
27
- @rfid.on_tag do |device, tag, obj|
28
- @rfid.led = true
27
+ @phidget.on_tag do |device, tag, obj|
28
+ @phidget.led = true
29
29
  @log << "\n\033[32m[+] #{protocol} tag detected #{@prompt}"
30
30
  end
31
31
 
32
- @rfid.on_tag_lost do |device, tag, obj|
33
- @rfid.led = false
32
+ @phidget.on_tag_lost do |device, tag, obj|
33
+ @phidget.led = false
34
34
  @log << "\n\033[33m[-] #{protocol} tag removed #{@prompt}"
35
35
  end
36
36
 
@@ -38,19 +38,28 @@ module PhidgetRfid
38
38
  end
39
39
 
40
40
  def protocol
41
- if(@rfid.attached?)
42
- @rfid.last_tag_protocol
41
+ if(@phidget.attached?)
42
+ @phidget.last_tag_protocol
43
43
  end
44
44
  end
45
45
 
46
46
  def read
47
- if(@rfid.attached?)
48
- @rfid.last_tag
47
+ if(@phidget.attached?)
48
+ @phidget.last_tag
49
49
  end
50
50
  end
51
51
 
52
- def write(value, protocol = @rfid.last_tag_protocol, lock = false)
53
- if(@rfid.attached?)
52
+ def write(value, protocol = nil, lock = false)
53
+ if (protocol == nil)
54
+ protocol =
55
+ if @phidget.tag_present
56
+ @phidget.last_tag_protocol
57
+ else
58
+ "EM4100"
59
+ end
60
+ end
61
+
62
+ if(@phidget.attached?)
54
63
  p = protocol.to_sym
55
64
 
56
65
  if lock
@@ -58,19 +67,21 @@ module PhidgetRfid
58
67
  puts "Protocol: #{p}"
59
68
  puts "Are you sure you want to lock the RFID Tag? This will make it read-only (y/N)"
60
69
  r = gets.chomp
61
- @rfid.write value, p, true if r == "y"
62
-
70
+ @phidget.write(value, p, true) if r == "y"
71
+ else
72
+ @phidget.write(value, p)
63
73
  end
64
74
 
75
+
65
76
  end
66
77
  end
67
78
 
68
79
  def device
69
80
  puts "Library Version: #{Phidgets::FFI.library_version}"
70
- puts "Class: #{device.device_class}"
71
- puts "Id: #{device.id}"
72
- puts "Serial number: #{device.serial_number}"
73
- puts "# Digital Outputs: #{device.outputs.size}"
81
+ puts "Class: #{@phidget.device_class}"
82
+ puts "Id: #{@phidget.id}"
83
+ puts "Serial number: #{@phidget.serial_number}"
84
+ puts "Digital Outputs: #{@phidget.outputs.size}"
74
85
  end
75
86
 
76
87
 
@@ -1,3 +1,3 @@
1
1
  module PhidgetRfid
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phidget_rfid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Fontes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-16 00:00:00.000000000 Z
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler