Ich bin grade mit der U8gLib am spielen. Versuche seit gestern Teile des
programms auszulagern. Es geht darum eine XBitmap als char array z.b in
ein anderes file zu packen um nicht alle bit maps im hauptcode zu haben.
dies ist ein Beispiel aus der U8g library. mein ziel ist
"static unsigned char u8g_logo_bits[] U8G_PROGMEM" in einer .h oder
ähnliches abzuspeichern. Ich hab schon einiges versucht und verstehe
nicht ganz warum ich es nicht einfach in eine .h datei verschieben und
von dort aus aufrufen kann.
michael w schrieb:> Ich hab schon einiges versucht
Was denn?
> und verstehe nicht ganz warum ich es nicht einfach in eine .h datei> verschieben und von dort aus aufrufen kann.
Das verstehe ich auch nicht. :-)
Ich sehe keinen Grund, warum das nicht gehen sollte.
fehlermeldung:
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560,
ATmega2560 (Mega 2560)"
In file included from C:\Users\XLA\Desktop\XBM\XBM.ino:44:0:
test.h:9:24: error: in-class initialization of static data member
'unsigned char test::u8g_logo_bits []' of incomplete type
static unsigned char u8g_logo_bits[] U8G_PROGMEM = {
^~~~~~~~~~~~~
Mehrere Bibliotheken wurden für "U8glib.h" gefunden
Benutzt: C:\Users\XLA\Documents\Arduino\libraries\U8glib
exit status 1
in-class initialization of static data member 'unsigned char
test::u8g_logo_bits []' of incomplete type
Dieser Bericht wäre detaillierter, wenn die Option
"Ausführliche Ausgabe während der Kompilierung"
in Datei -> Voreinstellungen aktiviert wäre.
Ja da mußt du dann das "u8g_logo_bits" früher bekannt machen, oder das
#include test_h weiter hinter schieben.
Ah das war quatsch. vergiss es, ich hatte noch keinen Kaffee.
static member in class mußt du warscheinlich im .c file definieren, und
im .h nur deklarieren oder so ähnlich.
im .h:
static unsigned char u8g_logo_bits[];
und im test.c:
static unsigned char test::u8g_logo_bits[] ...
michael w schrieb:> class test> {
was soll denn das da? mach das weg! hast du im originalen code doch auch
nicht...
Thomas W. schrieb:> aber ohne #include....
und wie macht man die header-datei dann bekannt?
> Thomas W. schrieb:>> aber ohne #include....>> und wie macht man die header-datei dann bekannt?
Hab mich falsch ausgedrückt. Ich meinte wenn der TO kein #include hat,
dann funktioniert es nicht.
michael w schrieb:> test.h:9:24: error: in-class initialization of static data member
Das ist halt so. In C++ kann ma keine statischen member in class
initialisieren.
Schreib constexpr davor, dann gehts.
Oliver
Thomas W. schrieb:> u8g.drawXBMP( 0, 0, u8g_logo_width, u8g_logo_height,> &test_h::u8g_logo_bits[0]);
lässt sich kompilieren aber das Display macht nicht was es soll. packe
ich den static unsigned char u8g_logo_bits[] array wieder in die main
läuft alles.
michael w schrieb:> dann rufe ich u8g_logo_bits mit :> u8g.drawXBMP( 0, 0, u8g_logo_width, u8g_logo_height,> test_h::u8g_logo_bits);auf.michael w schrieb:> #ifndef test_h> #define test_h>> static unsigned char u8g_logo_bits[] {
wo kommt denn beim funktionsaufruf das 'test::' her? das ist in deiner
header datei nicht zu finden...
was ich will sollte eigntlich doch ganz einfach sein. Ich will diesen
array
static unsigned char u8g_logo_bits[] = {0xff, 0xff, 0xff, 0xff, ........
};
außerhalb meiner main speichern und von der main aus drauf zugreifen
können. finde halt leider keine Beispiele oder Erklärung dafür. Mir
mangelt es hier an grundlegendem Wissen.
im library bsp ist es wie folgt.
1
staticunsignedcharu8g_logo_bits[]U8G_PROGMEM={
2
0x00,0x00,0x00,0x00,0x00,......};
entferne ich U8G_PROGMEM macht der Display fehler. was hat es
U8G_PROGMEM auf sich?
PROGMEM sagt soweit ich weiß, daß die Daten im Code mit abgelegt werden
und nicht Platz im RAM (Variable) belegen.
Bei Arduino:
https://www.arduino.cc/reference/en/language/variables/utilities/progmem/
Das "test_h::" ist definitiv falsch, das stammt aus deinem
"class"-Versuch.
Du hast einmal ein "class" hinzugefügt und dann "PROGMEM" entfernt,
ändere nicht mehrere Sachen auf einmal, das verwirrt.
Hier ist die Dokumentation der Library:
https://github.com/olikraus/u8glib/wiki/userreference#drawxbmp
Also wäre
u8g.drawXBMP( 0, 0, u8g_logo_width, u8g_logo_height, u8g_logo_bits);
schon richtig, nicht wie ich geschrieben hatte ;-)
den array aufrufen und die Funktion ausführen. Display zeigt alles
richtig an.
Jedoch ein Meldung:
C:\Users\XLA\AppData\Local\Temp\ccilhCLE.s: Assembler messages:
C:\Users\XLA\AppData\Local\Temp\ccilhCLE.s:4768: Warning: ignoring
changed section attributes for .progmem.data
kann ich denke ich ignorieren.
Thomas W. schrieb:> PROGMEM sagt soweit ich weiß, daß die Daten im Code mit abgelegt werden> und nicht Platz im RAM (Variable) belegen.
So ist es.
Es gibt zwei Varianten von drawXBM, eine, die die Bitmapdaten im RAM und
eine (mit "P"-Suffix), die sie im Flash erwartet:
Wenn du also das U8G_PROGMEM weglassen möchtest (wofür es eigentlich
kaum einen Grund gibt), musst du drawXBM statt drawXBMP aufrufen.
michael w schrieb:> u8g.drawXBMP( 0, 0, u8g_logo_width, u8g_logo_height,> test_h::u8g_logo_bits);
Das test_h kannst du weglassen, da das Makro sowieso in nichts
expandiert. Es täuscht einen nicht vorhandenen Klassen- oder
Namespace-Namen vor, was nur zur Verwirrung führt
michael w schrieb:> kann ich denke ich ignorieren.
Mach das. Im Lernprogramm "learning by guessing" ist es ausdrüclich
erlaubt, alles, was man nicht versteht, zu ignorieren.
Oliver
michael w schrieb:> ich hab eine Lösung gefunden:
naja... das ist ja das, was du im eingangspost gefragt hattest: ob du
das einfach so auslagern kannst... warum du dann unbedingt alles daran
verändern musstest (es in eine klassenstruktur packen, progmem
entfernen) bleibt deine sache...
Sven K. schrieb:> michael w schrieb:>> ich hab eine Lösung gefunden:>> naja... das ist ja das, was du im eingangspost gefragt hattest: ob du> das einfach so auslagern kannst... warum du dann unbedingt alles daran> verändern musstest (es in eine klassenstruktur packen, progmem> entfernen) bleibt deine sache...
Das hat mich auch gewundert. Warum erwartet er, dass alles exakt gleich
funktioniert, wenn er beim Auslagern nebenher immer noch irgendwas
verändert? Einfach ausschneiden, 1:1 einfügen, fertig.