kbaskett248 / adafruit_macropad

45 stars 21 forks source link

Create settings class #13

Closed kbaskett248 closed 2 years ago

kbaskett248 commented 2 years ago

This PR adds some formalization around the app settings by creating a settings class. The class allows settings access by attribute as in a normal class while maintaining the dictionary-like access needed for the settings keys.

There are actually two settings classes added. The BaseSettings class defines a base class, with no actual settings defined. The KeyAppSettings class extends the former, and adds the expected settings for KeyApps.

Some settings that were previously defined in constants have been moved into the settings; namely, the color scheme and the pixel color timeout. This makes it much easier to customize the colors used in an app.

One approach I considered was making the settings object a singleton, so it could be accessed anywhere at any time. I ultimately decided to abandon this idea because it should be possible to have two apps with two separate settings objects, if that was so desired. Going with a single global settings object enforces consistency, and I would rather maintain flexibility. So settings are still specified for each App individually.

kbaskett248 commented 2 years ago

@avi-perl this is what I came up with for the settings object, inspired by the work you did in https://github.com/kbaskett248/adafruit_macropad/pull/11. Interested to hear any feedback you have.