Giter Site home page Giter Site logo

gob52 / gob_unifiedbutton Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 192 KB

Add software touch buttons for CoreS3 and Tough, and commonality with conventional buttons (M5.BtnX)

Home Page: https://gob52.github.io/gob_unifiedButton/

License: MIT License

C++ 100.00%
m5gfx m5unified m5stack-cores3 m5tough

gob_unifiedbutton's Introduction

gob_unifiedButton

日本語

gob_unifiedButton

Overview

This library adds touch buttons on CoreS3, which does not have physical buttons or touch buttons, and enables the user to acquire the status via M5.BtnX.
Please use this as an interim feature until a similar feature is added to M5Unified in the future.
It is also useful for those who are making a common source for Basic, Gray, and Core2, as it does not process anything other than CoreS3.

Required libraries

M5Unified is assumed, so it cannot be applied to those using M5Core3.h.

How to install

Install in an appropriate way depending on your environment.

  • git clone or download zip, and extract into place
  • platformio.ini
lib_deps = gob/gob_unifiedButton
  • Use library manager on ArduinoIDE

How to use

#include <M5Unified.h>
#include <gob_unifiedButton.hpp>

goblib::UnifiedButton unifiedButton;

void setup()
{
    M5.begin();
    unifiedButton.begin(&M5.Display);
}

void loop()
{
    M5.update();
    unifiedButton.update(); // Must be call after M5.update. (Changed to call after M5.update() since 0.1.0)

    // M5.BtnX can be used to obtain status
    if(M5.BtnA.wasHold())
    {
        // ...
    }
    else if(M5.BtnA.wasClicked())
    {
        // ...
    }

    // Drawing Buttons
    unifiedButton.draw();
}

Button text font changes

You can configure which fonts can be used with M5GFX.

    unifiedButton.setFont(&fonts::Font4);

Appearance changes

You can specify it with begin or change it with changeAppearance.

Argument goblib::UnifiedButton::appearance_t Description
bottom Display buttons at the bottom of the screen (default)
top Display buttons at the top of the screen
transparent_bottom Transparent buttons on the bottom of the screen
transparent_top Transparent buttons on the top of the screen
transparent_all Transparent buttons are placed on the entire screen (three vertical sections)

Customize Buttons

You can get LGFX_Button*.

void setup()
{
    M5.begin();
    unifiedButton.begin(&M5.Display);

    auto btnA = unifiedButton.getButtonA();

    // Re-create buttons with unique shape, color, and text
    btnA->initButton(unifiedButton.gfx(), 40, 120, 80, 240 ,TFT_GREEN, TFT_BLUE, TFT_WHITE, "[A]");
    // Change label text
    btnA->setLabelText("Own");
}

Document

Can be created from a configuration file and shell script for Doxygen.
Output is to doc/html

bash doc/doxy.sh

or See also GitHub Pages

gob_unifiedbutton's People

Contributors

gob52 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

gob_unifiedbutton's Issues

M5 Tough

Hello,
I would like to use the lib with an M5Tough. For this I had to change line 27 in UnifiedButton::begin(LovyanGFX* gfx, const appearance_t app) function as follows:

 _enable = /*M5.getBoard() == m5::board_t::board_M5StackCoreS3 &&*/ M5.Touch.isEnabled();

This displayed the buttons and they changed colour when I clicked on them. However, conditions such as "M5.BtnA.wasHold()" were never true. I found out that this is probably due to line 1207 - 1209 in M5Unified.cpp (version 0.1.14) => M5.update()

    BtnA.setRawState(ms, btn_bits & 1);
    BtnB.setRawState(ms, btn_bits & 2);
    BtnC.setRawState(ms, btn_bits & 4);

The lib works at least if I comment out these lines. An alternative solution seems to be the execution of unifiedButton.update() BEFORE M5.update()

Is there a better way to solve the problem? I am also not clear why running unifiedButton.update() BEFORE M5.update() seems to be a solution.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.