p4labs / p4-robotsim

2D Arduino robot simulation powering Dawson Engineering Physics Virtual Lab
MIT License
6 stars 1 forks source link

Better design for Arduino Component #2

Open tawjaw opened 2 years ago

tawjaw commented 2 years ago

The Component class right now is not a good design. https://github.com/p4labs/p4-robotsim/blob/90d181769a2005918933494fbe3a618206ef359e/src/Arduino/Component.ts#L1 At first the assumption was that a component will only have one digital pin to update.

So it includes https://github.com/p4labs/p4-robotsim/blob/90d181769a2005918933494fbe3a618206ef359e/src/Arduino/Component.ts#L9-L10

and the abstract update expects true or false to update that digital pin.

A better design would probably be to create

DigitalPin, PWMPin and AnalogPin classes that handles the logic and update each pin separately. And a Component would have a collection of pins.

and in the https://github.com/p4labs/p4-robotsim/blob/90d181769a2005918933494fbe3a618206ef359e/src/Arduino/Uno/ArduinoUno.ts#L31 we would add the pin connections to be updated inside a component, instead of the component