Forum: PC-Programmierung c/c++ code auslagern


von michael w (Gast)


Lesenswert?

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.

1
#define u8g_logo_width 38
2
#define u8g_logo_height 24
3
//static unsigned char u8g_logo_bits[] = {
4
static unsigned char u8g_logo_bits[] U8G_PROGMEM = {
5
   0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xe0, 0xe0,
6
   0xff, 0xff, 0x3f, 0xe3, 0xe1, 0xff, 0xff, 0x3f, 0xf3, 0xf1, 0xff, 0xff,
7
   0x3f, 0xf3, 0xf1, 0xfe, 0xbf, 0x37, 0xf3, 0x11, 0x1c, 0x1f, 0x30, 0xf3,
8
   0x01, 0x08, 0x8c, 0x20, 0xf3, 0x01, 0x00, 0xc0, 0x39, 0xf3, 0x81, 0xc7,
9
   0xc1, 0x39, 0xf3, 0xc1, 0xc7, 0xc9, 0x38, 0xf3, 0xc1, 0xc3, 0x19, 0x3c,
10
   0xe3, 0x89, 0x01, 0x98, 0x3f, 0xc7, 0x18, 0x00, 0x08, 0x3e, 0x0f, 0x3c,
11
   0x70, 0x1c, 0x30, 0x3f, 0xff, 0xfc, 0x87, 0x31, 0xff, 0xff, 0xbf, 0xc7,
12
   0x23, 0x01, 0x00, 0x00, 0xc6, 0x23, 0x03, 0x00, 0x00, 0x0e, 0x30, 0xff,
13
   0xff, 0x3f, 0x1f, 0x3c, 0xff, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0xff, 0x3f,
14
   0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f };
15
16
void draw(void) {
17
  // graphic commands to redraw the complete screen should be placed here  
18
  u8g.drawXBMP( 0, 0, u8g_logo_width, u8g_logo_height, u8g_logo_bits);
19
}
20
21
void setup(void) {
22
  // flip screen, if required
23
  // u8g.setRot180();
24
}
25
26
void loop(void) {
27
  // picture loop
28
  u8g.firstPage();  
29
  do {
30
    draw();
31
  } while( u8g.nextPage() );
32
  
33
  // rebuild the picture after some delay
34
  delay(500);
35
}

von Sven K. (quotschmacher)


Lesenswert?

warum sollte das nicht gehen? wie sieht denn deine *.h datei am ende 
aus? bekommst du fehlermeldungen vom compiler?

von Rolf M. (rmagnus)


Lesenswert?

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.

von Thomas W. (goaty)


Lesenswert?

Auslagern geht warscheinlich, aber ohne #include....

von michael w (Gast)


Lesenswert?

z.b.
1
#ifndef test_h
2
#define test_h
3
4
5
class test
6
{
7
  public:
8
9
  static unsigned char u8g_logo_bits[] U8G_PROGMEM = {
10
   0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xe0, 0xe0,
11
   0xff, 0xff, 0x3f, 0xe3, 0xe1, 0xff, 0xff, 0x3f, 0xf3, 0xf1, 0xff, 0xff,
12
   0x3f, 0xf3, 0xf1, 0xfe, 0xbf, 0x37, 0xf3, 0x11, 0x1c, 0x1f, 0x30, 0xf3,
13
   0x01, 0x08, 0x8c, 0x20, 0xf3, 0x01, 0x00, 0xc0, 0x39, 0xf3, 0x81, 0xc7,
14
   0xc1, 0x39, 0xf3, 0xc1, 0xc7, 0xc9, 0x38, 0xf3, 0xc1, 0xc3, 0x19, 0x3c,
15
   0xe3, 0x89, 0x01, 0x98, 0x3f, 0xc7, 0x18, 0x00, 0x08, 0x3e, 0x0f, 0x3c,
16
   0x70, 0x1c, 0x30, 0x3f, 0xff, 0xfc, 0x87, 0x31, 0xff, 0xff, 0xbf, 0xc7,
17
   0x23, 0x01, 0x00, 0x00, 0xc6, 0x23, 0x03, 0x00, 0x00, 0x0e, 0x30, 0xff,
18
   0xff, 0x3f, 0x1f, 0x3c, 0xff, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0xff, 0x3f,
19
   0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f };
20
21
  private:
22
    
23
};
24
25
26
27
#endif


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.

von Thomas W. (goaty)


Lesenswert?

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[] ...

: Bearbeitet durch User
von Sven K. (quotschmacher)


Lesenswert?

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?

von Thomas W. (goaty)


Lesenswert?

> 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.

von Thomas W. (goaty)


Lesenswert?

Und hier der Link hat noch gefehlt:

https://en.cppreference.com/w/cpp/language/static

von Oliver S. (oliverso)


Lesenswert?

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

von michael w (Gast)


Lesenswert?

habe jetzt so:
1
#ifndef test_h
2
#define test_h
3
4
5
  static unsigned char u8g_logo_bits[] {
6
  
7
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
8
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
9
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7F, 
10
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
11
  0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
12
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x07, 0x00, 0x00, 0x00, 
13
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 
14
  0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
15
  0x00, 0x80, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
16
  0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0xC0, 0x7F, 0x00, 0x00, 0x00, 
17
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x00, 
18
  0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
19
  0x00, 0xF0, 0x07, 0x00, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
20
  0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0xF8, 0x01, 0x00, 0x00, 
21
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x01, 0x00, 
22
  0xF0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
23
  0x00, 0xF8, 0x00, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
24
  0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 
25
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 
26
  0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
27
  0x00, 0x7C, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xFC, 0x03, 0x00, 
28
  0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 
29
  0x80, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 
30
  0x80, 0x0F, 0x00, 0x00, 0xE0, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 
31
  0x00, 0x3E, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0x01, 
32
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 
33
  0xFC, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 
34
  0x80, 0x0F, 0x00, 0x00, 0xFE, 0x07, 0xFE, 0x07, 0x00, 0x00, 0x00, 0x00, 
35
  0x00, 0x3E, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0xFF, 0x00, 0xF0, 0x0F, 
36
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x80, 
37
  0x3F, 0x00, 0xC0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 
38
  0xC0, 0x0F, 0x00, 0x80, 0x1F, 0x00, 0x80, 0x1F, 0x00, 0x00, 0x00, 0x00, 
39
  0x00, 0x7C, 0x00, 0x00, 0xC0, 0x07, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x3F, 
40
  0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0xC0, 0x07, 0x00, 0xC0, 
41
  0x07, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 
42
  0xE0, 0x07, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 
43
  0x00, 0xF8, 0x00, 0x00, 0xE0, 0x03, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x7C, 
44
  0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x01, 0x00, 0xF0, 0x03, 0x00, 0xE0, 
45
  0x03, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 
46
  0xF8, 0x01, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 
47
  0x00, 0xF0, 0x07, 0x00, 0xFC, 0x01, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x7C, 
48
  0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x00, 0xFF, 0x00, 0x00, 0xE0, 
49
  0x03, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0xC0, 
50
  0x7F, 0x00, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 
51
  0x00, 0x80, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x3E, 
52
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xC0, 
53
  0x07, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 
54
  0x07, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 
55
  0x00, 0x00, 0xF8, 0xFF, 0x03, 0x00, 0x00, 0x80, 0x1F, 0x00, 0x80, 0x1F, 
56
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x80, 
57
  0x3F, 0x00, 0xC0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
58
  0x00, 0x80, 0x1F, 0x00, 0xFF, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x00, 
59
  0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x7F, 0x00, 0xFE, 0x03, 0xFC, 0x07, 
60
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0x01, 
61
  0xFC, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
62
  0x00, 0xFC, 0xFF, 0x03, 0xF8, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 
63
  0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x07, 0xE0, 0xFF, 0xFF, 0x00, 
64
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xF0, 0x07, 
65
  0x80, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
66
  0x00, 0x3E, 0xC0, 0x07, 0x00, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 
67
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x0F, 0x00, 0x00, 0x00, 0x00, 
68
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x80, 0x0F, 
69
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
70
  0x00, 0x1F, 0x80, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
71
  0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x80, 0x0F, 0x00, 0x00, 0x00, 0x00, 
72
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xC0, 0x0F, 
73
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
74
  0x00, 0xFE, 0xF0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
75
  0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 
76
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x03, 
77
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
78
  0x00, 0xF8, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
79
  0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 
80
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1F, 0x00, 
81
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
82
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
83
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
84
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
85
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
86
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
87
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
88
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
89
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
90
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
91
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
92
  0x00, 0x00, 0x00, 0x00};
93
94
  
95
#endif

dann rufe ich u8g_logo_bits mit :
1
u8g.drawXBMP( 0, 0, u8g_logo_width, u8g_logo_height, test_h::u8g_logo_bits);
auf.

jetzt zeigt der Display nur noch Unfug an. Aber keine Fehlermeldung 
mehr.

u8g.drawXBMP erwartet const uint8_t *bitmap als Argument.
1
void U8GLIB::drawXBM(u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap)

von Thomas W. (goaty)


Lesenswert?

Irgendwie eher die Adresse vom Array übergeben:

u8g.drawXBMP( 0, 0, u8g_logo_width, u8g_logo_height, 
&test_h::u8g_logo_bits[0]);

von michael w (Gast)


Lesenswert?

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.

von Sven K. (quotschmacher)


Lesenswert?

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...

: Bearbeitet durch User
von michael w (Gast)


Lesenswert?

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
static unsigned char u8g_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?

von Thomas W. (goaty)


Lesenswert?

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 ;-)

: Bearbeitet durch User
von michael w (Gast)


Lesenswert?

ich hab eine Lösung gefunden:
1
#ifndef test_h
2
#define test_h
3
#include "U8glib.h"
4
5
  static unsigned char u8g_logo_bits[]U8G_PROGMEM {
6
  
7
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
8
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
9
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7F, 
10
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
11
  0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
12
  };
13
  
14
#endif

dann kann ich in der main mit:
1
u8g.drawXBMP( 0, 0, u8g_logo_width, u8g_logo_height, test_h::u8g_logo_bits);

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.

von Yalu X. (yalu) (Moderator)


Lesenswert?

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:
1
void U8GLIB::drawXBM(u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h,
2
                     const uint8_t *bitmap)
3
4
void U8GLIB::drawXBMP(u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h,
5
                      const u8g_pgm_uint8_t *bitmap)

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

von Oliver S. (oliverso)


Lesenswert?

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

von Sven K. (quotschmacher)


Lesenswert?

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...

von Rolf M. (rmagnus)


Lesenswert?

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.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.