oschii_ruby 0.0.7 → 0.1.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
  SHA256:
3
- metadata.gz: e586910b9a9400a050fffb6649400b2ee5aa2026ed8bbfefc14cc8784b77fb74
4
- data.tar.gz: 3ea15b15df01618c3c8904254b1bb907dc2b3589ac685aa7445ec2558791ff2d
3
+ metadata.gz: ca8dbfc96521d361bcc916a2ef41700fc4bd587dfadd0588d060c6363d4cd20e
4
+ data.tar.gz: 76c261c49d53bce164dcaadd6135e0daf846178c23853d4a612e114f519be118
5
5
  SHA512:
6
- metadata.gz: fbe3a7446e3c57d7a9491eaa68f9c0b41d5f32aa5cbdbc7f49adcee49bdde651afc38ee817da794fc295aa41750e72217bfa35eb5f2dd776223d848a31a62a57
7
- data.tar.gz: 5153a84b8c8fb06bd955ff037a92995e0bbaa75f223a7dae676dfbafa6d6c3daadefdb2497ea1b535341d036ea1e9c7e765a639d0a5529e6c402ce402ed72fdf
6
+ metadata.gz: 421170576e181972700e2e630e5ffde3ca70e8503ea8b559cb0b4371b979647a89d2db1a3529b316510750e989470e81149ab76dd5b5d81b5bb85b86acc62d54
7
+ data.tar.gz: 9f28f28926d18a20d63720292ed31fbfdbf25854213744d651c0ac93ed03ab231833d61683f2119596ad07381cbaa499da22ea3cf8ed1e9a78da24312cfa35f6
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ruby '2.7.7'
3
+ ruby '>= 2.7.7'
4
4
 
5
5
  source 'http://rubygems.org'
6
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oschii_ruby (0.0.7)
4
+ oschii_ruby (0.1.0)
5
5
  activesupport (~> 7.1.2)
6
6
  faye-websocket (~> 0.11.3)
7
7
  osc-ruby (~> 1.1.4)
@@ -41,9 +41,9 @@ GEM
41
41
  domain_name (~> 0.5)
42
42
  i18n (1.14.1)
43
43
  concurrent-ruby (~> 1.0)
44
- make_menu (0.0.3)
44
+ make_menu (1.0.0)
45
45
  tty-screen (~> 0.8.2)
46
- mime-types (3.5.1)
46
+ mime-types (3.5.2)
47
47
  mime-types-data (~> 3.2015)
48
48
  mime-types-data (3.2023.1205)
49
49
  minitest (5.20.0)
data/lib/oschii/cloud.rb CHANGED
@@ -13,14 +13,19 @@ module Oschii
13
13
  RESPONSE_ADDR = '/i_am_oschii'
14
14
  HTTP_PORT = 8000
15
15
 
16
- def initialize(silent: false)
16
+ def initialize(http: false, silent: false)
17
17
  @osc_server = OSC::EMServer.new(RESPONSE_PORT)
18
- @http_server = WEBrick::HTTPServer.new(Port: HTTP_PORT)
18
+ if http
19
+ @http_server = WEBrick::HTTPServer.new(
20
+ Port: HTTP_PORT,
21
+ Logger: WEBrick::Log.new('/dev/null', WEBrick::Log::FATAL)
22
+ )
23
+ end
19
24
 
20
25
  @devices = {}
21
26
  @silent = silent
22
27
 
23
- start_listening
28
+ start_listening http: http
24
29
  end
25
30
 
26
31
  attr_reader :osc_server, :http_server, :devices, :silent
@@ -30,8 +35,9 @@ module Oschii
30
35
 
31
36
  puts "\n~~> Scanning Serial Ports...."
32
37
 
33
- 9.times do |i|
34
- port = "/dev/ttyUSB#{i}"
38
+ Dir.glob('/dev/cu.usbserial*') do |port|
39
+ # 9.times do |i|
40
+ # port = "/dev/ttyUSB#{i}"
35
41
  print "\n~~> #{port}: "
36
42
  begin
37
43
  node = ::Oschii::SerialDevice.new(port)
@@ -53,7 +59,7 @@ module Oschii
53
59
  self
54
60
  end
55
61
 
56
- def start_listening
62
+ def start_listening(http: false)
57
63
  osc_server.add_method RESPONSE_ADDR do |message|
58
64
  payload = message.to_a.first
59
65
  begin
@@ -82,19 +88,24 @@ module Oschii
82
88
  end
83
89
 
84
90
  Thread.new do
85
- puts "~~> Starting OSC Server on port #{RESPONSE_PORT}" unless silent
91
+ puts "~~> Starting OSC Server on #{base_ip}:#{RESPONSE_PORT}" unless silent
86
92
  osc_server.run
87
93
  end
88
94
 
89
- trap 'INT' do http_server.shutdown end
90
-
91
- Thread.new do
92
- puts "~~> Starting HTTP Server on port #{HTTP_PORT}" unless silent
93
- http_server.start
95
+ trap 'INT' do
96
+ http_server.shutdown
97
+ exit
94
98
  end
95
99
 
96
- http_server.mount '/api/devices', GetDevices, self
97
- http_server.mount '/api/refresh', RefreshCloud, self
100
+ if http
101
+ Thread.new do
102
+ puts "~~> Starting HTTP Server on #{base_ip}:#{HTTP_PORT}" unless silent
103
+ http_server.start
104
+ end
105
+
106
+ http_server.mount '/api/devices', GetDevices, self
107
+ http_server.mount '/api/refresh', RefreshCloud, self
108
+ end
98
109
  end
99
110
 
100
111
  def wait_for(oschii_name, timeout: 300)
@@ -156,12 +167,10 @@ module Oschii
156
167
  def base_ip
157
168
  return @base_ip if @base_ip
158
169
 
159
- ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
170
+ ip = Socket.ip_address_list.detect { |intf| intf.ipv4_private? }
160
171
 
161
172
  addr = ip.ip_address.to_s
162
173
 
163
- puts "Local IP: #{addr}"
164
-
165
174
  @base_ip = addr.split('.')[0..-2].join('.')
166
175
 
167
176
  # if File.exists? BASE_IP_FILE
@@ -277,10 +286,10 @@ module Oschii
277
286
 
278
287
  def saved_devices
279
288
  @saved_devices ||= if File.exists? '.saved_devices'
280
- File.read('.saved_devices').split("\n")
281
- else
282
- []
283
- end
289
+ File.read('.saved_devices').split("\n")
290
+ else
291
+ []
292
+ end
284
293
  end
285
294
 
286
295
  def save_device(ip)
@@ -34,7 +34,8 @@ module Oschii
34
34
  target_refs = [target_refs] if target_refs.is_a?(String)
35
35
  @targets += target_refs
36
36
  end
37
- @targets.map { |ref| ref.split('/').first }.uniq
37
+
38
+ @targets = @targets.map { |ref| ref.split('/').first }.uniq
38
39
  end
39
40
 
40
41
  def to_s
data/lib/oschii/config.rb CHANGED
@@ -3,11 +3,6 @@ require_relative 'template'
3
3
  require 'json'
4
4
 
5
5
  module Oschii
6
- # LOGO = '
7
- # ╔═╗┌─┐┌─┐┬ ┬┬┬
8
- # ║ ║└─┐│ ├─┤││
9
- # ╚═╝└─┘└─┘┴ ┴┴┴'
10
-
11
6
  COMPONENT_TYPES = %w(Sensor Driver Reporter Listener Monitor State Timer Pixel I2C).freeze
12
7
  I2C = 'I2C'.freeze
13
8
  BASIC_COMPONENT_TYPES = COMPONENT_TYPES.reject { |t| t == I2C }.freeze
@@ -117,7 +112,6 @@ module Oschii
117
112
  next unless components[target_ref].nil?
118
113
 
119
114
  type, name = target_ref.split(':')
120
- puts name
121
115
  name = name.split('/').first
122
116
  unless name.start_with?('*')
123
117
  new_comp = Component.new(type, { 'name' => name, 'warning' => 'Auto-created by Oschii Parser' })
@@ -0,0 +1,38 @@
1
+ module Oschii
2
+ module ConfigFile
3
+ def upload_config(filename = nil, silent: false)
4
+ if filename.nil?
5
+ filenames = Dir.glob("configs/#{name}_*.json")
6
+ if filenames.empty?
7
+ puts 'No previous config' unless silent
8
+ return
9
+ end
10
+ filename = filenames.sort.last
11
+
12
+ unless silent
13
+ display_name = filename.split('/')[-1]
14
+ .split('_')[-1]
15
+ .split('+')[0]
16
+ .gsub('T', ' ')
17
+ .gsub('.json', '')
18
+ puts "Latest: #{display_name}"
19
+ begin
20
+ prompt '>> [ENTER] to upload, [ESC] to cancel <<'
21
+ rescue CancelSerialQuery
22
+ return
23
+ end
24
+ end
25
+ end
26
+
27
+ self.config = JSON.parse File.read(filename)
28
+
29
+ self
30
+ end
31
+
32
+ def save_config(filename = nil, silent: false)
33
+ filename ||= "configs/#{name}_#{Time.now.iso8601}.json"
34
+ File.write filename, JSON.pretty_generate(config)
35
+ puts "Saved #{filename.split('/')[-1]}" unless silent
36
+ end
37
+ end
38
+ end
data/lib/oschii/device.rb CHANGED
@@ -1,17 +1,29 @@
1
+ require 'byebug'
2
+ require 'eventmachine'
3
+ require 'faye/websocket'
4
+ require 'io/console'
5
+ require 'json'
1
6
  require 'restclient'
2
7
  require 'rubyserial'
3
- require 'json'
4
- require 'io/console'
5
- require 'faye/websocket'
6
- require 'eventmachine'
7
- require 'byebug'
8
8
 
9
9
  require_relative 'config'
10
+ require_relative 'device_monitor'
11
+
12
+ # mixins
13
+ require_relative 'config_file'
14
+ require_relative 'logging'
15
+ require_relative 'helpers/prompt'
16
+
10
17
  module Oschii
18
+
11
19
  DeviceUnavailable = Class.new(StandardError)
12
20
  NoConnection = Class.new(StandardError)
13
21
 
14
22
  class Device
23
+ include ConfigFile
24
+ include Logging
25
+ include Helpers::Prompt
26
+
15
27
  def initialize
16
28
  @log_lines = []
17
29
  refresh
@@ -19,60 +31,15 @@ module Oschii
19
31
 
20
32
  attr_reader :log_lines
21
33
 
22
- def restart
23
- raise NoConnection
24
- end
25
-
26
- # Connection
27
-
28
- def refresh
29
- @device_details = nil
30
- @status = nil
31
- @settings = nil
32
- @config = nil
33
- poke!
34
- end
35
-
36
- def ip
37
- raise NoConnection
38
- end
39
-
40
- def poke
41
- raise NoConnection
34
+ def inspect
35
+ "<#{self.class.name}[#{name}] (v#{version})>"
42
36
  end
43
37
 
44
- def poke!
45
- remaining_attempts = 3
46
- while remaining_attempts > 0
47
- begin
48
- if poke
49
- # device_details
50
- return true
51
- end
52
- return false
53
-
54
- rescue RubySerial::Error => e
55
- raise DeviceUnavailable, case e.message
56
- when 'ENOENT'
57
- '(no device)'
58
- when 'EBUSY'
59
- '(port in use)'
60
- else
61
- e.message
62
- end
63
- rescue RestClient::Exception => e
64
- raise DeviceUnavailable, e.message
65
- end
66
- remaining_attempts -= 1
67
- end
68
- raise DeviceUnavailable, '(no response)'
38
+ def monitor
39
+ DeviceMonitor.new(self).start
69
40
  end
70
41
 
71
- # Device details
72
-
73
- def raw_device_details
74
- raise NoConnection
75
- end
42
+ # --- Device details ---
76
43
 
77
44
  def device_details
78
45
  @device_details ||= JSON.parse(raw_device_details)
@@ -95,193 +62,158 @@ module Oschii
95
62
  device_details['description']
96
63
  end
97
64
 
98
- def config_name
99
- device_details['configName']
65
+ # --- Status ---
66
+
67
+ def status
68
+ @status ||= JSON.parse(raw_status)
100
69
  end
101
70
 
102
- def config_description
103
- device_details['configDescription']
71
+ def uptime
72
+ status['uptime']
104
73
  end
105
74
 
106
- # Status
75
+ def total_mem
76
+ status['totalHeap']
77
+ end
107
78
 
108
- def raw_status
109
- raise NoConnection
79
+ def mem_used
80
+ total_mem - status['freeHeap']
110
81
  end
111
82
 
112
- def status
113
- @status ||= JSON.parse(raw_status)
83
+ def mem_used_percent
84
+ ((mem_used.to_f / total_mem.to_f) * 100.0).to_i
114
85
  end
115
86
 
116
- def uptime
117
- status['uptime']
87
+ def total_files
88
+ status['totalSPIFFS']
118
89
  end
119
90
 
120
- # Settings
91
+ def files_used
92
+ total_files - status['freeSPIFFS']
93
+ end
121
94
 
122
- def raw_settings
123
- raise NoConnection
95
+ def files_used_percent
96
+ ((files_used.to_f / total_files.to_f) * 100.0).to_i
124
97
  end
125
98
 
126
- def settings=(new_settings)
127
- raise NoConnection
99
+ def cycle_time_micros
100
+ status['cycleTime']
128
101
  end
129
102
 
103
+ # --- Settings ---
104
+
130
105
  def settings
131
106
  @settings ||= JSON.parse(raw_settings)
132
107
  end
133
108
 
134
- # Configuration
109
+ # --- Configuration ---
135
110
 
136
- def raw_config
137
- raise NoConnection
111
+ def config_name
112
+ device_details['configName']
138
113
  end
139
114
 
140
- def raw_config=(json)
141
- raise NoConnection
115
+ def config_description
116
+ device_details['configDescription']
142
117
  end
143
118
 
144
- def config=(hash)
145
- self.raw_config = hash.to_json
119
+ def config_valid?
120
+ device_details['configValid']
121
+ end
122
+
123
+ def failsafe_mode?
124
+ device_details['failsafeMode']
146
125
  end
147
126
 
148
127
  def config
149
128
  @config ||= Oschii::Config.new(raw_config)
150
129
  end
151
130
 
152
- def clear!
153
- self.config = {}
131
+ def config=(hash)
132
+ self.raw_config = hash.to_json
154
133
  end
155
134
 
156
135
  def update!
157
136
  self.config = config.compacted
158
137
  end
159
138
 
160
- def upload_config(filename = nil, silent: false)
161
- if filename.nil?
162
- filenames = Dir.glob("configs/#{name}_*.json")
163
- if filenames.empty?
164
- puts 'No previous config' unless silent
165
- return
166
- end
167
- filename = filenames.sort.last
168
-
169
- unless silent
170
- display_name = filename.split('/')[-1]
171
- .split('_')[-1]
172
- .split('+')[0]
173
- .gsub('T', ' ')
174
- .gsub('.json', '')
175
- puts "Latest: #{display_name}"
176
- begin
177
- prompt '>> [ENTER] to upload, [ESC] to cancel <<'
178
- rescue CancelSerialQuery
179
- return
139
+ def clear!
140
+ self.config = {}
141
+ end
142
+
143
+ # --- Connection ---
144
+
145
+ def refresh
146
+ @device_details = nil
147
+ @status = nil
148
+ @settings = nil
149
+ @config = nil
150
+ poke!
151
+ end
152
+
153
+ def poke!
154
+ remaining_attempts = 3
155
+
156
+ while remaining_attempts > 0
157
+ begin
158
+ if poke
159
+ # device_details
160
+ return true
180
161
  end
162
+ return false
163
+
164
+ rescue RubySerial::Error, RestClient::Exception => e
165
+ raise DeviceUnavailable, e.message
181
166
  end
167
+
168
+ remaining_attempts -= 1
182
169
  end
170
+ raise DeviceUnavailable, '(no response)'
171
+ end
183
172
 
184
- self.config = JSON.parse File.read(filename)
173
+ # --- Connection-specific commands ---
185
174
 
186
- self
175
+ def poke
176
+ raise NoConnection
187
177
  end
188
178
 
189
- def save_config(filename = nil, silent: false)
190
- filename ||= "configs/#{name}_#{Time.now.iso8601}.json"
191
- File.write filename, JSON.pretty_generate(config)
192
- puts "Saved #{filename.split('/')[-1]}" unless silent
179
+ def restart
180
+ raise NoConnection
193
181
  end
194
182
 
195
- # Logging
183
+ def ip
184
+ raise NoConnection
185
+ end
196
186
 
197
- def log
187
+ def raw_device_details
198
188
  raise NoConnection
199
189
  end
200
190
 
201
- def clear_log
191
+ def raw_status
202
192
  raise NoConnection
203
193
  end
204
194
 
205
- def tail(filter: nil)
206
- while true
207
- while (line = log_lines.shift)
208
- if filter.nil? || line.match?(filter)
209
- puts line
210
- end
211
- end
212
- sleep 0.05
213
- end
195
+ def raw_settings
196
+ raise NoConnection
214
197
  end
215
198
 
216
- def logger(params = {})
217
- current_logger = settings['logger']
218
-
219
- all = params[:all]
220
-
221
- sensors = all.nil? ? params[:sensors] : all
222
- drivers = all.nil? ? params[:drivers] : all
223
- monitors = all.nil? ? params[:monitors] : all
224
- listeners = all.nil? ? params[:listeners] : all
225
- states = all.nil? ? params[:states] : all
226
- timers = all.nil? ? params[:timers] : all
227
- subs = all.nil? ? params[:subs] : all
228
- pixels = all.nil? ? params[:pixels] : all
229
- network_in = all.nil? ? params[:network_in] : all
230
- network_out = all.nil? ? params[:network_out] : all
231
- timestamp = params[:timestamp]
232
- to_file = params[:to_file]
233
-
234
- current_logger['sensors'] = sensors unless sensors.nil?
235
- current_logger['drivers'] = drivers unless drivers.nil?
236
- current_logger['monitors'] = monitors unless monitors.nil?
237
- current_logger['listeners'] = listeners unless listeners.nil?
238
- current_logger['states'] = states unless states.nil?
239
- current_logger['timers'] = timers unless timers.nil?
240
- current_logger['subs'] = subs unless subs.nil?
241
- current_logger['pixels'] = pixels unless pixels.nil?
242
- current_logger['networkIn'] = network_in unless network_in.nil?
243
- current_logger['networkOut'] = network_out unless network_out.nil?
244
- current_logger['timestamp'] = timestamp unless timestamp.nil?
245
- current_logger['logToFile'] = to_file unless to_file.nil?
246
- update_settings({ 'logger' => current_logger })
247
- current_logger = settings['logger']
248
- puts JSON.pretty_generate current_logger
199
+ def settings=(new_settings)
200
+ raise NoConnection
249
201
  end
250
202
 
251
- def inspect
252
- "<#{self.class.name}[#{name}] (v#{version})>"
203
+ def raw_config
204
+ raise NoConnection
253
205
  end
254
206
 
255
- private
256
-
257
- def prompt(text, obscure: false)
258
- print "#{text}: "
259
- input = ''
260
- char = ''
261
- until !char.empty? && char.ord == 13
262
- char = STDIN.getch
263
- if char.ord == 127
264
- # BACKSPACE
265
- input = input[0..-2]
266
- print "\r#{text}: #{' ' * input.size} "
267
- print "\r#{text}: #{obscure ? '*' * input.size : input}"
268
- elsif char.ord == 27
269
- # ESC
270
- raise CancelSerialQuery
271
- elsif char.ord == 13
272
- # ENTER
273
- else
274
- input += char
275
- if obscure
276
- print '*'
277
- else
278
- print char
279
- end
280
- end
281
- end
282
- puts
283
- input
207
+ def raw_config=(json)
208
+ raise NoConnection
284
209
  end
285
210
 
211
+ def log
212
+ raise NoConnection
213
+ end
214
+
215
+ def clear_log
216
+ raise NoConnection
217
+ end
286
218
  end
287
219
  end
@@ -0,0 +1,53 @@
1
+ module Oschii
2
+ class DeviceMonitor
3
+ def initialize(oschii)
4
+ @oschii = oschii
5
+ end
6
+
7
+ attr_reader :oschii
8
+
9
+ BAR = "--------------------------------------------------"
10
+
11
+ def start
12
+ oschii.refresh
13
+
14
+ puts
15
+ puts " Device: #{oschii.name}"
16
+ puts " #{oschii.description}" if oschii.description
17
+ puts " #{oschii.class.name}"
18
+ puts " IP: #{oschii.ip}"
19
+ puts "Version: #{oschii.version}"
20
+ puts " Config: #{oschii.config_name} [#{oschii.config_valid? ? ' OK ' : ' INVALID '}]"
21
+ puts " #{oschii.config_description}" if oschii.config_description
22
+ puts
23
+
24
+ if oschii.failsafe_mode?
25
+ puts " ! IN FAILSAFE MODE !"
26
+ puts
27
+ end
28
+
29
+ running = true
30
+
31
+ Thread.new do
32
+ while running
33
+ print "\r"
34
+ print " cycle #{oschii.cycle_time_micros}µs "
35
+ print "- used mem #{oschii.mem_used_percent.to_s.rjust(2)}% "
36
+ print "- used files:#{oschii.files_used_percent.to_s.rjust(2)}% "
37
+ print "- uptime #{oschii.uptime} "
38
+
39
+ oschii.refresh
40
+ sleep 1
41
+ end
42
+ end
43
+
44
+ gets
45
+ puts
46
+
47
+ running = false
48
+
49
+ nil
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,34 @@
1
+ module Oschii
2
+ module Helpers
3
+ module Prompt
4
+ def prompt(text, obscure: false)
5
+ print "#{text}: "
6
+ input = ''
7
+ char = ''
8
+ until !char.empty? && char.ord == 13
9
+ char = STDIN.getch
10
+ if char.ord == 127
11
+ # BACKSPACE
12
+ input = input[0..-2]
13
+ print "\r#{text}: #{' ' * input.size} "
14
+ print "\r#{text}: #{obscure ? '*' * input.size : input}"
15
+ elsif char.ord == 27
16
+ # ESC
17
+ raise CancelSerialQuery
18
+ elsif char.ord == 13
19
+ # ENTER
20
+ else
21
+ input += char
22
+ if obscure
23
+ print '*'
24
+ else
25
+ print char
26
+ end
27
+ end
28
+ end
29
+ puts
30
+ input
31
+ end
32
+ end
33
+ end
34
+ end
@@ -143,6 +143,10 @@ module Oschii
143
143
  RestClient.delete("http://#{ip}/log")&.body
144
144
  end
145
145
 
146
+ def admin
147
+ `open http://#{ip}/admin`
148
+ end
149
+
146
150
  def to_s
147
151
  inspect
148
152
  end
@@ -0,0 +1,49 @@
1
+ module Oschii
2
+ module Logging
3
+ def tail(filter: nil)
4
+ while true
5
+ while (line = log_lines.shift)
6
+ if filter.nil? || line.match?(filter)
7
+ puts line
8
+ end
9
+ end
10
+ sleep 0.05
11
+ end
12
+ end
13
+
14
+ def logger(params = {})
15
+ current_logger = settings['logger']
16
+
17
+ all = params[:all]
18
+
19
+ sensors = all.nil? ? params[:sensors] : all
20
+ drivers = all.nil? ? params[:drivers] : all
21
+ monitors = all.nil? ? params[:monitors] : all
22
+ listeners = all.nil? ? params[:listeners] : all
23
+ states = all.nil? ? params[:states] : all
24
+ timers = all.nil? ? params[:timers] : all
25
+ subs = all.nil? ? params[:subs] : all
26
+ pixels = all.nil? ? params[:pixels] : all
27
+ network_in = all.nil? ? params[:network_in] : all
28
+ network_out = all.nil? ? params[:network_out] : all
29
+ timestamp = params[:timestamp]
30
+ to_file = params[:to_file]
31
+
32
+ current_logger['sensors'] = sensors unless sensors.nil?
33
+ current_logger['drivers'] = drivers unless drivers.nil?
34
+ current_logger['monitors'] = monitors unless monitors.nil?
35
+ current_logger['listeners'] = listeners unless listeners.nil?
36
+ current_logger['states'] = states unless states.nil?
37
+ current_logger['timers'] = timers unless timers.nil?
38
+ current_logger['subs'] = subs unless subs.nil?
39
+ current_logger['pixels'] = pixels unless pixels.nil?
40
+ current_logger['networkIn'] = network_in unless network_in.nil?
41
+ current_logger['networkOut'] = network_out unless network_out.nil?
42
+ current_logger['timestamp'] = timestamp unless timestamp.nil?
43
+ current_logger['logToFile'] = to_file unless to_file.nil?
44
+ update_settings({ 'logger' => current_logger })
45
+ current_logger = settings['logger']
46
+ puts JSON.pretty_generate current_logger
47
+ end
48
+ end
49
+ end
@@ -1,7 +1,9 @@
1
- require 'oschii'
1
+ require_relative '../oschii'
2
2
 
3
3
  include Oschii
4
4
 
5
+ cloud(http: ENV['OSCHII_HTTP_SERVER'])
6
+
5
7
  if ENV['OSCHII_AUTO_POPULATE']
6
8
  populate
7
9
  end
@@ -1,3 +1,3 @@
1
1
  module Oschii
2
- VERSION = '0.0.7'
3
- end
2
+ VERSION = '0.1.0'
3
+ end
data/lib/oschii.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'oschii/version'
1
+ require_relative 'oschii/version'
2
2
 
3
3
  require_relative 'oschii/device'
4
4
  require_relative 'oschii/http_device'
@@ -21,18 +21,19 @@ module Oschii
21
21
  end
22
22
  end
23
23
 
24
- def cloud(silent: false)
25
- @cloud ||= Cloud.new(silent: silent)
24
+ def cloud(http: false, silent: false)
25
+ @cloud ||= Cloud.new(http: http, silent: silent)
26
26
  end
27
27
 
28
- def populate
29
- cloud.populate
28
+ def populate(echo: false)
29
+ cloud.populate(echo: echo)
30
30
  end
31
31
 
32
- def serve_forever
32
+ def serve_oschii_forever
33
33
  populate
34
- puts 'Press ENTER to quit....'
35
- gets
34
+ puts "Press CTRL+C to stop server."
35
+
36
+ while true; end
36
37
  end
37
38
 
38
39
  def serial
@@ -0,0 +1,30 @@
1
+ require File.expand_path('lib/oschii/version', __dir__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "oschii_ruby"
5
+ s.version = Oschii::VERSION
6
+
7
+ s.required_ruby_version = '>= 2.7.7'
8
+
9
+ s.summary = "Gem for managing Oschiis"
10
+ s.description = "Interfaces with a network of Oschiis"
11
+
12
+ s.authors = ["Barri Mason"]
13
+ s.email = "loki@amarantha.net"
14
+ s.homepage = "https://github.com/MisterGrimalkin/oschii_rubygem"
15
+ s.license = "MIT"
16
+
17
+ s.files = Dir[
18
+ 'lib/**/*.rb',
19
+ 'oschii_ruby.gemspec',
20
+ 'Gemfile',
21
+ 'Gemfile.lock'
22
+ ]
23
+
24
+ s.add_dependency 'faye-websocket', '~> 0.11.3'
25
+ s.add_dependency 'rest-client', '~> 2.1.0'
26
+ s.add_dependency 'rubyserial', '~> 0.6.0'
27
+ s.add_dependency 'osc-ruby', '~> 1.1.4'
28
+ s.add_dependency 'webrick', '~> 1.8.1'
29
+ s.add_dependency 'activesupport', '~> 7.1.2'
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oschii_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barri Mason
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-21 00:00:00.000000000 Z
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket
@@ -106,8 +106,12 @@ files:
106
106
  - lib/oschii/cloud.rb
107
107
  - lib/oschii/component.rb
108
108
  - lib/oschii/config.rb
109
+ - lib/oschii/config_file.rb
109
110
  - lib/oschii/device.rb
111
+ - lib/oschii/device_monitor.rb
112
+ - lib/oschii/helpers/prompt.rb
110
113
  - lib/oschii/http_device.rb
114
+ - lib/oschii/logging.rb
111
115
  - lib/oschii/osc_monitor.rb
112
116
  - lib/oschii/parser.rb
113
117
  - lib/oschii/serial_device.rb
@@ -115,7 +119,8 @@ files:
115
119
  - lib/oschii/session.rb
116
120
  - lib/oschii/template.rb
117
121
  - lib/oschii/version.rb
118
- homepage: https://rubygems.org/gems/oschii_ruby
122
+ - oschii_ruby.gemspec
123
+ homepage: https://github.com/MisterGrimalkin/oschii_rubygem
119
124
  licenses:
120
125
  - MIT
121
126
  metadata: {}
@@ -125,7 +130,7 @@ require_paths:
125
130
  - lib
126
131
  required_ruby_version: !ruby/object:Gem::Requirement
127
132
  requirements:
128
- - - "~>"
133
+ - - ">="
129
134
  - !ruby/object:Gem::Version
130
135
  version: 2.7.7
131
136
  required_rubygems_version: !ruby/object:Gem::Requirement