|
Post by arcadetv on Feb 13, 2015 4:03:09 GMT -8
I'm displaying 4 rows with 5 rects on the screen. I tag them using GD.Tag and while one of them is touched I also display the Tag value for debugging. This is not doing what I want, what am I doing wrong?
Also when the GD.BlendFunc(ONE, ZERO); is active any Text that is displayed is boxed and not readable anymore, how can I revert the BlendFunc to normal/not blending?
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
int currentLine = 0;
void setup() { GD.begin(0); }
void loop() { GD.get_inputs(); GD.ClearColorRGB(0x000000); GD.Clear(); GD.cmd_gradient(0, 40, 0x5096fa, 0, 272, 0x62a1fb); GD.BitmapLayout(L8, 1, 1); //GD.BlendFunc(ONE, ZERO); GD.BitmapSize(NEAREST, REPEAT, REPEAT, 80, 40); GD.Begin(BITMAPS); int i = 0; for(int ry = 0; ry < 4; ry++){ for(int rx = 0; rx < 5; rx++){ GD.Tag(i); if(i == currentLine){ GD.ColorRGB(0,0,0); }else{ GD.ColorRGB(255, 255, 255); } int xpos = (rx*98)+5; int ypos = (ry*51)+5; GD.Vertex2ii(xpos, ypos); i++; } } if (GD.inputs.x != -32768) { currentLine = GD.inputs.tag; } GD.ColorRGB(0,0,0); GD.cmd_number(240, 230, 16, OPT_CENTERX, GD.inputs.tag); GD.swap(); }
|
|
|
Post by jamesbowman on Feb 13, 2015 16:28:22 GMT -8
I just ran it, and the issue is the GD.Begin. The zero argument means "do not initialize any extras". This means that the touchscreen does not get initialized.
Instead do:
GD.begin(GD_CALIBRATE); and it works fine.
To restore the blendfunc to its default, you can do either:
GD.BlendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA); or you can save/restore *all* the graphics state like this:
GD.SaveContext(); GD.BlendFunc(ONE, ZERO); ... GD.RestoreContext(); Oh, this code is sourcing a 1x1 pixel bitmap from address zero. This is unintialized at boot. Suggest adding something like this to set it:
GD.wr(0, 255);
|
|
|
Post by arcadetv on Feb 14, 2015 4:04:49 GMT -8
Great input! Thanks!! And it works ^^
|
|
|
Post by arcadetv on Feb 14, 2015 4:36:52 GMT -8
GD.wr(0, 255); There's no info on the "wr" method in the cookbook... What does it do?
|
|
|
Post by arcadetv on Feb 14, 2015 5:30:29 GMT -8
Giving back: For everyone who wants a simple multi-button-interface if you wanna control some hardware-stuff for example:
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
int currentLine = 0; const int totalLines = 20; int currentButton_touch = 1; int lastButton_touch = 0; void setup() { GD.begin(GD_CALIBRATE); }
int debounce_touch(int last_touch) { int current_touch = GD.inputs.tag; if (last_touch != current_touch) { delay(10); current_touch = GD.inputs.tag; } return current_touch; }
void loop() { GD.SaveContext(); GD.get_inputs(); GD.ClearColorRGB(0x000000); GD.Clear(); GD.cmd_gradient(0, 40, 0x5096fa, 0, 272, 0x62a1fb); GD.BitmapLayout(L8, 1, 1); GD.BlendFunc(ONE, ZERO); GD.BitmapSize(NEAREST, REPEAT, REPEAT, 80, 40); GD.Begin(BITMAPS); int i = 0; for(int ry = 0; ry < 4; ry++){ for(int rx = 0; rx < 5; rx++){ GD.Tag(i+1); if(i == currentLine){ GD.ColorRGB(0,0,0); }else{ GD.ColorRGB(255, 255, 255); } int xpos = (rx*98)+5; int ypos = (ry*51)+5; GD.Vertex2ii(xpos, ypos); i++; } } currentButton_touch = debounce_touch(lastButton_touch); if (GD.inputs.x != -32768 && currentButton_touch <= totalLines && currentButton_touch >= 0) { if (lastButton_touch != currentButton_touch){ currentLine = GD.inputs.tag-1; } } GD.RestoreContext(); i = 0; for(int ry = 0; ry < 4; ry++){ for(int rx = 0; rx < 5; rx++){ GD.Tag(i+1); if(i == currentLine){ GD.ColorRGB(255, 255, 255); }else{ GD.ColorRGB(0,0,0); } int xpos = (rx*98)+5; int ypos = (ry*51)+5; GD.cmd_number(xpos+40, ypos+12, 26, OPT_CENTERX, i+1); i++; } } GD.ColorRGB(0,0,0); GD.cmd_text(200, 220, 31, OPT_CENTERX, "Current Line: "); GD.cmd_number(350, 220, 31, OPT_CENTERX, currentLine+1); GD.swap(); }
|
|
|
Post by jamesbowman on Feb 14, 2015 15:32:36 GMT -8
Awesome. thanks. Did you see cmd_button() as a way of rendering buttons?
GD.wr(addr, b) writes a single byte value b to GD2 memory.
|
|