Skip to content

feat(nano): WIP. Done except for reset button (#8) #43

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

Merged
merged 5 commits into from
Sep 6, 2020

Conversation

sutaburosu
Copy link
Contributor

Regarding the reset button, am I supposed to just duplicate what I need from pushbutton-element.ts into the Nano element ? Is there a better, DRYer way?

The x,y locations in pinInfo[] have not been verified to be correct, Getting avr8js running so I can check them is my next task.

image

@urish
Copy link
Collaborator

urish commented Sep 3, 2020

Oh wow, first of all - thanks a million :-)

I hope to get a look at the files soon. Regarding the reset button - that's a good question. The easiest solution would probably to add a click listener on the group that contains the button. If we want to support keyboard interaction, a believe a good place to look for inspiration would be the implementation of the keypad element, where we use tabindex to make it focusable, and then listen for mouse/touch/keyboard event.

However, I think that in case of the reset button, we don't actually need all the complexity - it'd probably suffice just to emit a 'click' event, since we only care about the face it was clicked...

@urish
Copy link
Collaborator

urish commented Sep 3, 2020

p.s. it looks gorgeous, and the code also seems very tidy! great job :-)

@sutaburosu
Copy link
Contributor Author

Thanks. I've surprised myself. This time yesterday I had never used Inkscape, and I hadn't even heard of React, etc.

I've enjoyed myself a great deal, but now the difficult bit starts: trying to learn more about how this works, rather than simply mimicking what I've seen you do.

@urish
Copy link
Collaborator

urish commented Sep 3, 2020

I'm here to help :-)

Regarding pinInfo, this is what I did with the MEGA (I should have documented it, but I was rushing to get it out...):

I wrapped the <svg> element with another <div>, and then created a second <svg> inside it to show me the pin positions. This is what it looked like:

before:

render() {
  return `<svg...>blabla</svg>`;
}

After:

render() {
  return `
    <div style="position: relative">
      <svg...>blabla</svg>

      <svg style="position: absolute; top: 0; left: 0" width="100%" height="100%" fill="red">
        ${this.pinInfo.map(
          (pin) => svg`<circle cx=${pin.x} cy=${pin.y} r=2><title>${pin.name}</title></circle>`
        )}
      </svg>
    </div>
  `;
}

and then remove the extra code once you are done.

Ideally, I'd love to have some Storybook addon/integration that will do it automatically (so we can click on a button and see all the pinInfos), but for now this is the method that I've been using as a workaround...

@urish urish linked an issue Sep 3, 2020 that may be closed by this pull request
@sutaburosu
Copy link
Contributor Author

Thanks for the tip. If I add the map() within the existing SVG, everything aligns. Then, after using a <div> with 2 <svg> like you said it shrunk to like 25% the size. Multiplying my mm coords by 1 / 0.254 made it fit, so I deduced that 2nd <svg> is using 0.1in units.

But then I looked at the Mega pins. They seem be in units of 1/100 inch. Then it occurred to me that monitors are frequently 96 DPI and that is very close to 0.01". Is pinMap actually in 1/96th inch pixels? Does that work OK on high-DPI screens?

I also have a problem where all but the last <tspan> in a <text> is misaligned by x-=0.1 inch. I'm starting to think I may have found a bug in something.

I'll spend some time on the reset button logic later today.

@urish
Copy link
Collaborator

urish commented Sep 4, 2020

Thanks!

Yes, indeed pinMap is in 1/96 inch units. CSS defines a pixel as 1/96 of an inch, regardless of the screen resolution.

This is nicely explained in the Understanding pixels and other CSS units tutorial.

@sutaburosu
Copy link
Contributor Author

Thanks for the links. That aspect now makes a lot more sense, and I see that much of what I wrote is actually CSS styles rather than SVG. That's good to know.

I've learned what causes my centred text positioning problems. I can't see a way to use text-anchor="middle" at all with <tspan> without having the layout broken by the Prettier git commit hook. To work around this, I positioned one <text> per item, without the useful dx automatic relative positioning of <tspan>.

I've done what I can with the reset button by dispatching a CustomEvent. similar to what's in the membrane. I'm struggling to see where this event might be received so I can make the AVR reset.

<rect x="23.54" y="6.8" width="2.54" height="3.8" fill="#ccc" stroke="#888" />
<ellipse cx="24.8" cy="8.7" rx="1" ry="1" fill="#eeb" stroke="#777" />
${resetButton &&
svg`<circle cx="24.8" cy="8.7" r="1.5" fill="#f66" filter="url(#ledFilter)" />`}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It makes more sense to change the color of the ellipse above the a darken shade when the button is pressed (we could also use a gradient to make the graphics a bit more realistic, similar to how the pushbutton works).

Right now it seems like the button is illuminated whenever you press it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to make those changes, but perhaps I should first explain why I did it this way. At default zoom, the Nano is very small and the button is tiny. I figured just reversing a gradient wouldn't be visible. I have an MCU (a Teensy I think) with a red LED inside a similar tiny button, so it's not an invention of mine, just a little artistic license. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, a gradient may be to subtle in default zoom. The LED still seems a bit weird for me, how about just a darker shade for the round cap? e.g. #333

</g>

<!-- reset button -->
<g
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about adding a tabindex="0" attribute, so that the reset will be focusable by keyboard (using the tab key?)

Copy link
Contributor Author

@sutaburosu sutaburosu Sep 6, 2020

Choose a reason for hiding this comment

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

I've taken a shot at this in the latest commit. Much googling was required. I'm still not 100% happy. I would like the button to lose focus on mouseleave even after it's been clicked, but I'm struggling to make that happen. Now fixed too.

I've left the LED in pending your feedback re the LED/gradient.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shared my feedback. What was the rationale behind losing focus on mouseleave?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Losing focus on mouseleave is purely for appearance. It didn't feel right that the button looked different before/after clicking it, until it lost focus somehow.

@urish
Copy link
Collaborator

urish commented Sep 6, 2020

So there are some ways to work around prettier (such as wrapping the element that you don't want to be formatted with

   ${svg` <text>dont format me!  </text>  `}

and there's also prettier-ignore (but it doesn't play as nicely with lit-element code), but in general, I like to stick with prettier whenever possible.

I've left some comments on the PR, and I hope that you will be able to look into them.

Re: the reset - it's actually not implemented yet at the simulator level. Right now the best way to "reset" is to restart the simulation altogether. Once the new nano lands, I'll start looking into restarting just the simulated MCU. If I'm not wrong, most peripherals already implement a reset() method, so it could be as simple as calling that method on all the peripherals and the CPU instance.

@sutaburosu sutaburosu requested a review from urish September 6, 2020 16:00
Copy link
Collaborator

@urish urish left a comment

Choose a reason for hiding this comment

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

Cool! Some more small things, and we're good to go!

@sutaburosu
Copy link
Contributor Author

I've done those two small changes. I initially used CSS active to restyle the circle when pressed, but of course that doesn't work with the keyboard so instead I manually restyle it in up() and down()

@urish urish merged commit 665ebc3 into wokwi:master Sep 6, 2020
@urish
Copy link
Collaborator

urish commented Sep 6, 2020

🎉

@sutaburosu sutaburosu deleted the arduino-nano branch September 6, 2020 20:30
@urish urish mentioned this pull request May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Arduino Nano Element
2 participants