Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Planar Clarity Video Wall #65

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

Conversation

GabFitzgerald
Copy link

First attempt
Resolves #59

some confusion with options / **options

@GabFitzgerald GabFitzgerald self-assigned this Oct 14, 2020
@GabFitzgerald GabFitzgerald marked this pull request as draft October 14, 2020 06:39
@kimburgess
Copy link
Contributor

Having a quick read now. To provide some further reading on **options, that's a use of splatting.

TL;DR it can be used as a continent way to forward an arbitrary set of keyword arguments around. It was used a lot in the previous Ruby drivers, but would recommend avoiding it unless absolutely needed here as it can lead to some sloppy type signatures.

drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved
drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved
drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved
drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved
@@ -0,0 +1,10 @@
DriverSpecs.mock_driver "Planar::ClarityMatrix" do
# on connect it should do_poll the device
should_send("op A1 display.power ? \r")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing specs, you also want to mock mock the device responses so that you test full request -> response behaviour. For some info on this, see: https://github.com/PlaceOS/drivers/blob/master/docs/writing-a-spec.md#testing-streaming-io.

drivers/planar/codes.txt Outdated Show resolved Hide resolved
@dukenguyenxyz
Copy link
Contributor

dukenguyenxyz commented Oct 15, 2020

Having a quick read now. To provide some further reading on **options, that's a use of splatting.

TL;DR it can be used as a continent way to forward an arbitrary set of keyword arguments around. It was used a lot in the previous Ruby drivers, but would recommend avoiding it unless absolutely needed here as it can lead to some sloppy type signatures.

Hi @kimburgess , upon going through this comment I thought it'd be a good idea to implement Hash instead of splat. However, this is not allowed since splatting in drivers is mostly used in

queue(**({
      name: command,
    }.merge(options))) do
...
end

and queue's method is defined in placeos-driver/src/placeos-driver.cr as follows (line 114-117)

  # Queuing
  def queue(**opts, &block : Task -> Nil)
    @__queue__.add(**opts, &block)
  end

which disallows anything but splats and NamedTuple in the argument.

Copy link
Contributor

@pkheav pkheav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had a look through and have picked up some things on style/feedback that @kimburgess has given me previously. There are probably other things I have missed or not knowledgable enough to give feedback on so best to reach out to @kimburgess for further feedback but this should hopefully be a good start of some things to look out for :)

drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved
drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved
drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved

protected def do_poll
power?
input_status if self["power"] == "ON"
Copy link
Contributor

@pkheav pkheav Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self[:power] will be of type JSON::Any so this should be changed to:
input_status if self[:power]?&.try as_bool

I've noticed this is necessary in order to use self values that are of type Bool properly in conditional statements.

Explanation of why this is needed is here #19 (comment) and is probably to do with how crystal deals with truthy/falsy values

Copy link
Contributor

@pkheav pkheav Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self[:key] will return an error if the key does not exist while self[:key]? will return nil so is safer to use generally.

.try is a safe way to deal with objects that may be nil https://crystal-lang.org/api/0.35.1/Object.html#try(&)-instance-method

as_bool https://crystal-lang.org/api/0.19.4/JSON/Any.html#as_bool%3ABool-instance-method is necessary in order to convert self[:power] which is of type JSON::Any to type Bool so it behaves as expected in conditional statements

send "op ** slot.recall #{preset} \r", name: :recall
end

def input_status
Copy link
Contributor

@pkheav pkheav Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be renamed to input? to keep it consistent with power? but @kimburgess can probably better comment on this

drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved
drivers/planar/clarity_matrix.cr Outdated Show resolved Hide resolved
@caspiano caspiano changed the title Draft: Planar Clarity Video Wall feat: Planar Clarity Video Wall May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Planar Clarity Video Wall
5 participants