syncsign 0.2.0 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ec8ce97ef1f4882420617de3310d74e2d4a3783a4f1922847c706c3eb04b13c
4
- data.tar.gz: 0a867fa0debe259b37d347aff38800f9ae589a4e2afde253d69fbe2f2cab4bbe
3
+ metadata.gz: 0c71d9ba121262edad7f9e12094cede28b97909345521b48898bc792da31070d
4
+ data.tar.gz: 63a4e344b54a6ee357e636c5e62e56fc33565a17561a8b616a356304f5f0d10c
5
5
  SHA512:
6
- metadata.gz: fc9cc2483763d6a35cee7d3c9370b2abe6774b5870321ec219ed02c26b61a0d60378c8a38149507bcef9e4cecbb6b88f9a4888e888732d7d47516d6597ab4d3b
7
- data.tar.gz: 9bba6acf10f9b33d4a9d11065e12ae6c3d4270bc95e991e03651aace8dd0c52655fe07ea628f110572a0b58b6fce7ca51601dcf48d43cd30308b574b5b165de9
6
+ metadata.gz: d500314480cda678242c4204b88cb0275c5a2d10642922cc79e49f05850bd32a064b646d25aed15401ad56f2b8f01112ced44a676e2ce2f3e00e7ba42a0eece9
7
+ data.tar.gz: 5e1acd15b5443e3a5097e1e3a89f520a610efdea3c37caea5f1d328e1f1d60c3dec152bcc9532318e8e21341233c50a4f2056f7ca52fb2a2d09981b2b63b6dcf
data/README.md CHANGED
@@ -36,3 +36,5 @@ Check out the examples/ folder for:
36
36
  * nodes.rb - List all nodes on the system and information about them.
37
37
  * render.rb - Render a sample screen to the given node.
38
38
 
39
+ ## Full Documentation
40
+ YARD docs included, also available on [RubyDoc.info](https://www.rubydoc.info/github/sarahemm/ruby-syncsign/master)
@@ -14,9 +14,12 @@ module SyncSign
14
14
  # @param items [Array] List of Widgets to add to the template.
15
15
  # @param pollrate [Integer] How often (in ms) the node should poll the hub
16
16
  # for new information.
17
- def initialize(bgcolour: :white, items: [], pollrate: 10000)
17
+ # @param enable_buttons [Boolean] Whether to enable the button labels at
18
+ # the bottom of the screen.
19
+ def initialize(bgcolour: :white, items: [], pollrate: 10000, enable_buttons: false)
18
20
  @bgcolour = bgcolour
19
21
  @pollrate = pollrate
22
+ @enable_buttons = enable_buttons
20
23
 
21
24
  @items = []
22
25
  items.each do |item|
@@ -35,7 +38,10 @@ module SyncSign
35
38
  ##
36
39
  # Output this template as JSON in the format that the SyncSign service understands.
37
40
  def to_s
38
- background = {bgColor: @bgcolour.to_s.upcase}
41
+ background = {
42
+ bgColor: @bgcolour.to_s.upcase,
43
+ enableButtonZone: @enable_buttons
44
+ }
39
45
  items = @items.collect { |item| item.to_a }
40
46
  options = {'pollRate': @pollrate}
41
47
  {
@@ -1,4 +1,4 @@
1
1
  module SyncSign
2
2
  # The version number of the SyncSign module.
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.3'
4
4
  end
@@ -199,9 +199,10 @@ module SyncSign
199
199
  # @param font [Symbol] The font to use when drawing the text.
200
200
  # @param size [Integer] The point size to use when drawing the text.
201
201
  # @param align [Symbol] Whether to align the text left, center, or right.
202
+ # @param linespacing [Integer] How much space to leave between each line.
202
203
  # @param text [String] The text to draw in the box.
203
204
  # @param id [String] An ID value to attach to the text box.
204
- def initialize(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white, font: nil, size: nil, id: nil, align: :left, text: nil)
205
+ def initialize(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white, font: nil, size: nil, id: nil, align: :left, linespacing: 2, text: nil)
205
206
  check_font(font: font, size: size)
206
207
  raise(AlignmentException, "Textbox: either y or height must be a multiple of 8") if y % 8 != 0 and height % 8 != 0
207
208
  raise(AlignmentException, "Textbox: width must be a multiple of 8") if width % 8 != 0
@@ -209,6 +210,7 @@ module SyncSign
209
210
  @size = size
210
211
  @id = id
211
212
  @align = align
213
+ @linespacing = linespacing
212
214
  @text = text
213
215
  super(x: x, y: y, width: width, height: height, colour: colour, bgcolour: bgcolour)
214
216
  end
@@ -216,18 +218,26 @@ module SyncSign
216
218
  ##
217
219
  # Convert the widget into an array for sending to the SyncSign service.
218
220
  def to_a
221
+ font_string = "#{@font}_#{@size.to_s}"
222
+ # this one font has to be specified in a different way
223
+ font_string += "_B" if @font.to_s.upcase == "YANONE_KAFFEESATZ"
219
224
  {
220
225
  'type': 'TEXT',
221
226
  'data': {
222
227
  'block': {x: @x, y: @y, w: @width, h: @height},
223
228
  'textColor': @colour.to_s.upcase,
224
229
  'textAlign': @align.to_s.upcase,
225
- 'font': "#{@font}_#{@size.to_s}",
230
+ 'font': font_string,
231
+ 'lineSpace': @linespacing,
226
232
  'text': @text
227
233
  }
228
234
  }
229
235
  end
230
236
 
237
+ # Check a font/size combination to make sure it's valid.
238
+ # Will raise ArgumentError if the font, size, or combination isn't supported..
239
+ # @param font [Symbol] A symbol to check, representing a font.
240
+ # @param size [Integer] A font size to check.
231
241
  def check_font(font: nil, size: nil)
232
242
  available_sizes = {
233
243
  :ddin => [16, 24, 32, 48, 64, 128],
@@ -306,6 +316,48 @@ module SyncSign
306
316
  end
307
317
  end
308
318
 
319
+ ##
320
+ # A widget that draws button labels for the 4.2" display.
321
+ class ButtonLabels
322
+ # @return [Array] Up to 4 strings of 17 characters each, to label the buttons with.
323
+ attr_accessor :labels
324
+ # @return [Array] Up to 4 boolean values showing whether each button should be reverse colours.
325
+ attr_accessor :reversed
326
+
327
+ ##
328
+ # Initialize a new Button Labels widget.
329
+ # @param labels [Array] Up to 4 strings of 17 characters each, to label the buttons with.
330
+ # @param reversed [Array] Up to 4 boolean values showing whether each button should be reverse colours (white on black). Default is black on white.
331
+ def initialize(labels: [], reversed: [])
332
+ # TODO: validate <= 17 characters in each label
333
+ @labels = labels
334
+ @reversed = reversed
335
+ end
336
+
337
+ ##
338
+ # Convert the widget into an array for sending to the SyncSign service.
339
+ def to_a
340
+ label_arr = []
341
+ (0..3).each do |idx|
342
+ label_arr[idx] = {
343
+ :title => @labels[idx] || "",
344
+ :style => @reversed[idx] || 'DISABLED'
345
+ }
346
+ end
347
+
348
+ {
349
+ 'type': 'BOTTOM_CUSTOM_BUTTONS',
350
+ 'data': {
351
+ 'list': label_arr
352
+ }
353
+ }
354
+ end
355
+ end
356
+
357
+ ##
358
+ # Check a set of colours to make sure they're all valid.
359
+ # Will raise ArgumentError if any elements are not valid colours.
360
+ # @param colours [Array] An array of symbols to check.
309
361
  def self.check_colours(colours)
310
362
  colours.each do |colour|
311
363
  next if [:white, :black, :red].include? colour
@@ -313,6 +365,9 @@ module SyncSign
313
365
  end
314
366
  end
315
367
 
368
+ # Check a set of patterns to make sure they're all valid.
369
+ # Will raise ArgumentError if any elements are not valid patterns.
370
+ # @param patterns [Array] An array of symbols to check.
316
371
  def self.check_patterns(patterns)
317
372
  patterns.each do |pattern|
318
373
  next if [:solid, :interleave, :dash_tiny, :dash_medium, :dash_wide, :none].include? pattern
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syncsign
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sarahemm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-16 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Interface library for SyncSign e-paper displays
14
14
  email: github@sen.cx