0

Your shopping cart

0
Subtotal:  0
No products in the cart.
Make your cart full of Floowers 🌷

I wrote a terrible firmware

So I rewrote Floower’s firmware (Flooware) from scratch.

The main reason to do that – I would love to build a community of developers around Floower. I would love to have you write custom mods to the behavior of Floower to bring joy into everyday life. That’s my dream. Yes, it’s Opensource and every Floower is equipped with a USB-C interface that is used to flash the firmware. Just hook it up to your computer and you are good to go!

Customizing the Floower is fun. I already made several mods for several occasions and faires – Halloween Floower, color mixer, blooming garden installation, simple reflex game, etc. And it nicely shows that the Floower is a very versatile device.

The original code was far from being easy to explain and extend. After all, it was created by a 2-year long spaghetti-like evolution where I was adding functionalities without having a big picture on the overall architecture. The nightmare is over!

It took me 3 weeks, 39 files changed with 2,422 additions and 2,303 deletions.

I switched over to PlatformIO

I resisted for a long time. I was too busy to innovate. But the switch from Arduino to PlatformIO was the best thing I could do. Suddenly the nightmare of setting up the project, libraries, and development board was gone. Everything is already configured, so all you need to do is clone the repository and hit the upload button. All the dependencies are auto-installed, and the board is pre-configured. One barrier down.

I abstracted the hardware

I don’t want you to study what pins you need to configure and what signals to use. I moved everything regarding the bare hardware behind a single interface. If you need to make it bloom, you just call the appropriate method, and magic will happen. Second barrier down.

I created behavior eco-system

The original firmware contained a lot of core functionality spread around multiple classes and even the main class. It was tough to change or introduce another Floower’s behavior without changing several classes. So I designed the firmware to be a programming platform inside a platform. To make your Floower behave as you wish, all you need to do is write a simple “sketch” class – aka behavior class with a dead-simple interface – setup and loop. Sounds familiar? Third barrier down!

				
					if (state == STATE_STANDBY) {
    // light + open
    HsbColor nextColor = nextRandomColor();
    floower->transitionColor(nextColor.H, nextColor.S, config->colorBrightness, config->speedMillis);
    floower->setPetalsOpenLevel(config->personification.maxOpenLevel, config->speedMillis);
    changeState(STATE_BLOOM_OPENING);
    return true;
}
else if (state == STATE_BLOOM_LIGHT) {
    // open
    floower->setPetalsOpenLevel(config->personification.maxOpenLevel, config->speedMillis);
    changeState(STATE_BLOOM_OPENING);
    return true;
}
				
			

Quickstart Guide

The code is still subject to change, so I am no aiming right now for extensive documentation. After all, the code should be self-explanatory. So I will give you a quick tour through the Flooware architecture so you can start from somewhere.

Flooware is Arduino-based

The core functionality of the Floower is represented by a state machine. Everything that is happening with your Floower is a state. And interaction with Floower, timer event, or mobile application event is a trigger to change state in a pre-defined way. I call this state machine behavior. Behavior is a simple interface of 3 methods:

setup & loop – functions are an analogy to Arduino’s sketch setup and loop functions. Setup is called only once and is useful to initialize variables and states. Loop is called as often as possible repetitively, allowing you to program the behavior itself.

isIdle – method should return true if your behavior is not actively animating the Floower. The software will save some battery power idling.

				
					class Behavior {
    public:
        virtual void setup(bool wokeUp = false) = 0;
        virtual void loop() = 0;
        virtual bool isIdle() = 0;
};
				
			

The above is everything you need to implement to make the Floower doing what you need. To make the job even easier, there is plenty of helpful functions and abstractions:

behavior/SmartPowerBehavior represents a basic behavior of Floower you should always implement – power management. If you extend your behavior from this class, you will get for free all the boring stuff:

  • Turning off Floower when the battery is low
  • Indicating the status of the battery
  • Watchdog Timer
  • Bluetooth pairing
  • Deep Sleep
  • Listening to touch events

So you can freely focus on the fun part – implementing what you need to do with Floower.

behavior/BloomingBehavior is a default romantic behavior. When you touch the leaf, it will bloom with a random color. If you browse the code, you will see it’s no rocket science. It’s just a simple state machine, changing the state every time the leaf is touched.

hardware/Floower is hardware abstraction, so you don’t need to care what your Floower is being packed with. When you need to move the petals, just call the setPetalsOpenLevel method, and it will do the magic. All the methods are hopefully self-explanatory.

BluetoothController provides a BLE interface for connecting your Floower with a mobile application. No need to care about this at all since the mobile app is closed software anyway.

Config stores and loads all the configuration and calibration values of your Floower. Like the name, serial number, touch sensitivity calibration, color scheme, and much more. It’s a single place to store persistent values between restarts. Don’t mess around here unless you want to introduce a breaking change into your code.

And finally, the main file is the entry point for the entire Flooware with an Arduino’s setup and loop functions. The code here is rather simple since the core functionality is implemented within the behaviors.

Never miss a new Make Blog post again

You can do it. Start coding. Now!

Hope this was helpful. I will add better documentation as the firmware mature. And I am going to showcase how to implement custom behavior in the next article. I am sure everything will click once you see how easy it is to overwrite the default behavior of Floower.

To begin visit the Fooware repository and read the instructions there. You will end up with firmware on your computer ready to be uploaded. So you can start customizing it.

Do you want to code but don’t have Floower yet? There is a simple solution! Get one!

Do you like my work?
Sdílej článek
Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on email
E-mail

Floower kvete po celém světě

Lidi jako ty už mají Floower doma.