Cannot canvas.drawString() onto canvas. (M5PaperTouchArea)
-
I have made a small modification to RAWSEQ'sexcellent M5PaperTouchArea project.
I am trying to use the spare white area as an output canvas. I can place the CanvasOP (output canvas) correctly and I can check it is really there by filling it in different shades and moving it around. but I cannot write into it. Any canvasOP.drawString() commands seem to be ignored. I have tried changing the text color, size and position but I cannot seem to get text to show up on the pushed canvasOP.
#include <M5EPD.h> #include "M5PaperTouchArea.h" #include "MPlusFontsSubset.h" // M5EPD Canvas M5EPD_Canvas canvas(&M5.EPD); M5EPD_Canvas canvasOP(&M5.EPD); // Module (Grid & TouchArea) M5PaperTouchAreas _m5pta; // Module (Grid Only) GridUtil _gu; void setup() { // Display Setup M5.begin(); M5.EPD.SetRotation(90); M5.TP.SetRotation(90); M5.EPD.Clear(true); canvas.loadFont(MPlusFontsSubset, sizeof(MPlusFontsSubset)); canvas.createCanvas(540, 960); canvas.createRender(48, 256); canvas.fillRect(0, 0, 540, 960, 10); _m5pta.current_canvas = &canvas; _m5pta.getGutil()->setVertical(true); _gu.setVertical(true); // Event Setting _m5pta.e_touch.func = bTouch; _m5pta.e_release.func = bRelease; // Change Default Setting _m5pta.default_font_size = 48; _m5pta.default_radius = 15; _m5pta.default_font_linepos = 6; _m5pta.default_bc = { 13, 0, 0 }; // Touch Area Test _m5pta.add_grid(1, 1, 1, 1, "B1", "b1"); _m5pta.add_grid(2, 1, 1, 1, "B2", "b2"); _m5pta.add_grid(3, 1, 1, 1, "B3", "b3"); _m5pta.add_grid(4, 1, 1, 1, "B4", "b4"); _m5pta.add_grid(5, 1, 1, 1, "B5", "b5"); _m5pta.add_grid(1, 2, 3, 1, "B6", "b6"); _m5pta.add_grid(4, 2, 2, 1, "B7", "b7"); _m5pta.add_grid(1, 3, 2, 1, "B8", "b8"); _m5pta.add_grid(3, 3, 3, 1, "B9", "b9"); _m5pta.add_grid(1, 4, 5, 1, "B10 Steve", "Steve"); _m5pta.add_grid(1, 5, 2, 1, "B11", "b11"); //_m5pta.add_grid(3, 5, 3, 2, "B16", "b16");//added by steve _m5pta.add_grid(1, 6, 2, 2, "B12", "b12"); _m5pta.add_grid(3, 7, 3, 3, "B13", "b13"); _m5pta.add_grid(1, 8, 2, 1, "B14", "b14"); _m5pta.add_grid(1, 9, 2, 1, "B15", "b15"); _m5pta.draw(); // Grid Draw Test // GURect g = _gu.convert(3, 5, 3, 2); // canvas.setTextColor(10); // canvas.fillRect(g.x, g.y, g.w, g.h, 0); canvas.pushCanvas(0, 0, UPDATE_MODE_GC16); /* Serial.print(g.x); Serial.print("..."); Serial.print(g.y); Serial.print("..."); Serial.print(g.w); Serial.print("..."); Serial.print(g.h);*/ //230...440...290...180 g.cordinates canvasOP.createCanvas(290, 180); //canvasOP.fillCanvas(5); canvasOP.setTextSize(4); canvasOP.setTextColor(15); canvasOP.drawString("Hello", 20, 100); canvasOP.pushCanvas(230, 440, UPDATE_MODE_GC16); } // Touch Event void bTouch(M5PTAEventContext& ct) { Serial.println("T:" + ct.code); } // Release Event void bRelease(M5PTAEventContext& ct) { Serial.println("R:" + ct.code); } void loop() { _m5pta.loop(); } -
I am just starting out with the M5Paper and a lot of things are taking some getting use to. I thought about deleting this thread when I found out how easy the solution was but then I thought that maybe this will help someone else. So here is the solution:
You have to declare a font for use in the canvasOP. So adding his line after creating canvasOP fixes the problem:
canvasOP.setFreeFont(&FreeSerif24pt7b);
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login