mushy 0.11.0 → 0.13.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: a7e8090ce2ca66c9aff11ada4b9beee80bb7866dcd27d51b618c1cfa699b2d4f
4
- data.tar.gz: b9849eca063fa80c99e465c498994c04796245e01c79762338616563e484c312
3
+ metadata.gz: 85eb693e91e6a27ab2943d07ab5d4a7d3544c958793aac1830a3d03a81d98001
4
+ data.tar.gz: be51f8e5b94fb4184c1e8f7ba037de1a5ae9901a0fd7ace4fc85e6cc182a864b
5
5
  SHA512:
6
- metadata.gz: b632030b6ce53a9364e6861b466e6574cd9f2e5836964db87a4124109bb4e0c23d801c448b40b1270e367cc2ab7eecb04b4ef94fa86ae844e1626f2a97471f52
7
- data.tar.gz: 421e022ab044af27b72b2380be9343c22fa94c435388512712045f717af46c3ee10a2524e2784aff5bfb5c0e1bbe3a255b73a47ab38d514e17bb9307b626dad2
6
+ metadata.gz: 8bc9319d1c55c581d91377c28ec526ec2215c66962eae0723cfa47eaca5599d6a5bebc439ce423864c37544e6b6250354235f14dddb182c370836c9a289ddd66
7
+ data.tar.gz: '08efdce27c2820c503ef940224c9b27da0d4c88f11d3f837d50ca1ba99f062de019b1143dc4a3d5bf575b1789b9218c913315570ef00d82b7173c0cbbaa8299a'
@@ -0,0 +1,28 @@
1
+ require 'csv'
2
+
3
+ module Mushy
4
+
5
+ class ReadJson < Flux
6
+
7
+ def self.details
8
+ {
9
+ name: 'ReadJson',
10
+ description: 'Read JSON and output it as an event.',
11
+ config: {
12
+ json: {
13
+ description: 'The JSON contents that will be returned as an event.',
14
+ type: 'text',
15
+ value: 'json',
16
+ },
17
+ },
18
+ }
19
+ end
20
+
21
+ def process event, config
22
+ return nil unless config[:json].to_s != ''
23
+ JSON.parse config[:json]
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -4,8 +4,8 @@ module Mushy
4
4
 
5
5
  def self.details
6
6
  details = Browser.details
7
- details['name'] = 'Screenshot'
8
- details['description'] = 'Take a screenshot of the browser.'
7
+ details[:name] = 'Screenshot'
8
+ details[:description] = 'Take a screenshot of the browser.'
9
9
 
10
10
  details[:config].merge!(Mushy::WriteFile.file_saving_config.tap do |x|
11
11
  x[x.keys.first][:value] = 'file.jpg'
@@ -0,0 +1,283 @@
1
+ module Mushy
2
+
3
+ class SenseHatLedMatrix < SimplePythonProgram
4
+
5
+ def self.details
6
+ {
7
+ name: 'SenseHatLedMatrix',
8
+ description: 'Interface with the LED Matrix.',
9
+ config: Mushy::SimplePythonProgram.default_config.tap do |config|
10
+ config[:get_pixels] = {
11
+ description: 'Specify the pixels you want returned as events. Use "all" to return all 64, 3,3 to return x:3 y:3, or "none" to return none.',
12
+ type: 'text',
13
+ shrink: true,
14
+ value: 'all',
15
+ }
16
+ config[:set_pixel] = {
17
+ description: 'Set a single pixel to the RGB color.',
18
+ type: 'text',
19
+ shrink: true,
20
+ value: '',
21
+ }
22
+ config[:set_pixels] = {
23
+ description: 'An array of multiple pixels to set. The records must have coordinates and rgb values, just like what comes out of the get pixels call.',
24
+ type: 'text',
25
+ shrink: true,
26
+ value: '',
27
+ }
28
+ config[:rgb] = {
29
+ description: 'The RGB value as a comma-delimited list. Leave blank to not set a color.',
30
+ type: 'text',
31
+ shrink: true,
32
+ value: '',
33
+ }
34
+ config[:background_color] = {
35
+ description: 'The RGB of the background, which is used in some API calls.',
36
+ type: 'text',
37
+ shrink: true,
38
+ value: '',
39
+ }
40
+ config[:clear] = {
41
+ description: 'The RGB color to apply to the entire grid.',
42
+ type: 'text',
43
+ shrink: true,
44
+ value: '',
45
+ }
46
+ config[:show_letter] = {
47
+ description: 'Show a single letter on the grid. Uses Rgb and Background Color.',
48
+ type: 'text',
49
+ shrink: true,
50
+ value: '',
51
+ }
52
+ config[:show_message] = {
53
+ description: 'Scroll a message across the grid. Uses Rgb and Background Color.',
54
+ type: 'text',
55
+ shrink: true,
56
+ value: '',
57
+ }
58
+ config[:load_image] = {
59
+ description: 'Load a 8x8 image.',
60
+ type: 'text',
61
+ shrink: true,
62
+ value: '',
63
+ }
64
+ config[:set_rotation] = {
65
+ description: 'Rotate the image by these degrees.',
66
+ type: 'select',
67
+ options: ['', '0', '90', '180', '270'],
68
+ shrink: true,
69
+ value: '',
70
+ }
71
+ config[:redraw] = {
72
+ description: 'Redraw.',
73
+ type: 'boolean',
74
+ shrink: true,
75
+ value: '',
76
+ }
77
+ config[:low_light] = {
78
+ description: 'Use the low light to turn down the brightness.',
79
+ type: 'boolean',
80
+ shrink: true,
81
+ value: '',
82
+ }
83
+ config[:flip_h] = {
84
+ description: 'Flips the image horizontally.',
85
+ type: 'boolean',
86
+ shrink: true,
87
+ value: '',
88
+ }
89
+ config[:flip_v] = {
90
+ description: 'Flips the image vertically.',
91
+ type: 'boolean',
92
+ shrink: true,
93
+ value: '',
94
+ }
95
+ config[:target] = {
96
+ description: 'The target of these commands. "hat" is a SenseHAT plugged into your Raspberry Pi, and "emu" is the SenseHAT emulator. Defaults to "hat".',
97
+ type: 'select',
98
+ options: ['', 'hat' , 'emu'],
99
+ shrink: true,
100
+ value: '',
101
+ }
102
+ end
103
+ }
104
+ end
105
+
106
+ def python_program event, config
107
+
108
+ commands = [
109
+ :set_pixel_code_from,
110
+ :set_pixels_code_from,
111
+ :clear_pixels_code_from,
112
+ :show_letters_code_from,
113
+ :show_message_code_from,
114
+ :load_images_code_from,
115
+ :set_rotation_code_from,
116
+ :low_light_code_from,
117
+ :flip_h_code_from,
118
+ :flip_v_code_from,
119
+ ].map { |x| self.send x, event, config }
120
+ .select { |x| x.to_s != '' }
121
+ .join("\n")
122
+
123
+ hat = config[:target] == 'emu' ? 'sense_emu' : 'sense_hat'
124
+
125
+ <<PYTHON
126
+ from #{hat} import SenseHat
127
+ import json
128
+ sense = SenseHat()
129
+ #{commands}
130
+ value = json.dumps({"all": #{get_pixels_code_from(event, config)}})
131
+ print(value)
132
+ PYTHON
133
+ end
134
+
135
+ def adjust data, event, config
136
+ limit = 8
137
+
138
+ coordinates = coordinates_from config[:get_pixels]
139
+
140
+ records = coordinates ? [data[:all]] : data[:all]
141
+
142
+ results = records.each_with_index.map do |item, index|
143
+ {
144
+ x: index % limit,
145
+ y: index / limit,
146
+ r: item[0],
147
+ g: item[1],
148
+ b: item[2],
149
+ }
150
+ end
151
+
152
+ if coordinates
153
+ results[0][:x] = coordinates[:x]
154
+ results[0][:y] = coordinates[:y]
155
+ end
156
+
157
+ results.each do |record|
158
+ record[:coordinate] = "#{record[:x]},#{record[:y]}"
159
+ record[:rgb] = "#{record[:r]},#{record[:g]},#{record[:b]}"
160
+ end
161
+
162
+ results
163
+ end
164
+
165
+ def rgb_from config
166
+ color_split = config.to_s.split ','
167
+ return nil unless color_split.count == 3
168
+ return [:r, :g, :b].each_with_index
169
+ .reduce({}) { |t, i| t[i[0]] = color_split[i[1]].to_s.to_i ; t}
170
+ end
171
+
172
+ def coordinates_from config
173
+ coordinate_split = config.to_s.split ','
174
+ return nil unless coordinate_split.count == 2
175
+ return [:x, :y].each_with_index
176
+ .reduce({}) { |t, i| t[i[0]] = coordinate_split[i[1]].to_s.to_i ; t}
177
+ end
178
+
179
+ def set_pixel_code_from event, config
180
+ rgb = rgb_from config[:rgb]
181
+ set_pixel_coordinates = coordinates_from config[:set_pixel]
182
+ return '' unless rgb
183
+ return '' unless set_pixel_coordinates
184
+
185
+ turn_these_to_pixels([ {
186
+ coordinate: "#{set_pixel_coordinates[:x]},#{set_pixel_coordinates[:y]}",
187
+ rgb: "#{rgb[:r]},#{rgb[:g]},#{rgb[:b]}",
188
+ } ])
189
+ end
190
+
191
+ def set_pixels_code_from event, config
192
+ return '' unless config[:set_pixels]
193
+ turn_these_to_pixels config[:set_pixels]
194
+ end
195
+
196
+ def turn_these_to_pixels values
197
+ options = [:coordinate, :rgb]
198
+ values.map do |pixel|
199
+ options.reduce({}) { |t, i| t[i] = pixel[i].split(',') ; t}
200
+ end.map do |pixel|
201
+ "sense.set_pixel(#{pixel[:coordinate][0]}, #{pixel[:coordinate][1]}, [#{pixel[:rgb][0]}, #{pixel[:rgb][1]}, #{pixel[:rgb][2]}])"
202
+ end.join("\n")
203
+ end
204
+
205
+ def clear_pixels_code_from event, config
206
+ clear = rgb_from config[:clear]
207
+ return '' unless clear
208
+ "sense.clear(#{clear[:r]}, #{clear[:g]}, #{clear[:b]})"
209
+ end
210
+
211
+ def show_letters_code_from event, config
212
+ return '' if config[:show_letter].to_s == ''
213
+
214
+ rgb = rgb_from config[:rgb]
215
+ background_color = rgb_from config[:background_color]
216
+
217
+ args = ["\"#{config[:show_letter]}\""]
218
+ args << "text_colour=[#{rgb[:r]}, #{rgb[:g]}, #{rgb[:b]}]" if rgb
219
+ args << "back_colour=[#{background_color[:r]}, #{background_color[:g]}, #{background_color[:b]}]" if background_color
220
+ "sense.show_letter(#{args.join(',')})"
221
+ end
222
+
223
+ def show_message_code_from event, config
224
+ return '' if config[:show_message].to_s == ''
225
+
226
+ rgb = rgb_from config[:rgb]
227
+ background_color = rgb_from config[:background_color]
228
+
229
+ args = ["\"#{config[:show_message]}\""]
230
+ args << "text_colour=[#{rgb[:r]}, #{rgb[:g]}, #{rgb[:b]}]" if rgb
231
+ args << "back_colour=[#{background_color[:r]}, #{background_color[:g]}, #{background_color[:b]}]" if background_color
232
+ "sense.show_message(#{args.join(',')})"
233
+ end
234
+
235
+ def load_images_code_from event, config
236
+ return '' if config[:load_image].to_s == ''
237
+
238
+ args = ["\"#{config[:load_image]}\""]
239
+ args << config[:redraw].to_s.capitalize if config[:redraw].to_s != ''
240
+ "sense.load_image(#{args.join(',')})"
241
+ end
242
+
243
+ def set_rotation_code_from event, config
244
+ return '' if config[:set_rotation].to_s == ''
245
+ args = ["#{config[:set_rotation]}"]
246
+ args << config[:redraw].to_s.capitalize if config[:redraw].to_s != ''
247
+ "sense.set_rotation(#{args.join(',')})"
248
+ end
249
+
250
+ def low_light_code_from event, config
251
+ return '' if config[:low_light].to_s == ''
252
+ "sense.low_light = #{config[:low_light].capitalize}"
253
+ end
254
+
255
+ def flip_h_code_from event, config
256
+ return '' unless config[:flip_h].to_s == 'true'
257
+ args = []
258
+ args << config[:redraw].to_s.capitalize if config[:redraw].to_s != ''
259
+ "sense.flip_h(#{args.join(',')})"
260
+ end
261
+
262
+ def flip_v_code_from event, config
263
+ return '' unless config[:flip_v].to_s == 'true'
264
+ args = []
265
+ args << config[:redraw].to_s.capitalize if config[:redraw].to_s != ''
266
+ "sense.flip_v(#{args.join(',')})"
267
+ end
268
+
269
+ def get_pixels_code_from event, config
270
+ get_pixel_coordinates = coordinates_from config[:get_pixels]
271
+
272
+ if get_pixel_coordinates
273
+ "sense.get_pixel(#{get_pixel_coordinates[:x]}, #{get_pixel_coordinates[:y]})"
274
+ elsif config[:get_pixels].to_s.downcase == 'all'
275
+ 'sense.get_pixels()'
276
+ else
277
+ '[]'
278
+ end
279
+ end
280
+
281
+ end
282
+
283
+ end
@@ -23,10 +23,14 @@ module Mushy
23
23
 
24
24
  return nil unless result[:success]
25
25
 
26
- JSON.parse result[:text]
26
+ adjust SymbolizedHash.new(JSON.parse(result[:text])), event, config
27
27
 
28
28
  end
29
29
 
30
+ def adjust data, event, config
31
+ data
32
+ end
33
+
30
34
  end
31
35
 
32
36
  end
@@ -0,0 +1,29 @@
1
+ require 'csv'
2
+
3
+ module Mushy
4
+
5
+ class WriteJson < Flux
6
+
7
+ def self.details
8
+ {
9
+ name: 'WriteJson',
10
+ description: 'Write the incoming event as JSON.',
11
+ config: {
12
+ key: {
13
+ description: 'The key of the outgoing field that will contain the JSON.',
14
+ type: 'text',
15
+ value: 'json',
16
+ },
17
+ },
18
+ }
19
+ end
20
+
21
+ def process event, config
22
+ {
23
+ config[:key] => event.to_json
24
+ }
25
+ end
26
+
27
+ end
28
+
29
+ end
data/mushy.gemspec CHANGED
@@ -4,7 +4,7 @@ require 'mushy/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'mushy'
7
- s.version = '0.11.0'
7
+ s.version = '0.13.0'
8
8
  s.date = '2020-11-23'
9
9
  s.summary = 'Process streams of work using common modules.'
10
10
  s.description = 'This tool assists in the creation and processing of workflows.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mushy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -203,12 +203,15 @@ files:
203
203
  - lib/mushy/fluxs/pwd.rb
204
204
  - lib/mushy/fluxs/read_csv.rb
205
205
  - lib/mushy/fluxs/read_file.rb
206
+ - lib/mushy/fluxs/read_json.rb
206
207
  - lib/mushy/fluxs/screenshot.rb
207
208
  - lib/mushy/fluxs/sense_hat_environmental_sensors.rb
209
+ - lib/mushy/fluxs/sense_hat_led_matrix.rb
208
210
  - lib/mushy/fluxs/simple_python_program.rb
209
211
  - lib/mushy/fluxs/smtp.rb
210
212
  - lib/mushy/fluxs/times.rb
211
213
  - lib/mushy/fluxs/write_file.rb
214
+ - lib/mushy/fluxs/write_json.rb
212
215
  - lib/mushy/masher.rb
213
216
  - lib/mushy/run.rb
214
217
  - lib/mushy/runner.rb