davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

openvg (Paeryn, ajstarks)

Wed Dec 30, 2015 1:27 pm

hello again... :)

a question about the #includes which are now finally needed for openvg (seperately for Paeryn fork + ajstarks)
I currently use for both versions

#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"

is there one or the other #include which can be securely dropped?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Wed Dec 30, 2015 4:48 pm

If you are still using the libshapes library (either ajstarks' original or my fork) then #include "shapes.h" is needed as that contains all the definitions required for that library.

As long as you are including shapes.h then you don't technically need to include the other three as the first three lines of shapes.h include them for you. However some people - myself included - like to explicitly include headers that contain things they are using just to make sure (the header file that includes others might change to not include them, or I might decide to not include that one but still require the ones it included).

Generally header files that are likely to be included multiple times in one go have an #ifdef / #endif block around the whole file that prevents it being parsed multiple times (and gcc recognises when header files do that so it doesn't even bother re-reading them).

If you really want to remove an include you could always try deleting it / commenting it out. If the compile fails then you needed it so put it back in.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Wed Dec 30, 2015 5:08 pm

hey,
thanks!
- But of course I tried already one or the other #include to comment out or not but didn't examine too many effects to my programs - if any. Nevertheless, I could not be sure of being able to detect all possible and conceivable errors or failures then, e.g. for "fontinfo.h" or "VG/vgu.h" - that's why I asked. :)
As libshapes are supposed to provide all the geometric figures, it surely will be essential.
OTOH, I actually don't appreciate to have a list of #included header files at the start of my proprietary code which is long enough to fill up the entire British Library (or perhaps, even more likely, actually the whole Encyclopedia Galactica :shock: ).

So I considered shortening down the header file list to something of a common Chinese restaurant's menu card size to be a bit more handsome, that's why I asked... :P
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Wed Dec 30, 2015 6:50 pm

If you've got too many include lines in one file then perhaps you could split your code up better. It's much easier to have many small files each concentrating on one (or a few) small parts than it is to have one / few huge files doing everything. Even if you do need loads of them, they are all at the top of the file out of the way.

Generally, if you don't include a header file that contains information that the compiler needs then your program won't compile. Off-hand I can't really think of many cases where you can get away with not including headers, the only one I can gcc will give you a warning (implicit function declaration if you try using a function from another file without including the relevant header that declares it).
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Wed Dec 30, 2015 7:05 pm

thanks, Paeryn,
I have already a little experience in C coding by my Arduino experiments - Arduino is doing most of the standard file #includes by it's own Java-based Wiring/Processing IDE.
Anyway, for "real" embedded C coding my skills are quite poor FTM, and so I'm still sort of struggling with some Linux based problems I have not encountered so far.
For the Arduino IDE, for lack of nested #include features, I coded in 1 single file with very few #includes, but my source code partially exceeded 3000 lines and more and so run into kind of "complexity". Now I will split them, accepting even more #includes, so I will decrease the current ones to as few as possible.
Additionally, I am writing a blog in our MINDSTORMS Forum about my Raspi experiences to become a Quick Guide for Newbies to C coding featured by Geany, and for that purpose I try to keep things as simple as possible.
Currently I am re-working the paragraph about Paeryn's and ajstark's openvg libs. :)
Although it's written in German - share and enjoy.
http://www.mindstormsforum.de/viewtopic ... 689#p67838 8-)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Wed Dec 30, 2015 7:58 pm

about adding new fonts:

I'm still clueless how to generate new fonts. Although a description is provided, I'm not clear about how to follw the instructions - a little assistance would be very much appreciated... ;)

e.g., I found the following digital_7 font which mimics LED displays (perhaps there are even better ones out in the http://www...):
digital_7.zip
(37.47 KiB) Downloaded 49 times
next I assume I have to copy it into the folder
/usr/share/fonts/truetype/
and then write in LX terminal

Code: Select all

./font2openvg   /usr/share/fonts/truetype/ttf-dejavu/digital-7.ttf    digital-7.inc   digital-7

is that correct?
then, is that all what Ihave to do to subsequently may use this font in my C programs by

Code: Select all

#include "digital_7.inc"
Fontinfo digital_7
//...
Text( x, y, strbuf, digital_7, 10); 
... or are there now additional steps to do like e.g., using loadfonts?

I'm a little scared about messing all up in the Linux and the openvg installation, so I'm addmittedly (perhaps) overly cautious before manipulating things I don't understand clearly...
Last edited by davenull on Wed Dec 30, 2015 10:44 pm, edited 1 time in total.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Wed Dec 30, 2015 8:56 pm

You're nearly there. You can't have the dash in the name at the end of the font2openvg command (that's what it uses to generate variable names and dashes aren't allowed) though you seem to have used an underscore in the source code so I'll show it with that, plus you don't need to copy the font to the system font directory unless you want it to be available for use on the desktop.

Code: Select all

./font2openvg digital-7.ttf digital-7.inc digital_7
Your code looks okay, but you need to load the font at the start of the program after the init() call, and unload it just before the finish() call

Code: Select all

    init();
    digital_7 = loadfont(digital_7_glyphPoints,
			digital_7_glyphPointIndices,
			digital_7_glyphInstructions,
			digital_7_glyphInstructionIndices,
			digital_7_glyphInstructionCounts,
			digital_7_glyphAdvances,
			digital_7_characterMap,
			digital_7_glyphCount);
...
    unloadfont(digital_7.Glyphs, digital_7.Count);
    finish();
The digital_7 part at the start of the variable names in the function calls comes from the last parameter that you passed to font2openvg.

So complete example using it

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"
//#include "paintcache.h"

#include "digital-7.inc"

Fontinfo digital_7;

int main() {
    int width, height;
    char s[3];

    // Request a window size of 600x360 with top-left at 20,20
    initWindowSize(20, 20, 600, 360);
    init(&width, &height);                  // Graphics initialization
    digital_7 = loadfont(digital_7_glyphPoints,
			digital_7_glyphPointIndices,
			digital_7_glyphInstructions,
			digital_7_glyphInstructionIndices,
			digital_7_glyphInstructionCounts,
			digital_7_glyphAdvances,
			digital_7_characterMap,
			digital_7_glyphCount);

    Start(width, height);                   // Start the picture
    Background(0, 0, 0);                    // Black background
    Fill(44, 77, 232, 1);                   // Big blue marble
    Circle(width / 2, 0, width);            // The "world"

    Fill(255, 255, 255, 1);                 // White text
    TextMid(width / 2, height / 2, "hello, world 1234", digital_7, width / 10);  // Greetings 
    End();                                  // End the picture
    fgets(s, 2, stdin);                     // look at the pic, end with [RETURN]
    unloadfont(digital_7.Glyphs, digital_7.Count);
    finish();                               // Graphics cleanup

    return 0;
}
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Wed Dec 30, 2015 10:58 pm

thank you for your input!
1st, about digital-7 and digital_7: what about just renaming all the digital-7*.* fonts to digital_7*.* ?

2nd, - no nitpicking ! - it's (frankly) looking very complicated.
Wouldn't there be an easier way to include additional fonts, e.g. just by sort of

#include digital_7.ttf
#include Helvetica.ttf
#include windings.ttf
#include symbol.ttf
#include Courier.ttf
(or kind of initfont() instead of #include or whatever)
maybe providing some wraps around already existing libs and API functions, letting the compiler do the minor nitty details?)

(I admit I don't know how the fonts work, maybe even more convenient:
somehow like Windows is using *.ttf fonts automatically if they once have been copied to c:\Windows\fonts and provides them, just in the moment "they are there"?).

But all this clump of code:

#include "digital_7.inc"
Fontinfo digital_7

init();
digital_7 = loadfont(digital_7_glyphPoints,
digital_7_glyphPointIndices,
digital_7_glyphInstructions,
digital_7_glyphInstructionIndices,
digital_7_glyphInstructionCounts,
digital_7_glyphAdvances,
digital_7_characterMap,
digital_7_glyphCount);
...
unloadfont(digital_7.Glyphs, digital_7.Count);
finish();

- already for 1 single font big enough to sink a ship, but all that even multiple additionally, each for either additional font, then even desastrous for the entire Royal Navy ... :o
that should be able to be simplified, what do you think? 8-)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Thu Dec 31, 2015 12:43 am

davenull wrote:thank you for your input!
1st, about digital-7 and digital_7: what about just renaming all the digital-7*.* fonts to digital_7*.* ?
Having the dash in the filename is ok but if you'd prefer to change it then that's fine, it's just the variable names that can't have dashes in them (as C would interpret it as subtracting 7 from digital).
davenull wrote:2nd, - no nitpicking ! - it's (frankly) looking very complicated.
Wouldn't there be an easier way to include additional fonts, e.g. just by sort of

#include digital_7.ttf
#include Helvetica.ttf
#include windings.ttf
#include symbol.ttf
#include Courier.ttf
(or kind of initfont() instead of #include or whatever)
maybe providing some wraps around already existing libs and API functions, letting the compiler do the minor nitty details?)
Yes, font handling could be better, it's next on my to-do list. Ideally I'll end up with something simple like

Code: Select all

helvetica_font = loadfont("Helvetica");
though it may be a little bit more involved, definately I'll get rid of having to convert the font and allow dynamic loading rather than the current method of having to embed the font in the program.

At the moment I'm playing around with caching paints (colours) and allowing you to name them. At the moment it allows using strings as names (has the 148 or so predefined that the go version has defined), currently I have working functions like

Code: Select all

SetPaintName("grey", 127, 127, 127, 1);
FillByName("red");
But I might give up on string names, the overheads are costly and aren't that useful.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Thu Dec 31, 2015 8:18 am

ok, that sounds very promising!
anyway, did you recognize that I already made a list of "full color names" derivated from a standardized color list?
http://www.december.com/html/spec/colordeccompact.html

IMO color names are very intuitive and so perfect for quick implementing (and remembering) - finally, who is supposed to remember after a few months when reworking old code which color once was
135, 38, 87
or what kind of "violet" once had been taken in another code for a certain "violet" which one now wants to mimic?

I would gladly share it and would be very happy if you implemented my list into your libs to be available to everybody :)

Code: Select all

// decimal Color Codes

#define RED         255,  0, 0
#define SIGNRED     175, 30, 45
#define STRAWBERRY  190, 38, 37
#define RASPBERRY   135, 38, 87

#define MAGENTA     255,  0, 255
#define DARKMAGENTA 139,  0, 139
#define ROSE        255,  0, 204
#define PURPLE      160, 32, 240
#define PINK        255, 192, 203
#define DEEPPINK    255, 20, 147

#define YELLOW      255, 255, 0
#define SIGNYELLOW  255, 209, 22
#define LIGHTYELLOW 255, 255, 224
#define PAPAYA      255, 255, 126
#define PEACH       254, 240, 219
#define COPPER      184, 115, 51
#define LIGHTCOPPER 237, 195, 147
#define GOLD        255, 215, 0
#define ORANGE      255, 102, 0
#define SIGNORANGE  221, 117, 0
#define TANGERINE   255, 114, 22
#define SALMON      250, 128, 114
#define APRICOT     251, 161, 108

#define LIME          0, 255, 0
#define SIGNGREEN     0, 107, 87
#define GREEN         0, 128, 0
#define LIGHTGREEN  144, 238, 144
#define DARKGREEN    47,  79, 47
#define MINTGREEN   189, 252, 201

#define CYAN          0, 255, 255
#define LIGHTCYAN   224, 255, 255

#define BLUE          0,   0, 255
#define SIGNBLUE      0,  63, 135
#define DARKBLUE      0,   0, 139
#define NAVY          0,   0, 128
#define ULTRAMARINE  18,  10, 143
#define SKYBLUE     135, 206, 235
#define LIGHTBLUE   173, 216, 230
#define BLUEBERRY   117, 161, 208
#define AQUA        102, 204, 204
#define AQUAMARINE  112, 219, 147
#define VIOLET      143,  94, 153
#define WILDVIOLET  130,  11, 187

#define BROWN       128,  42, 42
#define SIGNBROWN    96,  51, 17
#define OCHRE       204, 119, 34
#define BRONZE      140, 120, 83

#define BLACK         0,  0,  0
#define WHITE       255, 255, 255
#define GRAY25       64,  64, 64
#define GRAY50      127, 127, 127
#define GRAY75      191, 191, 191
#define LIGHTGRAY   211, 211, 211
#define SILVER      192, 192, 192
usage:

Code: Select all

Stroke(RED, 1);
Fill (VIOLET, 0.3);
Last edited by davenull on Thu Dec 31, 2015 9:37 am, edited 1 time in total.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: openvg (Paeryn, ajstarks)

Thu Dec 31, 2015 8:34 am

/etc/X11/rgb.txt :roll:
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Thu Dec 31, 2015 8:47 am

/etc/X11/rgb.txt :roll:
PeterO
What should that mean?
could you please be a little more kind of "extensive" ...?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
rpdom
Posts: 15191
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: openvg (Paeryn, ajstarks)

Thu Dec 31, 2015 12:03 pm

davenull wrote:
/etc/X11/rgb.txt :roll:
PeterO
What should that mean?
could you please be a little more kind of "extensive" ...?
It's a file. Have a look at it. The contents should be fairly obvious from the name.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Thu Dec 31, 2015 12:52 pm

perhaps this needs to be reworked for #defines but then I'm curious why it not already has been integrated into openvg so far?
Finally no newbies (at all) - but at least advanced users are supposed to know about this list... :roll:
Anyway, paeryn or ajstarks surely will know how to integrate either list. Gladly looking forward to it... 8-)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Thu Dec 31, 2015 2:10 pm

As far as openvg is concerned why should they define a bucket load of colour names when there are plenty out there to use. The way ajstarks did paint handling in libshapes is a bit off, he discards the paint straight away so if you want to use the same colour later you have to recreate it, whereas normally if you know you need the same colour later you would keep the paint. That's why I was adding paint caching.

I personally find some of the colour names to be misleading, grey is 50% white but darkgrey is 66% white!
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Thu Dec 31, 2015 2:26 pm

that's right, I would assume a grey50 for "grey" or "gray":

#define GRAY25 64, 64, 64
#define GRAY50 127, 127, 127
#define GRAY75 191, 191, 191
#define LIGHTGRAY 211, 211, 211
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Fri Jan 01, 2016 1:10 pm

hey'all and a Happy new year!

1 question about openvg arguments, e.g.
void RectOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h)

why are the variable types for argumets called VGfloat and not just float?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Fri Jan 01, 2016 1:41 pm

davenull wrote:hey'all and a Happy new year!

1 question about openvg arguments, e.g.
void RectOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h)

why are the variable types for argumets called VGfloat and not just float?
Happy new year.
VGfloat is used to make sure that it is the correct float type no matter what platform/compiler is used. Normally it's just a simple typedef for float, but C doesn't specify the exact properties of float so if a compiler/platform uses something other than IEEE754 single-precision for float then VGfloat would be defined differently.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Fri Jan 01, 2016 1:45 pm

so given I had on either platform
double x,y,height, width;
- would there be an implicite typecasting in case of passing double values e.g., to RectOutline() ?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Fri Jan 01, 2016 2:04 pm

Yes, doubles will be converted to floats by the compiler before passing them to the functions that expect floats. You might get warnings about loss of precision, ideally you should explicitly cast doubles to floats rather than relying on the compiler doing it.
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Fri Jan 01, 2016 2:20 pm

that's fine, thank you very much!
so I can be secure that it will work with either float precision having been declared before 8-)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Sat Jan 02, 2016 8:38 pm

I have now restored my old code for UART communication using the former paeryn openvg enhancement libs.
but it doesn't work any longer.
I changed everything I could find but here I'm clueless:

Code: Select all

/*     Tx master 
 *     Raspberry Pi  
       ver 0006.4       
 */
 
// (C) Helmut Wunder (HaWe) 2015
// protected under the friendly Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// http://creativecommons.org/licenses/by-nc-sa/3.0/
 

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <pthread.h>

#include "fontinfo.h"
#include "shapes.h"

#include <wiringPi.h>
#include <wiringSerial.h>

#define  byte  uint8_t

char   * uart  =  "/dev/ttyAMA0";
int    Serial1;

 
//=====================================================================================
//  timer
//  millis() and micros() by wiringPi lib!


//=====================================================================================
// openvg + shapes_plus

int _scrwidth_, _scrheight_;

#define   cls()       Background(0, 0, 0);   

int      _fontsize_ = 20;

inline void lcdprintxy(float x, float y, char * buf) {
   Text(x, y, buf, MonoTypeface , _fontsize_);
}


void vgInitgraph() {
    initWindowSize(0,0, 600,360);     // Graphics initialization

    Start(_scrwidth_, _scrheight_);   // Start the picture
    cls();   
   
    Stroke(255, 255, 255, 1);  // Set these at the start, no need to   
    Fill(255,255,255, 1);      // keep calling them if colour hasn't changed

}



//=====================================================================================
// debug monitor

void displayvalues(int line, char * caption, uint8_t array[]) {
  int cnt;
  char sbuf[128];
 
  sprintf(sbuf, "%s cks=%-4d", caption, array[1]);
  //lcdprintxy(0, line, sbuf);
  printf(sbuf); printf("\n");
  for(cnt=0; cnt<8; ++cnt) {
    sprintf(sbuf, "%3d ", array[cnt]);      // print on TFT
    lcdprintxy(cnt*3*8, line+10, sbuf);
    printf(sbuf);
  }   
  printf("\n");
 
}

//=====================================================================================
//=====================================================================================
// serial com


const    uint8_t  MSGSIZE=32;
uint8_t  bsync=255;
uint8_t  sendbuf[MSGSIZE];
uint8_t  recvbuf[MSGSIZE];


uint8_t calcchecksum(uint8_t array[]) {
  int32_t  sum=0;
  for(int i=2; i<MSGSIZE; ++i) sum+=(array[i]);
  return (sum & 0x00ff);
}

bool checksumOK(uint8_t array[]){
return (calcchecksum(array)==array[1]);
}

// ================================================================
// addToBuffer and receive function courtesy of chucktodd

bool addToBuffer( uint8_t buf[], uint8_t *cnt, uint16_t timeout){
bool inSync = *cnt>0;
unsigned long start=millis();
while((*cnt<MSGSIZE)&&(millis()-start<timeout)){
  if( serialDataAvail( Serial1 ) ) { // grab new char, test for sync char, if so start adding to buffer
    buf[*cnt] = (uint8_t)serialGetchar( Serial1 );
    if(inSync) *cnt += 1;  // my origional *cnt++ was updating the pointer address, not
                           // the pointed to sendbuffer
    else{
     if(buf[*cnt]==0xFF){
       inSync = true;
       *cnt +=1;
       }
     }
    }
  }
return (*cnt==MSGSIZE);
}


//=====================================================================================

bool receive(uint8_t * buf, uint16_t timeout, uint8_t *cnt){ // by passing cnt in and out,
// i can timeout and still save a partial buffer, so a resync costs less (less data lost)

bool inSync=false;
unsigned long start=millis();
uint8_t * p;  // pointer into buf for reSync operation
bool done=false;

do{
  done = addToBuffer(buf,cnt,timeout); // if this return false, a timeout has occured, and the while will exit.
  if(done){                         // do checksumOK test of buffer;
    done=checksumOK(buf);
    if(!done){                      // checksumOK failed, scan buffer for next sync char
       p = (uint8_t*)memchr((buf+1),0xff,(MSGSIZE-1)); //forgot to skip the current sync at 0
       
       
       if(p){ // found next sync char, shift buffer content, refill buffer
         *cnt = MSGSIZE -(p-buf); // count of characters to salvage from this failure
         memcpy(buf,p,*cnt); //cnt is now where the next character from Serial is stored!
         }
       else *cnt=0; // whole buffer is garbage
       }
    }
   
  } while(!done&&(millis()-start<timeout));

return done; // if done then buf[] contains a sendbufid buffer, else a timeout occurred
}

//=====================================================================================


void loop()
{
  char     sbuf[128],  resOK;   
  static   uint8_t cnt=0;
  uint8_t  cbuf[MSGSIZE], chk;

 
  //   send to Rx slave Arduino
 
  //Serial.println();
  sendbuf[0]=bsync;
  sendbuf[1]=calcchecksum(sendbuf);
 
  for(uint8_t i=0; i<MSGSIZE; i++) {                     // better use write() ?
     serialPutchar( Serial1, sendbuf[i]);                // Send values to the Rx Arduino       
  }       
  //serialFlush( Serial1 );                              // clear output buffer
 
  //displayvalues(20, "Transmitted...: ", sendbuf);
  sprintf(sbuf, "%4d %4d", sendbuf[4], sendbuf[6]);
  //lcdprintxy(0, 20, sbuf);
  printf(sbuf); printf("\n");

 
  //     Receive from Rx slave Arduino

  memset(cbuf, 0, sizeof(cbuf));
   
  resOK = receive ( cbuf, 10000,&cnt);
 
  if( resOK ) {                         // byte 0 == syncbyte ?
    cnt=0;

    //displayvalues(60, "Received...:", cbuf);
     chk=(byte)calcchecksum(cbuf);     
     memcpy(recvbuf, cbuf, sizeof(cbuf));
 
        // change values to send back!
        memcpy(sendbuf, recvbuf, sizeof(sendbuf));         // copy inbuf to outbuf
        sendbuf[4]+=1;                                     // change [4] to send back
       
       
  }
 
}


//=====================================================================================

 
int main() {
    unsigned long timesav;
    char  sbuf[128];
    char  instr[128];
     
    printf("initializing..."); printf("\n");
   
    // UART Serial com port
    Serial1 = serialOpen (uart, 115200); // for Arduino code compatibility reasons
   
    while(1) { loop(); } 
   
    serialClose( Serial1);
    
    End();
    finish();   
    exit(0);
}

//=====================================================================================
//=====================================================================================

error:
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -c "Tx_master006.c" -lshapes -pthread -lrt -lwiringPi -lpigpio (im Verzeichnis: /home/pi/programs/UART_com)
In file included from Tx_master006.c:29:0:
/usr/include/fontinfo.h:11:3: error: ‘VGPath’ does not name a type
VGPath Glyphs[500];
^

^
Kompilierung fehlgeschlagen.
by double click on the error msg I'm landing on the fontinfo.h file at

Code: Select all

extern "C" {
#endif
	typedef struct {
		const short *CharacterMap;
		const int *GlyphAdvances;
		int Count;
		VGPath Glyphs[500];  //<<<<<<<<<<<<<<<<<<<<<<< 
                                                 // /usr/include/fontinfo.h:11:3: 
                                                 // error: ‘VGPath’ does not name a type
	} Fontinfo;

	extern Fontinfo SansTypeface, SerifTypeface, MonoTypeface;

where is the mistake?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 1:23 am

fontinfo.h needs VGPath which is defined in VG/openvg.h, however fontinfo.h doesn't include VG/openvg.h itsself (I take it this was an oversight), if you use #include "fontinfo.h" it needs to be done after either #include "VG/openvg.h" or #include "shapes.h"
She who travels light — forgot something.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 1:30 am

ah - that's what one of my last questions about all the #includes was about...
viewtopic.php?f=38&t=130650&p=874672#p872094

Isn't it possible to simplify the lib architecture to just include ONE lib for ONE functionality ("one for all")?

#include <openvg.h>
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
Paeryn
Posts: 2663
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openvg (Paeryn, ajstarks)

Sun Jan 03, 2016 2:59 am

davenull wrote:ah - that's what one of my last questions about all the #includes was about...
viewtopic.php?f=38&t=130650&p=874672#p872094

Isn't it possible to simplify the lib architecture to just include ONE lib for ONE functionality ("one for all")?

#include <openvg.h>
I'm sure I've said it before (yes, there in the second post of this very thread) - shapes.h inlcudes fontinfo.h, VG/openvg.h and VG/vgu.h so if you want you can just #include "shapes.h" and not bother including the other three yourself.
She who travels light — forgot something.

Return to “Graphics, sound and multimedia”