pebblewatch 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -5
- data/lib/pebble.rb +19 -0
- data/lib/pebble/protocol.rb +6 -8
- data/lib/pebble/version.rb +1 -1
- data/lib/pebble/watch.rb +25 -8
- data/lib/pebble/watch/event.rb +3 -1
- metadata +9 -9
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# pebblewatch
|
2
2
|
|
3
3
|
A Ruby library for communicating with your Pebble smartwatch.
|
4
4
|
|
@@ -21,7 +21,7 @@ gem install pebblewatch
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
Make sure your Pebble is paired
|
24
|
+
Make sure your Pebble is paired with your computer and set up as a serial port. We're going to need the path or index of the port, which in the case of OS X looks like `/dev/tty.Pebble7F30-SerialPortSe` for Pebble ID `7F30`.
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
require "pebble"
|
@@ -56,11 +56,11 @@ handler = watch.on_event(:media_control) do |event|
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
# Suddenly
|
59
|
+
# Suddenly had a change of heart? Just cover your ears.
|
60
60
|
watch.stop_listening(:media_control, handler)
|
61
61
|
|
62
62
|
# To make sure we don't miss any events, we haven't connected yet.
|
63
|
-
#
|
63
|
+
# Because we also want to *send* stuff to the watch, we will now.
|
64
64
|
watch.connect
|
65
65
|
|
66
66
|
|
@@ -116,8 +116,18 @@ watch.listen_for_events
|
|
116
116
|
watch.disconnect
|
117
117
|
```
|
118
118
|
|
119
|
+
Oh, and if you want to do some lower level stuff, have a look at [`Pebble::Protocol`](lib/pebble/protocol.rb) which you can access through `watch.protocol`.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
watch.protocol.on_receive(endpoint) do |message|
|
123
|
+
# Do whatever
|
124
|
+
end
|
125
|
+
|
126
|
+
watch.protocol.send_message(endpoint, message)
|
127
|
+
```
|
128
|
+
|
119
129
|
## Examples
|
120
|
-
Check out the `examples/` folder for two examples that I actually use myself. They're kind of similar, but should give you an idea of how this whole thing works.
|
130
|
+
Check out the [`examples/`](examples) folder for two examples that I actually use myself. They're kind of similar, but should give you an idea of how this whole thing works.
|
121
131
|
|
122
132
|
## License
|
123
133
|
Copyright (c) 2013 Douwe Maan
|
data/lib/pebble.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
module Pebble
|
4
|
+
def self.logger=(new_logger)
|
5
|
+
@@logger = new_logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.logger
|
9
|
+
return @@logger if defined?(@@logger)
|
10
|
+
@@logger = default_logger
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.default_logger
|
14
|
+
logger = Logger.new(STDOUT)
|
15
|
+
logger.level = Logger::INFO
|
16
|
+
logger
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
1
20
|
require "pebble/version"
|
2
21
|
require "pebble/endpoints"
|
3
22
|
require "pebble/capabilities"
|
data/lib/pebble/protocol.rb
CHANGED
@@ -32,13 +32,11 @@ module Pebble
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def connect
|
35
|
-
puts "Connecting with port #{@port}"
|
36
|
-
|
37
35
|
@serial_port = SerialPort.new(@port, baudrate: 115200)
|
38
36
|
@serial_port.read_timeout = 500
|
39
37
|
|
40
38
|
@connected = true
|
41
|
-
|
39
|
+
Pebble.logger.debug "Connected to port #{@port}"
|
42
40
|
|
43
41
|
@receive_messages_thread = Thread.new(&method(:receive_messages))
|
44
42
|
|
@@ -79,7 +77,7 @@ module Pebble
|
|
79
77
|
|
80
78
|
message ||= ""
|
81
79
|
|
82
|
-
|
80
|
+
Pebble.logger.debug "Sending #{Endpoints.for_code(endpoint)}: #{message.inspect}"
|
83
81
|
|
84
82
|
data = [message.size, endpoint].pack("S>S>") + message
|
85
83
|
|
@@ -119,7 +117,7 @@ module Pebble
|
|
119
117
|
|
120
118
|
private
|
121
119
|
def receive_messages
|
122
|
-
|
120
|
+
Pebble.logger.debug "Waiting for messages"
|
123
121
|
while @connected
|
124
122
|
header = @serial_port.read(4)
|
125
123
|
next unless header
|
@@ -129,18 +127,18 @@ module Pebble
|
|
129
127
|
size, endpoint = header.unpack("S>S>")
|
130
128
|
message = @serial_port.read(size)
|
131
129
|
|
132
|
-
|
130
|
+
Pebble.logger.debug "Received #{Endpoints.for_code(endpoint)}: #{message.inspect}"
|
133
131
|
|
134
132
|
trigger_received(endpoint, message)
|
135
133
|
end
|
136
134
|
rescue IOError => e
|
137
135
|
if @connected
|
138
|
-
|
136
|
+
Pebble.logger.debug "Lost connection"
|
139
137
|
@connected = false
|
140
138
|
raise Errors::LostConnection
|
141
139
|
end
|
142
140
|
ensure
|
143
|
-
|
141
|
+
Pebble.logger.debug "Finished waiting for messages"
|
144
142
|
end
|
145
143
|
|
146
144
|
def trigger_received(endpoint, message)
|
data/lib/pebble/version.rb
CHANGED
data/lib/pebble/watch.rb
CHANGED
@@ -9,14 +9,14 @@ module Pebble
|
|
9
9
|
def self.autodetect
|
10
10
|
return nil unless RUBY_PLATFORM =~ /darwin/
|
11
11
|
|
12
|
-
|
12
|
+
watches = Dir.glob("/dev/tty.Pebble????-SerialPortSe")
|
13
13
|
|
14
|
-
raise NoWatchesFound if
|
15
|
-
|
14
|
+
raise Errors::NoWatchesFound if watches.length == 0
|
15
|
+
Pebble.logger.debug "Found multiple watches: #{watches}" if watches.length > 1
|
16
16
|
|
17
|
-
port =
|
17
|
+
port = watches.first
|
18
18
|
id = port[15, 4]
|
19
|
-
|
19
|
+
Pebble.logger.debug "Detected watch with ID #{id}"
|
20
20
|
|
21
21
|
return new(id, port)
|
22
22
|
end
|
@@ -50,8 +50,8 @@ module Pebble
|
|
50
50
|
@client_capabilities = Capabilities::Client::TELEPHONY | Capabilities::Client::SMS | Capabilities::Client::ANDROID
|
51
51
|
|
52
52
|
answer_phone_version_message
|
53
|
-
|
54
53
|
receive_event_messages
|
54
|
+
log_log_events
|
55
55
|
end
|
56
56
|
|
57
57
|
def connect
|
@@ -177,7 +177,7 @@ module Pebble
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def system_message(code)
|
180
|
-
|
180
|
+
Pebble.logger.debug "Sending system message #{SystemMessages.for_code(code)}"
|
181
181
|
|
182
182
|
message = [code].pack("S>")
|
183
183
|
|
@@ -213,8 +213,25 @@ module Pebble
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
+
def log_log_events
|
217
|
+
on_event(:log) do |event|
|
218
|
+
case event.level
|
219
|
+
when :error
|
220
|
+
Pebble.logger.error event.message
|
221
|
+
when :warning
|
222
|
+
Pebble.logger.warn event.message
|
223
|
+
when :info
|
224
|
+
Pebble.logger.info event.message
|
225
|
+
when :debug, :verbose
|
226
|
+
Pebble.logger.debug event.message
|
227
|
+
else
|
228
|
+
Pebble.logger.info event.message
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
216
233
|
def trigger_event(name, event)
|
217
|
-
|
234
|
+
Pebble.logger.debug "Triggering event '#{name}': #{event.inspect}"
|
218
235
|
|
219
236
|
@event_handlers[:any].each do |handler|
|
220
237
|
Thread.new(handler) do |handler|
|
data/lib/pebble/watch/event.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pebblewatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-04-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: serialport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70177874616340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70177874616340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70177874615460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70177874615460
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70177874613320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70177874613320
|
47
47
|
description: A Ruby library for communicating with your Pebble smartwatch.
|
48
48
|
email: douwe@selenight.nl
|
49
49
|
executables: []
|
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
segments:
|
83
83
|
- 0
|
84
|
-
hash:
|
84
|
+
hash: -467314085737445579
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
segments:
|
92
92
|
- 0
|
93
|
-
hash:
|
93
|
+
hash: -467314085737445579
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
96
|
rubygems_version: 1.8.6
|