Hi!
I don't know weather this is the right forum to post my question/problem, but I'll try my luck here. Basically, there is an issue with text positioning and I can't find out weather it's U8Glib related or it's just me. I'm writing a clock programm for Arduino, that displays a clock. It starts with an edit menu, where user can switch between 3 items: hours, minutes and OK button. Every selected item gets treated with a foreground color box and text is set to background color. Displaying a single text block with time and no boxes is not a problem, but once I separate every item (hours, colon sign in between, minutes, and a nice XBM icon) something goes worng when user select minutes for editing - there seems to be double rendering, where "unselected" minute view shows up slightli positioned to the left, which by the way it shouldn't. This is how it looks like: http://gusc.lv/stuff/fun/arduino_time.jpg the first number 5 is over the colon sign.
Here is my rendering code:
void viewMenuTime(){
// x, y coords, widht and height of a character
unsigned int x = 45, y = 5, w = 10, h = 17;
// small itoa() implementation
char hour[2] = {(timeH / 10) + 48, (timeH % 10) + 48};
char minute[2] = {(timeM / 10) + 48, (timeM % 10) + 48};
// Set Font
u8g.setFont(u8g_font_10x20);
// Set color to black
u8g.setDefaultForegroundColor();
// Draw icon
u8g.drawXBM(25, 9, clock_width, clock_height, clock_bits);
// Highlight hour spinner if selected
if (menuTimeItem == TIME_ITEM_HOUR){
u8g.drawBox(x, y, 20, 20);
u8g.setDefaultBackgroundColor();
}
// Draw hour numbers
u8g.drawStr(x, y + h, hour);
x += (w * 2);
// Reset color to black
u8g.setDefaultForegroundColor();
// Draw colon
u8g.drawStr(x, y + h, ":");
x += w;
// Highlight minute spinner if selected
if (menuTimeItem == TIME_ITEM_MINUTE){
u8g.drawBox(x, y, 20, 20);
u8g.setDefaultBackgroundColor();
}
// Draw minute numbers
u8g.drawStr(x, y + h, minute);
}
Some global definitions that might clear thins up:
#define TIME_ITEM_HOUR 0
#define TIME_ITEM_MINUTE 1
#define TIME_ITEM_OK 2
...
char timeH = 0;
char timeM = 0;
...
unsigned int menuTimeItem = TIME_ITEM_HOUR;
Render loop:
void loop(){
u8g.firstPage();
do {
viewMenuTime();
} while( u8g.nextPage() );
}
Could this be some rendering optimization issue?
Hardware:
Arduino Uno R3
DOGM132 display connected on the breadboard using the schematics from GitHub - olikraus/dogm128: Automatically exported from code.google.com/p/dogm128
4 push buttons (left, right, up, down) connected like http://arduino.cc/en/Tutorial/Button
Software:
Arduino IDE 1.0.1
U8Glib for drawing through SPI on DOGM display.