Jump to content

Recommended Posts

Posted

I have a project where i draw a graph from a coil current (which is non linear) and want to point to a position with a touch panel and get the graph point (x,y) back to make some calculations.

I already have display, graph, slider, touchpad,... working with the help of the samples. What would be the way to go? Is there an output from the graph window i can use or do i have to write something new?

Thank you.

2018-02-15_11_17_22.jpg

Posted

No need to write something new. In your main loop before calling geventWait you can obtain the mouse source and attach it to the listener. That way you will get a copy of all mouse events and you can find when it is pressed over the graph. As an example look at code in the touch test tool (under the tools directory).

Posted

For more complex things you might want to copy the existing graph widget (which is a window) and make it become a widget. The difference between windows, widgets and containers are explained in the GWIN section of the wiki. The main difference that is helpful for you here is that a widget can process user input (eg. it gets touch events) and that it can redraw itself.

Posted

Thank you for your feedback.

Ok. The redraw feature is certanly nice.

For now i came up with this:

Setup:

  GHandle     gh;
  uint16_t    i;
  font_t    font1;

  gfxInit();
  font1 = gdispOpenFont("UI2");
  gwinSetDefaultFont(font1);

  // Create the graph window
  {
      GWindowInit wi;

      wi.show = TRUE;
      wi.x = wi.y = 0;
      wi.width = gdispGetWidth();
      wi.height = gdispGetHeight()/2;
      gh = gwinGraphCreate(0, &wi);
  }
  gdispClear(Black);
   // Set the graph origin and style
   gwinGraphSetOrigin(gh, 0, gwinGetHeight(gh)/2);
   gwinGraphSetStyle(gh, &GraphStyle1);
   gwinGraphDrawAxis(gh);
   for(i = 0; i < gwinGetWidth(gh); i++) {
     gwinGraphDrawPoint(gh, i, data[i]*0.85);
   }
   {
       GWindowInit     wi;

       gwinClearInit(&wi);
       wi.show = TRUE;
       wi.y = (gdispGetHeight()/2) + 40;
       wi.x = 0;
       wi.width = gdispGetWidth();
       wi.height = (gdispGetHeight()/2) -40;
       ghConsole = gwinConsoleCreate(0, &wi);
   }

   gwinSetColor(ghConsole, Green);
   gwinSetBgColor(ghConsole, White);
   gwinClear(ghConsole);
   ginputGetMouse(0);

In a while(1) loop:

    ginputGetMouseStatus(0, &ev);

    if(DRAW_AREA(ev.x, ev.y) && ((ev.buttons & GINPUT_MOUSE_BTN_LEFT))){
      gwinPrintf(ghConsole, "X: %u, Y: %u SIN: %d\n", ev.x, ev.y, data[ev.x]);
    }

DRAW_AREA is the size of my graph window, data[] is my array of sine points.

But i will look again at the touch_driver_test and also how to make a widget from a window. But for now this all sound really overwhelming.

Then again when you get the hang of it uGFX rocks!

2018-02-15_15_55_48.jpg

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...