tamashii-agent 0.3.4 → 0.4.0

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: 4f8a6bed3bf8f1f705b5c21447fdf9ac48d6cf03
4
- data.tar.gz: 339afb9a39fdf6f5c478d124ca0e73997fd49c93
3
+ metadata.gz: f5564313a19fba8b431b645ef8f6d158ff85f519
4
+ data.tar.gz: e23ae9334789cfac3a3deb060708a97a814c3d0a
5
5
  SHA512:
6
- metadata.gz: 7c2bbc212637f2120e34eee02ac695c8543ad6c260e4f1bf1d31df0fc432a2a00e2d5f5129d19a80f811928c3341d0c4f0e2aae9b0bf960557851e9b3ec2434e
7
- data.tar.gz: 0ba0b3399a3a811e6f4a616a23438d5f042c3a6e6ff380c168fa1e0741cf5992b9b111353cc548cda8b129cc8ea3bb2f6738724525fe720a7513e2d62eb510f8
6
+ metadata.gz: 3c9e2d6506b627b817c7edfa26940fa793f37f00c24872d9492d8accd124e278b75775c7537632f4f8425b90de6606ad82800307c99459f04d9a62040e30a060
7
+ data.tar.gz: 0e62e0649fc7009f81501585f412d1576da1d82249e41a5cce383467ab71beb8cb832e4b61e5fc5575c51ff9f44c0146d49d118e346961db500daada11f2900d
@@ -1,3 +1,5 @@
1
+ require 'tamashii/config'
2
+
1
3
  require "tamashii/agent/version"
2
4
  require "tamashii/agent/master"
3
5
  require "tamashii/agent/config"
@@ -6,7 +8,7 @@ require "tamashii/agent/config"
6
8
  module Tamashii
7
9
  module Agent
8
10
  def self.config(&block)
9
- return Config.class_eval(&block) if block_given?
11
+ return instance_exec(Config.instance, &block) if block_given?
10
12
  Config
11
13
  end
12
14
 
@@ -15,3 +17,7 @@ module Tamashii
15
17
  end
16
18
  end
17
19
  end
20
+
21
+ Tamashii::Hook.after(:config) do |config|
22
+ config.register(:agent, Tamashii::Agent.config)
23
+ end
@@ -2,15 +2,37 @@ require 'tamashii/common'
2
2
  require 'tamashii/client'
3
3
  module Tamashii
4
4
  module Agent
5
- class Config < Tamashii::Config
5
+ class Config
6
+ class << self
7
+ def instance
8
+ @instance ||= Config.new
9
+ end
10
+
11
+ def respond_to_missing?(name, _all = false)
12
+ super
13
+ end
14
+
15
+ def method_missing(name, *args, &block)
16
+ # rubocop:disable Metrics/LineLength
17
+ return instance.send(name, *args, &block) if instance.respond_to?(name)
18
+ # rubocop:enable Metrics/LineLength
19
+ super
20
+ end
21
+ end
22
+
23
+ include Tamashii::Configurable
24
+
6
25
  AUTH_TYPES = [:none, :token]
7
26
 
8
- register :default_components, {networking: {class_name: :Networking, options: {}}}
9
- register :connection_timeout, 3
27
+ config :default_components, default: {networking: {class_name: :Networking, options: {}}}
28
+ config :connection_timeout, default: 3
29
+
30
+ config :env, deafult: nil
31
+ config :token
10
32
 
11
- register :localtime, "+08:00"
33
+ config :localtime, default: "+08:00"
12
34
 
13
- register :lcd_animation_delay, 1
35
+ config :lcd_animation_delay, default: 1
14
36
 
15
37
 
16
38
  def auth_type(type = nil)
@@ -27,7 +49,7 @@ module Tamashii
27
49
 
28
50
  def log_file(value = nil)
29
51
  return @log_file ||= STDOUT if value.nil?
30
- Client.config.log_file(value)
52
+ Client.config.log_file = value
31
53
  @log_file = value
32
54
  end
33
55
 
@@ -38,7 +60,7 @@ module Tamashii
38
60
  end
39
61
 
40
62
  def add_component(name, class_name, options = {}, &block)
41
- self.components[name] = {class_name: class_name, options: options, block: block}
63
+ self.components[name] = {class_name: class_name, options: options, block: block}
42
64
  end
43
65
 
44
66
  def remove_component(name)
@@ -48,6 +70,11 @@ module Tamashii
48
70
  def components
49
71
  @components ||= self.default_components.clone
50
72
  end
73
+
74
+ def env(env = nil)
75
+ return Tamashii::Environment.new(self[:env]) if env.nil?
76
+ self.env = env.to_s
77
+ end
51
78
  end
52
79
  end
53
80
  end
@@ -8,44 +8,50 @@ Following figure shows a typical Raspberry PI and pins on it.
8
8
 
9
9
  ## Buzzers
10
10
 
11
- ### PWM buzzer
11
+ ### SFM-27-W buzzer via PWM
12
12
 
13
13
  ![PWM Buzzer](https://tamashii.io/images/devices/pwm_buzzer.jpg)
14
14
 
15
15
  - Connect positive wire (the red one) to the PWM GPIO pin
16
16
  - Example in figure: pin 35 (GPIO 19)
17
- - The **GPIO number** (not the pin number) should be specify in the configuration
18
- ```ruby
19
- add_component :buzzer, 'Buzzer', device: 'PwmBuzzer', pin: 19
20
- ```
17
+ - The **GPIO number** (not the pin number) should be specify in the configuration using `pin`
21
18
  - Connect the negative wire (the black one) to the GND pin
22
19
  - Example in figure: pin 34 (GND)
20
+ - Add following line to your Tamashii Agent configuration file:
21
+ ```ruby
22
+ add_component :buzzer, 'Buzzer', device: 'PwmBuzzer', pin: 19
23
+ ```
24
+ - Restart Tamashii Agent
23
25
 
24
26
  ## Card Readers
25
27
 
26
28
  ### MFRC522 via SPI
27
29
 
28
30
  ![MFRC522 SPI](https://tamashii.io/images/devices/mfrc522_spi.jpg)
31
+ - Make sure your MFRC522 is configured to use SPI interface
29
32
  - Connect corresponding pins from reader module to Raspberry PI
30
33
  - reader NSS to pin 24 (SPI0 CS0)
31
34
  - reader SCK to pin 23 (SPI0 SCLK)
32
35
  - reader MOSI to pin 19 (MOSI)
33
36
  - reader MISO to pin 21 (MISO)
34
- - reader GND to pin 20 (GND)
37
+ - reader GND to any GND pin (pin 20 for example)
35
38
  - reader RST522 to pin 18 (GPIO 24)
36
39
  - The RESET pin
37
- - Could be changed in configuration
38
- ```ruby
39
- add_component :card_reader_mfrc, 'CardReader', device: 'Mfrc522Spi', reset_pin: 24
40
- ```
41
- - reader VIN to pin 4(5V PWR)
40
+ - Could be changed in configuration using `reset_pin`
41
+ - reader VIN to any 5V PWR pin (pin 4 for example)
42
+ - Add following line to your Tamashii Agent configuration file:
43
+ ```ruby
44
+ add_component :card_reader_mfrc, 'CardReader', device: 'Mfrc522Spi', reset_pin: 24
45
+ ```
46
+ - Restart Tamashii Agent
42
47
 
43
48
  ### PN532 via UART
44
49
 
45
50
  ![PN532 UART](https://tamashii.io/images/devices/pn532_uart.jpg)
51
+ - Make sure your PN532 is configured to use UART (or HSU, High Speed UART) interface
46
52
  - Connect corresponding pins from reader module to Raspberry PI
47
- - reader GND to pin 6 (GND)
48
- - reader VIN to pin 1 (3.3V PWR)
53
+ - reader GND to any GND pin (pin 6 for example)
54
+ - reader VIN to any 3.3V PWR pin (pin 1 for example)
49
55
  - reader **TX** to pin 10 (UART0 **RX**)
50
56
  - reader **RX** to pin 8 (UART0 **TX**)
51
57
  - On Raspberry 3 (Jessie), the Bluetooth module occupied the UART interface `/dev/ttyAMA0`. Before you using PN532 via UART, you need to disable Bluetooth first.
@@ -83,19 +89,110 @@ Following figure shows a typical Raspberry PI and pins on it.
83
89
 
84
90
  - Remove `console=serial0` from `/boot/cmdline.txt`, if any.
85
91
  - Reboot
86
-
92
+ - Check whether your PN532 works by using `nfc-list`
93
+ - Add following line to your Tamashii Agent configuration file:
94
+ ```ruby
95
+ add_component :card_reader_felica_uart, 'CardReader', device: 'Pn532Uart', path: "/dev/ttyAMA0"
96
+ ```
97
+ - Restart Tamashii Agent
98
+
99
+
100
+ #### PN532 via UART to USB adapter
101
+
102
+ ![UART to USB](https://tamashii.io/images/devices/uart_to_usb_adapter.jpg)
103
+
104
+
105
+ If you have the UART to USB adapter in this case, the setup is much simpler. You don't need to disable Bluetooth described in the previous section. Instead, after setup serial via `rasp-config` and install `libnfc`, you have to do the following step:
106
+
107
+ - Attach yout PN532 to the UART-to-USB adapter
108
+ - reader GND to USB GND
109
+ - reader VCC to USB 5V
110
+ - reader **TX** to USB **RXD**
111
+ - reader **RX** to USB **TXD**
112
+ - Plug it into the USB port on your Raspberry PI.
113
+ - Find out the USB device name of your PN532. If it is the only USB device on your Raspberry PI, it should be `/dev/ttyUSB0`. You can find more information by executing command `dmesg`
114
+ - Create or modify `libnfc` configuration file. Modify or create one of the following files (assume your device is at `/dev/ttyUSB0`. Modify it to match your need):
115
+ - `/etc/nfc/libnfc.conf`
116
+ ```
117
+ device.name = "PN532 board via USB"
118
+ device.connstring = "pn532_uart:/dev/ttyUSB0"
119
+ ```
120
+
121
+ - or `/etc/nfc/devices.d/pn53x_usb.conf`
122
+ ```
123
+ name = "PN532 board via USB
124
+ connstring = pn532_uart:/dev/ttyUSB0
125
+ ```
126
+ - Reboot
127
+ - Check whether your PN532 works by using `nfc-list`
128
+ - Add following line to your Tamashii Agent configuration file:
129
+ ```ruby
130
+ add_component :card_reader_felica_usb, 'CardReader', device: 'Pn532Uart', path: "/dev/ttyUSB0"
131
+ ```
132
+ - Restart Tamashii Agent
133
+
134
+
135
+ ## Keyboards
136
+
137
+ ### 8/16-Way TTP229 Capacitive Touch Sensor via GPIO
138
+
139
+ ![TTP 229](https://tamashii.io/images/devices/ttp229_gpio.jpg)
140
+
141
+ > Note: the 16-key functionality in 16-way TTP229 is disabled by default. You need to attach a jumper wire between P1/3 and P1/6 like following figure:
142
+ ![TTP229 connection](https://raw.githubusercontent.com/tamashii-io/tamashii-io.github.io/master/images/devices/TTP229_connection.png)
143
+
144
+ - Connect corresponding pins from TTP229 module to Raspberry PI:
145
+ - TTP229 VCC to any 3.3V PWR pin (pin 1 for example)
146
+ - TTP229 GND to any GND pin (pin 14 for example)
147
+ - TTP229 SCL to pin 11 (GPIO 17)
148
+ - TTP229 SDO to pin 7 (GPIO 4)
149
+ - Add following line to your Tamashii Agent configuration file. Change the `number_of_keys` to match your need.
150
+ ```ruby
151
+ add_component :kb_touch, 'KeyboardLogger', device: 'TTP229Serial', number_of_keys: 16
152
+ ```
153
+ - Restart Tamashii Agent
154
+
155
+
156
+
157
+ ### 4x4 Button Matrix via GPIO (8 pins)
158
+
159
+ ![Button Matrix 4x4](https://tamashii.io/images/devices/button_matrix_4x4.jpg)
160
+
161
+ - The button matrix requires 8 arbitrary GPIO pins on your device. 4 pins for generating **row output** from PI to button matrix and 4 pins for receiving **column input** from button matrix.
162
+ - Choose 4 GPIO pins for row output (assume GPIO 21, 20, 16, 12 for row 0 to row 3). Connect these pins from PI to button matrix **in order**.
163
+ - GPIO 21 (pin 40) to the 1st pin on matrix
164
+ - GPIO 20 (pin 38) to the 2nd pin on matrix
165
+ - GPIO 16 (pin 36) to the 3rd pin on matrix
166
+ - GPIO 12 (pin 42) to the 4th pin on matrix
167
+ - Choose 4 GPIO pins for column input (assume GPIO 26, 19, 13, 6 for column 0 to column 3). Connect these pins from PI to button matrix **in order**.
168
+ - GPIO 26 (pin 37) to the 5th pin on matrix
169
+ - GPIO 19 (pin 35) to the 6th pin on matrix
170
+ - GPIO 13 (pin 33) to the 7th pin on matrix
171
+ - GPIO 6 (pin 31) to the 8th pin on matrix
172
+ - Add following line to your Tamashii Agent configuration file:
173
+ ```ruby
174
+ add_component :kb_button, 'KeyboardLogger', device: 'ButtonMatrix4x4', row_pins: [21, 20, 16, 12], col_pins: [26, 19, 13, 6]
175
+ ```
176
+ - Restart Tamashii Agent
177
+
87
178
 
88
179
  ## LCDs
89
180
 
90
- ## LCM 1602 via I2C
181
+ ### LCM 1602 via I2C
91
182
 
92
183
  ![LCM602 I2C](https://tamashii.io/images/devices/lcm1602_i2c.jpg)
93
184
 
185
+ - Make sure your LCM 1602 has bundled with the I2C adapter
94
186
  - Connect corresponding pins from lcd module to Raspberry PI
95
- - lcd GND to pin 9 (GND)
96
- - lcd VCC to pin 2 (5V PWR)
187
+ - lcd GND to any GND pin (pin 9 for example)
188
+ - lcd VCC to any 5V PWR pin (pin 2 for example)
97
189
  - lcd SDA to pin 3 (SDA)
98
190
  - lcd SCL to pin 5 (SCL)
99
191
  - Enable I2C interface on your Raspberry PI
100
- - Using `rasp-config` => `Interfacing Options` => `I2C`
101
- - If successful, you should able to see `/dev/i2c-1` under `/dev` on Raspberry PI
192
+ - Using `rasp-config` => `Interfacing Options` => `I2C`, then reboot
193
+ - If successful, you should able to see `/dev/i2c-1` under `/dev` on Raspberry PI.
194
+ - Add following line to your Tamashii Agent configuration file:
195
+ ```ruby
196
+ add_component :lcd, 'Lcd', device: 'Lcm1602I2c'
197
+ ```
198
+ - Restart Tamashii Agent
@@ -1,5 +1,5 @@
1
1
  module Tamashii
2
2
  module Agent
3
- VERSION = "0.3.4"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -39,8 +39,10 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "pry"
40
40
 
41
41
 
42
- spec.add_runtime_dependency "tamashii-common", ">=0.1.6"
43
- spec.add_runtime_dependency "tamashii-client", ">=0.1.2"
42
+ spec.add_runtime_dependency "tamashii-common", ">=0.2"
43
+ spec.add_runtime_dependency "tamashii-client", ">=0.2"
44
+ spec.add_runtime_dependency "tamashii-config"
45
+ spec.add_runtime_dependency "tamashii-hookable"
44
46
  spec.add_runtime_dependency "websocket-driver"
45
47
  spec.add_runtime_dependency "nio4r"
46
48
  spec.add_runtime_dependency "pi_piper"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tamashii-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-09-14 00:00:00.000000000 Z
13
+ date: 2017-11-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -130,28 +130,56 @@ dependencies:
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 0.1.6
133
+ version: '0.2'
134
134
  type: :runtime
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: 0.1.6
140
+ version: '0.2'
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: tamashii-client
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - ">="
146
146
  - !ruby/object:Gem::Version
147
- version: 0.1.2
147
+ version: '0.2'
148
148
  type: :runtime
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - ">="
153
153
  - !ruby/object:Gem::Version
154
- version: 0.1.2
154
+ version: '0.2'
155
+ - !ruby/object:Gem::Dependency
156
+ name: tamashii-config
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :runtime
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ - !ruby/object:Gem::Dependency
170
+ name: tamashii-hookable
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :runtime
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
155
183
  - !ruby/object:Gem::Dependency
156
184
  name: websocket-driver
157
185
  requirement: !ruby/object:Gem::Requirement
@@ -341,7 +369,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
341
369
  version: '0'
342
370
  requirements: []
343
371
  rubyforge_project:
344
- rubygems_version: 2.5.1
372
+ rubygems_version: 2.6.11
345
373
  signing_key:
346
374
  specification_version: 4
347
375
  summary: The agent module for RubyConfTW checkin system.