When does setup() run?

When does setup() run? Specifically, will setup() run while the computer is being used, if the computer sleeps, the user logs out, the computer restarts, the computer shuts down, if the cable is unplugged, or when?

I would like to be able to have Keyboardio be QWERTY when someone unplugs it and plugs it back in, but to stay COLEMAK after I change it to COLEMAK. Right now it’s set up so I can switch to QWERTY and back again using leader key sequences, but COLEMAK is the default. I’m thinking about how the keyboard can be easy for other people to use on occasion. It seems like the best way for that to work is to say “I use a different keyboard layout, just plug unplug it and plug it back in and it will work the way you expect it to;” or “plug it in to your laptop and try it out.”

setup() runs whenever the keyboard “boots”, which usually happens when you plug it in, or after you’ve reset it. It does not run when the computer resumes from sleep, nor when the user logs out (unless logging out cuts power from the keyboard). Restarting the computer, shutting it down, plugging the cable out all cut power, and setup() will run when you turn the computer on or plug the cable back in.

So if you default to QWERTY, but change to COLEMAK with a Leader sequence, it will stay in COLEMAK until you reboot your computer or re-plug your keyboard (in which cases, it will go back to the default QWERTY).

As an additional data point: setup() does not run if you cut and then reattach the USB connection from software (either on the host or on the firmware side), but keep powering the keyboard.

Thank you. That is how I hoped it would work.

My set up is a bit of a mess. I’m going to re-install the latest standard Keyboardio firmware and set everything up the way I like it again, but in a neater and more organized way this time. There isn’t a major upgrade coming up really soon, is there? If that were the case I might want to wait—but no more than a few weeks.

We have a major upgrade behind us :slight_smile:

There are going to be some big changes coming soon-ish, to the MagicCombos, Focus and EEPROM-Settings plugins. If you aren’t using those, there’s no reason to wait. If you are, migration will be quite easy too.

Btw. is there any guide on how to update existing plugins to the new system?

This is the closest thing we have for an upgrade guide:

It may or may not be enough. If it isn’t, please ask, and we’ll try to help and improve the documentation too.