sqfmi / Watchy

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

add basic button support #164

Open bushmango opened 2 years ago

bushmango commented 2 years ago

I added basic support for handling three of the four buttons when the watch is in Watchface mode.

This can be an example for others, or I'm happy to modify to make it part of the core base, as it is nice to use the buttons to change settings on some watchfaces.

Enjoy! Thanks for the fun product.

synthead commented 2 years ago

Oh hey interesting! It looks like we were both thinking the same thing! I also just submitted https://github.com/sqfmi/Watchy/pull/165 :smile:

I think your PR has an interesting implementation, because it lives alongside core functionality without overriding anything. Ultimately, both changes can be merged without conflicts, which would give users the option to override specific buttons, or the implementation as a whole.

How would you feel about also adding a fourth button function, and putting showMenu(menuIndex, false); in it by default? That way, the user could even conditionally override the default behavior of pulling up the menu, if they wanted.

Also, how would you feel about following the existing function names a little closer, and calling them something like Watchy::handleButton1Press?

synthead commented 2 years ago

Also, how about following the button numbers in the Getting Started doc?

image

bushmango commented 2 years ago

I like all of this feedback, I was wondering what to call the buttons.

It does make sense to let the user override the menu even if normally they shouldn't 😛

On Thu, May 12, 2022, 6:27 AM Maxwell Pray @.***> wrote:

Also, how about following the button numbers in the Getting Started doc?

[image: image] https://user-images.githubusercontent.com/820984/168064421-d470830a-3877-47d5-8df8-725c58486c59.png

— Reply to this email directly, view it on GitHub https://github.com/sqfmi/Watchy/pull/164#issuecomment-1124875599, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACAM657QNVL5VS4TGUXJZFDVJTTILANCNFSM5VWMS7WA . You are receiving this because you authored the thread.Message ID: @.***>

aneeshdurg commented 2 years ago

This is my 2 cents - maybe instead of referrng to buttons by numbers in the functions names we could refer to buttons by their default functionality? e.g. handleButtonBackPress, handleButtonMenuPress, handleButtonUp/DownPress

Really like this approach though! :heart:

JollyWizard commented 1 year ago

This is my 2 cents - maybe instead of referrng to buttons by numbers in the functions names we could refer to buttons by their default functionality? e.g. handleButtonBackPress, handleButtonMenuPress, handleButtonUp/DownPress

Really like this approach though! heart

This would create confusion if the dev/user wanted to swap the handedness of the watch. It would be more appropriate to use a clear coordinate naming system, such as handleButtonUpperLeft, handleButtonUpperRight, handleButtonLowerLeft, handleButtonLowerRight.

This also creates a coherency issue with vertical flips, but is tied semantically to the physical orientation of the device, without making unnecessary assumptions about use case.

edent commented 1 year ago

Is it possible to use this to update the watch face? I've updated the .cpp and .h file with the handleButton2Press(); etc code. If I add something like this to my code:

 void handleButton2Press(){
          pinMode(VIB_MOTOR_PIN, OUTPUT);
          digitalWrite(VIB_MOTOR_PIN, true);
          delay(150); 
          digitalWrite(VIB_MOTOR_PIN, false);
}

Then the Watchy vibrates when I press the button. But how can I get the display to change when a button is pressed?

Code like this doesn't work:

void handleButton4Press(){ 
          display.fillScreen(GxEPD_WHITE);
          display.setTextColor(GxEPD_BLACK);
          display.setFont(&latin8pt7b);

          display.setCursor(0, 10);
          display.println("Button 4 Pressed!");
}

Is there something else I need to do to get the screen to update?

amsam0 commented 10 months ago

@edent judging from this line of code:

https://github.com/sqfmi/Watchy/blob/master/src/Watchy.cpp#L610

display.display() (WatchyDisplay::refresh()?) needs to be called for the display to update