sqfmi / Watchy

Watchy - An Open Source E-Ink Smartwatch
http://www.sqfmi.com
MIT License
1.85k stars 322 forks source link

Allow watch faces to implement custom handleButtonPress functions #165

Closed synthead closed 2 years ago

synthead commented 2 years ago

This PR allows users to implement custom implementations for handleButtonPress!

For example, with the changes in this PR, I could do:

void WatchyKeen::handleButtonPress() {
  pinMode(VIB_MOTOR_PIN, OUTPUT);

  digitalWrite(VIB_MOTOR_PIN, HIGH);
  delay(50);
  digitalWrite(VIB_MOTOR_PIN, LOW);

  Watchy::handleButtonPress();
}

This example gives a "tactile" effect for every button press by doing two things:

These changes are backward-compatible: if a watch face does not implement handleButtonPress, then there will be no functional changes with any watch face.

In addition, calling Watchy::handleButtonPress() from the user's own handleButtonPress function will make the watch perform its regular functions with the original buttons. However, if the user would like to have their own menu, for example, they don't need to always call Watchy::handleButtonPress(). This could look like this:

bool inMyMenu = false;

void WatchyKeen::handleButtonPress() {
  if (!inMyMenu && buttonPressed == myMenuButton) {
    inMyMenu = true;
  }

  if (inMyMenu) {
    // perform your own tasks here
    // set inMyMenu to false when you're done
  } else {
    Watchy::handleButtonPress();
  }
}

Other examples of how this could be implemented:

synthead commented 2 years ago

I actually kinda like https://github.com/sqfmi/Watchy/pull/164 more, since it's more straight-forward and has the potential to cause less problems :slightly_smiling_face: I'm going to close this PR in favor of https://github.com/sqfmi/Watchy/pull/164 :+1: