M2tklib + openGLCD. Low level graphics and M2_TOGGLE issues

Hi.

Since I got my ks0108 display working with openGLCD with my teensy 3.1 I've started to try to make a ui to control a stepper motor and ir-led to trigger a camer(panoramic photo shooter/photogramitry rig).

I found m2tklib and it seemed nice. Got a few things working. Like displaying lists and updating parameters like, turning speed, shots per revolution and so on, from buttons.

First issue:

I also wanted a progress bar when the rig is shooting photos. Since i didnt find any element in m2tk I tried to use low level graphics to produce the progress bar. All turned out ok except that the screen is flickering when changing a value or navigating between the inputs in the lists. Searched through the library and found that m2tklib uses GLCD.ClearScreen() when drawing(which i dont when I update my progress bar). How do I solve the flickering?

Second issue:

In the same sketch I want to start and stop the photo function some how and tried to use M2_TOGGLE to change the criteria to start the photo function. Navigating through lists and updating the other parameters work fine but when I toggle the M2_TOGGLE my application hangs/freezes.

This is what I came up with. I dont have the actual functions to control the motor and the camera implemented yet:

#include <openGLCD.h>
#include <multiCameraIrControl.h>
#include "M2tk.h"
#include "utility/m2ghopenglcd.h"
#include "fonts/System5x7.h"

//button pins
uint8_t uiKeyDownPin = 10;
uint8_t uiKeyNextPin = 11;
uint8_t uiKeyPrevPin = 12;
uint8_t uiKeyUpPin = 15;
uint8_t uiKeySelectPin = 14;

//settings
uint32_t microStepping = 0;
uint32_t shotsPerSweep = 0;
uint32_t shutterSpeed = 0;
uint8_t* shoot = 0;
uint8_t shoot2;

uint8_t progbar = 50;
uint32_t lastTime = 0;

boolean up = true;

void fn_ok(m2_el_fnarg_p fnarg){

}

// initialize list items
M2_LABEL(micro_stepping, "f0", "Micro stepping");
M2_U32NUM(el_micro_stepping, "a1c2", &microStepping);

M2_LABEL(shots_per_sweep, "f0", "Shots/sweep");
M2_U32NUM(el_shots_per_sweep, "a1c3", &shotsPerSweep);

M2_LABEL(shutter_speed, "f0", "Shutter speed");
M2_U32NUM(el_shutter_speed, "a1c3", &shutterSpeed);

M2_LABEL(shoot_sweep, "f0", "Shoot sweep");
M2_TOGGLE(el_shoot, "f0", shoot);

M2_BUTTON(el_ok, "", "ok", fn_ok);


M2_LIST(list) = {
	&micro_stepping,	&el_micro_stepping,
	&shots_per_sweep,	&el_shots_per_sweep,
	&shutter_speed,		&el_shots_per_sweep,
	&shoot_sweep,		&el_shoot
};

M2_GRIDLIST(list_element, "c2", list);


M2tk m2(&list_element, m2_es_arduino, m2_eh_2bs, m2_gh_openglcd_ffs);

void setup(){

	m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
	m2.setPin(M2_KEY_NEXT, uiKeyNextPin);

	Serial.begin(9600);

	m2.setFont(0, System5x7);

}

void loop(){

	m2.checkKey();
	if(m2.handleKey()){
		m2.draw();
	}

	//update progress bar, for progress bar test/debug.
	if((millis() - lastTime) > 200){
		lastTime = millis();
		if(up){progbar++;}
		if(progbar==100){up=false;}
		
		if(!up){progbar--;}
		if(progbar==0){up=true;}

		progressBar(1,1,126,8,progbar);
	}
}

void progressBar(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t progress){
	//create boarder progressbar

	//draw progressbar box
	GLCD.DrawRect(x,y,w,h);
	//clear old progress
	GLCD.FillRect(x+2,y+2,w-4,h-4,PIXEL_OFF);	
	//draw progress
	GLCD.FillRect(x+2,y+2,map(progress,0,100,0,w-2),h-4);

}

Later on i would like to change the layout a bit, but I read, somewhere on the forum, that openGLCD and m2tklib uses different coordinatesystems.

Also Im a noob at programming, still learning though :slight_smile:

Thanks in advance.

Hi

Let me start with the second problem:

uint8_t* shoot = 0;
...
M2_TOGGLE(el_shoot, "f0", shoot);

Although correct from a pure syntax perspective, there is a memory problem in the code. I would call this a typical C/C++ problem. M2_TOGGLE expects a variable to store the value (0 or 1). For this reason M2_TOGGLE expects the address of a variable. You do provide an address, but not a variable. Use this:

// define a variable
uint8_t shoot = 0;
...
// inform M2_TOGGLE about the address of "shoot"
M2_TOGGLE(el_shoot, "f0", &shoot);

The first problem is a general problem. m2.draw() redraws everything.In order to do so, everything must be cleared first. Maybe openGLCD includes a double buffer feature and allows rendering to RAM first.
Another option is to u8glib, which uses a different approach for drawing. But i currently do not know the status of u8glib regarding your board.

Oliver

Thanks for pointing(pun intended) out the solution to M2_TOGGLE.

As for the rendering problem, it doesnt really matter in my application but I wanted to know what caused it. I wont be updating any parameters that causes a m2.draw() during my progress bar.

I might check out u8glib later, if I change my mind about it :slight_smile:

Thank a lot!

flog,
I'm curious why you didn't use the bargraph function(s) in openGLCD?
The functions are quite flexible and should be able to do what you are wanting in terms
of drawing a bargraph.

Oliver,
In terms of double buffering in openGLCD, there isn't that capability. When the read-cache is enabled
there is a frame buffer, that could be written to and then flushed to the display but currently
there is no API to use the buffer or to do the flush. I've thought about adding some API functions
to allow using the read-cache buffer but it isn't there right now.
I've decided to defer that to a 2.x version of the library where everything will be re-factored
to better support other displays and features like multiple displays, changeable origins,
rotations, and scalable fonts.