Jump to content

ginput Toggle and event,How to use?


lijian100

Recommended Posts

Hello everyone!

Petition bright, I'm a newbie.I'm learning how to use ginput Toggle,


my "ginput_lld_toggle_board.h":
#define GINPUT_TOGGLE_NUM_PORTS            1            // The total number of toggle inputs
#define GINPUT_TOGGLE_CONFIG_ENTRIES    1            // The total number of GToggleConfig entries


#define GINPUT_TOGGLE_SW1                0            // Switch 1


#define GINPUT_TOGGLE_DECLARE_STRUCTURE()                                            \
    const GToggleConfig GInputToggleConfigTable[GINPUT_TOGGLE_CONFIG_ENTRIES] = {    \
        {GPIOM,                 /* Switch 1 */                 \
            PIN18,                                            \
            PIN18,                                            \
            1},}

 

my "ginput_lld_toggle_Pal.c":

#if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) /*|| defined(__DOXYGEN__)*/

#include "../../../../src/ginput/ginput_driver_toggle.h"

GINPUT_TOGGLE_DECLARE_STRUCTURE();

void ginput_lld_toggle_init(const GToggleConfig *ptc) {
    GPIO_Init(GPIOM, PIN18, 0, 1, 0);  // input AND pull_up
}

unsigned ginput_lld_toggle_getbits(const GToggleConfig *ptc) {
    return GPIO_GetBit(GPIOM, PIN18);  // get_bit 18
}

#endif /* GFX_USE_GINPUT && GINPUT_NEED_TOGGLE */

 

my "main.cpp":

//----------------------------uGFX_GINPUT_TOGGLE_TEST---------------------------
template<> OS_PROCESS void TProc1::exec()
{
    GEvent* event;
    static GListener pl;
    GSourceHandle upHandle = ginputGetToggle(GINPUT_TOGGLE_SW1);

    geventListenerInit(&pl);
    geventAttachSource(&pl, upHandle, GLISTEN_TOGGLE_ON|GLISTEN_TOGGLE_OFF);

  while(1)
    {
        gfxSleepMilliseconds(100); // uGFX_dalay
        sleep(200);                          // OS_dalay

        event = geventEventWait(&pl, 1000);
        if(event)
        T++;   // test1 is NG!

        if(GPIO_GetBit(GPIOM, PIN18))       
        T++;   // test2 is OK!
    }
}

 

After GIPIO switch, if(event) did not work.    if(GPIO_GetBit(GPIOM, PIN18)) Work properly,

How do I implement this test? 

Sorry for the above text translator's help to me, hope the description is clear,

thanks!

 

 

Link to comment
Share on other sites

  • 1 month later...
On 23/12/2021 at 14:10, lijian100 said:

After GIPIO switch, if(event) did not work.    if(GPIO_GetBit(GPIOM, PIN18)) Work properly,

Have a look at some of the application demos. You'd want to do something like this instead:

switch(event->type)
{
  case GEVENT_TOGGLE:
    // Here you know it's a toggle event
    // You can cast the event to GEventToggle* and retrieve information which toggle triggered the event and the true/false state
    break;
}

 

On 23/12/2021 at 14:10, lijian100 said:

Sorry for the above text translator's help to me, hope the description is clear,

No worries! We try our best to work together - Language has never been a problem 😉

Link to comment
Share on other sites

//=============================================
//In the main.c
//=============================================
void GfxTestTask(void *pvParameters) {

  GEvent *pe;
  gFont wFont;

  gfxInit();

  // Set the widget defaults
  wFont = gdispOpenFont(fontName);   //GOST_UI_215
  gwinSetDefaultFont(wFont);   //"UI2"
  gwinSetDefaultStyle(&CustomWidgetStyle, gFalse);

  GHandle ghEdit1 = createEditTextKey4x5("Edit1_4x5", 180, 22, 60, 20, 16);

  ghList1 = createListCheckbox("List1Checkbox", 64, 2, 110, 61);

    gwinAttachToggle(ghList1, 0, 1);//down //2
    gwinAttachToggle(ghList1, 1, 2);//up //4
    gwinAttachToggle(ghList1, 2, 3);//checked //8
    gwinAttachToggle(ghList1, 3, 4);//checked //8
}

//=============================================
ginput_lld_toggle_Pal.c
//=============================================

void ginput_lld_toggle_init(const GToggleConfig *ptc) {
  //palSetGroupMode(((IOBus *)ptc->id)->portid, ptc->mask, 0, ptc->mode);
}

//This is just for testing mode
//I have generate button pressing
unsigned ginput_lld_toggle_getbits(const GToggleConfig *ptc) {
  volatile unsigned int res = 0;
  if (g_test_button_event_counter++ > 40) {
    g_test_button_event_counter = 0;
  }

  switch (g_test_button_event_counter) {
    case 10:
      res = 8; //(1 << 3) - bit in the port
      break;
    case 20:
      res = 4; //(1 << 2) - bit
      break;
    case 40:
    case 50:
      res = 2;
      break;
    default:
      res = 0;
  }
  return res;
}

//============================================
//it is my new component, it is just copy from list.c
//list_checkbox.c
//I add role number 3
//============================================
// a toggle-on has occurred
static void ListCheckboxToggleOn(GWidgetObject *gw, gU16 role) {
  const gfxQueueASyncItem *qi;
  const gfxQueueASyncItem *qix;
  int i;

  gCoord iheight;
  gCoord iwidth;
  iheight = gdispGetFontMetric(gw->g.font, gFontHeight) + LST_CHECKBOX_VERT_PAD;
  switch (role) {
    // select down
    case 0:
      for (i = 0, qi = gfxQueueASyncPeek(&gw2obj->list_head); qi; qi = gfxQueueASyncNext(qi), i++) {
        if ((qi2li->flags & GLIST_FLG_SELECTED)) {
          qix = gfxQueueASyncNext(qi);
          if (qix) {
            qi2li->flags &= ~ GLIST_FLG_SELECTED;
            qix2li->flags |= GLIST_FLG_SELECTED;

            //if we need to scroll down
            if (((i + 2) * iheight - gw2obj->top) > gw->g.height) {
              gw2obj->top += iheight;
            }

            _gwinUpdate(&gw->g);
          }
          break;
        }
      }
      break;

      // select up
    case 1:
      qi = gfxQueueASyncPeek(&gw2obj->list_head);
      qix = 0;

      for (i = 0; qi; qix = qi, qi = gfxQueueASyncNext(qi), i++) {
        if ((qi2li->flags & GLIST_FLG_SELECTED)) {
          if (qix) {
            qi2li->flags &= ~ GLIST_FLG_SELECTED;
            qix2li->flags |= GLIST_FLG_SELECTED;

            if (((i - 1) * iheight) < gw2obj->top) {
              gw2obj->top -= iheight;
              if (gw2obj->top < 0)
                gw2obj->top = 0;
            }

            _gwinUpdate(&gw->g);
          }
          break;
        }
      }
      break;
    case 2://This one
      qi = gfxQueueASyncPeek(&gw2obj->list_head);
      qix = 0;

      for (i = 0; qi; qix = qi, qi = gfxQueueASyncNext(qi), i++) {
        if ((qi2li->flags & GLIST_FLG_SELECTED)) {
          qi2li->flags ^= GLIST_FLG_CHECKED;
          if (qi2li->keyActions.Enter.keyFunct) {
            qi2li->keyActions.Enter.keyFunct(1, gTrue);
          }
          _gwinUpdate(&gw->g);
          break;
        }
      }
      break;
  }
}

static void ListCheckboxToggleAssign(GWidgetObject *gw, gU16 role, gU16 instance) {
  if (role == 1)
    gw2obj->t_up = instance;
  else if (role == 0)
    gw2obj->t_dn = instance;
  else if (role == 2)
    gw2obj->t_check = instance;//This one
}

static gU16 ListCheckboxToggleGet(GWidgetObject *gw, gU16 role) {
  if (role == 1)
    return gw2obj->t_up;
  else if (role == 0)
    return gw2obj->t_dn;
  else if (role == 2)
    return gw2obj->t_check;//This one

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...