Skip to content

Support the auto matching regexes for pin selection. Requires schema including regex and io-rails using it #295

@tyeth

Description

@tyeth

Adding displays on the DFRobot C5, the new isHardwired pins are not being automatically selected (now regexes).
It's in a couple of places in io-rails, and multiple magic string locations = tech debt + risk, so we'd ideally refactor them to only be in the schema.json definition from this repository.

We already have a concept of matching strings in component definitions, but it would need expanding for regex or string arrays.

Related Slack Conversation

Oh Loren, where's that /re?se?t/  ishardwired stuff in rails? I'm curious if it should auto select a couple more of my pins, or if it's correct to just include them in the dropdown (assuming filter matches)
Loren Norman  [3:11 PM]
oh yeah i used a different regex than that specifically since i wanted to catch the lcd_ prefix
[3:11 PM]sec
[3:11 PM]https://github.com/AdafruitInternalDev/io-rails/blob/0850a560a87390cc661b03bf533a5804aef5b9ff/app/javascript/src/components/WipperSnapper/component_forms/DisplayForm.jsx#L36
DisplayForm.jsx          [reset)/ } /](https://github.com/adafruit/Wippersnapper_Components/PinSelector%20label=%22Reset%20Pin%22%20pinKey=%22rstPinName%22%20showHardwired=%7B%20/(lcd_rst)
AdafruitInternalDev/io-rails | Added by GitHub
Tyeth  [3:12 PM]
Legend, thanks
Loren Norman  [3:12 PM]
the showHardwired prop can take a regex now
Tyeth  [3:12 PM]
oooo nice, okay
Loren Norman  [3:12 PM]
easy to extend as we like, just try to be more exclusive than not
[3:12 PM]be thoughtful, etc
[3:13 PM]and lemme know if the regex isnt providing the flexibility you need
[3:13 PM](also a raw string is converted to a regex and used now, which i think does an exact match... but that may not be true)
[3:14 PM](in case you see any unexpected behavior changes on hardwired pin exposure)
[3:15 PM]actually yeah it substring matches, so that might've widened the matches when i pushed it
[3:15 PM]i think there's just so few hardwired pins it's not a big deal, but we can tighten the belt when it's relevant
Tyeth  [3:15 PM]
Got you. Yeah the simple ones (MOSI/MISO/SCK) are matching and being selected automatically. Feels like the regexes are including the results in dropdown but not autoselecting. I'll watch it through in js land (edited) 
Loren Norman  [3:15 PM]
easy enough to constrain it back to exact match
[3:16 PM]oh it's not auto-selecting anymore?
[3:16 PM]autoselect might be a different function entirely
[3:18 PM]yep it is
[3:19 PM]https://github.com/AdafruitInternalDev/io-rails/blob/0850a560a87390cc661b03bf533a5804aef5b9ff/app/javascript/src/slices/components.js#L251-L283
components.js    if(displayType.type === "epd") {
     // auto select appropriate EPD pins
     const epdString = autoSelectString || 'epd'
     propsByType.rstPinName = autoSelectPin(state, epdString, 'digital', 'reset')
     propsByType.csPinName = autoSelectPin(state, epdString, 'digital', 'cs')
AdafruitInternalDev/io-rails | Added by GitHub[3:19 PM] magic strings here, magic strings there, magic strings everywhere!
Tyeth  [3:19 PM]
Aha! Thank you
[3:19 PM]More magic more better right?
Loren Norman  [3:22 PM]
dang that's tough, need to do the same modification there and switch those extraMatch params to regexes as well
[3:22 PM]i can do this
[3:23 PM]i broke DRY once, this is my penance
Tyeth  [3:26 PM]
Wonder if there's some way we can stash this in the schema files, write once use everywhere. I guess we could do (as we already define different schema requirements based on displayType = tft/epd).  "Just" have to plumb it all up
Loren Norman  [3:27 PM]
yeah
Tyeth  [3:27 PM]
I'll stick an issue in the components repo, and we can deal with it after v2 issues, or if it becomes more urgent/useful
Loren Norman  [3:28 PM]
we do actually have this in the schema to some degree
[3:28 PM]just need to swap those to regexes, or allow arrays-of-strings

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions