![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
Help with this function |
Posted: Sat Apr 06, 2019 11:42 pm |
|
|
I want use this function
Code: | void SSD1306_DrawPixel(uint8_t x, uint8_t y, int1 color = TRUE) {
if ((x >= SSD1306_LCDWIDTH) || (y >= SSD1306_LCDHEIGHT)) return;
if (color) buffer[x + (uint16_t)(y / 8) * SSD1306_LCDWIDTH] |= (1 << (y & 7));
else buffer[x + (uint16_t)(y / 8) * SSD1306_LCDWIDTH] &= ~(1 << (y & 7));
} |
I want draw any icon in buffer mapping
Code: | void SSD1306_Drawicon(uint8_t x, uint8_t y, char *c, int16_t w, int16_t h) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t ptr;
for(i = 0; i < h; i++ ) {
ptr = c[i];
for(j = 0; j < w; j++, ptr >>= 1) {
if(ptr & 0x01) SSD1306_DrawPixel(x + i, y + j);
// if(bit_test(c[i], 7-j)) SSD1306_DrawPixel(x+i, y+j);
}
}
} |
using
Code: | const unsigned char bat_4 [32] = {
0xE0, 0xF0, 0xF8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xB8, 0xB8, 0x38, 0x38, 0xF0, 0xE0, 0x80,
0x07, 0x0F, 0x1F, 0x1C, 0x1C, 0x1D, 0x1F, 0x1F, 0x1D, 0x1D, 0x1D, 0x1D, 0x1C, 0x0F, 0x07, 0x01
};
SSD1306_DrawCharx(40,40,bat_4,16,16); |
The function work 50%, only keep half array of bat_4 in array buffer. When I display buffer, only show top part of icon.
My question is, how i can keep array bat_4, on array buffer but with postion x,y, buffer is of 1024, I am making bab the tranverse array. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Help with this function |
Posted: Sun Apr 07, 2019 12:48 am |
|
|
cvargcal wrote: |
void SSD1306_Drawicon(uint8_t x, uint8_t y, char *c, int16_t w, int16_t h) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t ptr;
for(i = 0; i < h; i++ ) {
ptr = c[i];
for(j = 0; j < w; j++, ptr >>= 1) {
if(ptr & 0x01) SSD1306_DrawPixel(x + i, y + j);
// if(bit_test(c[i], 7-j)) SSD1306_DrawPixel(x+i, y+j);
}
}
}
// using:
SSD1306_DrawCharx(40, 40, bat_4, 16, 16);
// The function work 50%
|
First, the variable that you call 'ptr' is not a pointer, it's the data.
It's just a byte of data from the bat_4 array. That's just an issue
of giving it a confusing name.
The real problem is that your width is 16 pixels, but your data (called 'ptr')
is only one byte of 8 bits. You need to be processing 2 bytes (16 bits) for
the width.
Also, what is the symbol 'bat_4' supposed to be ? Describe it. Is it
a rectangle that's partially filled up, like a battery would be partially full ? |
|
![](templates/subSilver/images/spacer.gif) |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
Re: Help with this function |
Posted: Sun Apr 07, 2019 2:14 am |
|
|
PCM programmer wrote: | cvargcal wrote: |
void SSD1306_Drawicon(uint8_t x, uint8_t y, char *c, int16_t w, int16_t h) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t ptr;
for(i = 0; i < h; i++ ) {
ptr = c[i];
for(j = 0; j < w; j++, ptr >>= 1) {
if(ptr & 0x01) SSD1306_DrawPixel(x + i, y + j);
// if(bit_test(c[i], 7-j)) SSD1306_DrawPixel(x+i, y+j);
}
}
}
// using:
SSD1306_DrawCharx(40, 40, bat_4, 16, 16);
// The function work 50%
|
First, the variable that you call 'ptr' is not a pointer, it's the data.
It's just a byte of data from the bat_4 array. That's just an issue
of giving it a confusing name.
The real problem is that your width is 16 pixels, but your data (called 'ptr')
is only one byte of 8 bits. You need to be processing 2 bytes (16 bits) for
the width.
Also, what is the symbol 'bat_4' supposed to be ? Describe it. Is it
a rectangle that's partially filled up, like a battery would be partially full ? |
Thanks you
the bat_0 is full, I tried with this but not show correct the pixel
Code: | void drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t height, char *xbm) {
int16_t widthInXbm = (width + 7) / 8;
uint8_t data = 0;
for(int16_t y = 0; y < height; y++) {
for(int16_t x = 0; x < width; x++ ) {
if (x & 7) {
data >>= 1; // Move a bit
} else { // Read new data every 8 bit
data = xbm[(x / 8) + y * widthInXbm];
}
// if there is a bit draw it
if (data & 0x01) {
SSD1306_DrawPixel(xMove + x, yMove + y);
}
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 07, 2019 3:20 am |
|
|
Post a link to an image on a website that shows me what the bat_4 symbol
should look like.
For example, which one of these icons is bat_4 supposed to look like ?
https://www.freepik.com/free-vector/battery-icons-collection_1095897.htm
Also, those symbols are vertical. Is the bat_4 symbol vertical or horizontal ?
Be accurate and complete in your answer. |
|
![](templates/subSilver/images/spacer.gif) |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Sun Apr 07, 2019 8:31 am |
|
|
PCM programmer wrote: | Post a link to an image on a website that shows me what the bat_4 symbol
should look like.
For example, which one of these icons is bat_4 supposed to look like ?
https://www.freepik.com/free-vector/battery-icons-collection_1095897.htm
Also, those symbols are vertical. Is the bat_4 symbol vertical or horizontal ?
Be accurate and complete in your answer. |
Look,
full
Code: | void SSD1306_Icon(char *icon, uint8_t seg, uint8_t pag, uint8_t _width, uint8_t _height){ //x,y
uint8_t i, j;
uint8_t x_seg, y_pag;
y_pag = pag;
for(i = 0; i < _height / 8; i++) {
x_seg = seg;
for(j = 0; j < _width; j++) {
SSD1306_SetPointer(x_seg, y_pag);
SSD1306_WriteRam(*icon); // Directamente al display
// buffer[x_seg + (y_pag * 128)] = *icon; // On buffer
icon++;
x_seg++;
}
y_pag++;
} |
Half
Code: | void SSD1306_DrawCharx(uint8_t x, uint8_t y, char *c, int16_t w, int16_t h,int size) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t ptr;
for(i = 0; i < h; i++ ) {
ptr = c[i];
for(j = 0; j < w; j++, ptr >>= 1) {
// if(bit_test(c[i], 7-j)) SSD1306_DrawPixel(x+i, y+j);
if(ptr & 0x01) SSD1306_DrawPixel(x + i, y + j); // else SSD1306_FillRect(x + (i * size), y + (j * size), size, size);
}
}
} |
rares bit
Code: | void drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t height, char *xbm) {
int16_t widthInXbm = (width + 7) / 8;
uint8_t data = 0;
for(int16_t y = 0; y < height; y++) {
for(int16_t x = 0; x < width; x++ ) {
if (x & 7) {
data >>= 1; // Move a bit
} else { // Read new data every 8 bit
data = xbm[(x / 8) + y * widthInXbm];
}
// if there is a bit draw it
if (data & 0x01) {
SSD1306_DrawPixel(xMove + x, yMove + y);
}
}
}
} |
I can draw any icon, but the problem is that I have show with "pag ans seg" so I can not draw the icon where i want because the the PAG is 0...7, so if I start in PAG 0, I can not draw in top screen without over rectangle.
With the function drawpixel(x,y) I can draw all bits in buffer array with direction for after display all buffer. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sun Apr 07, 2019 8:33 am |
|
|
OK, looks like you're using Proteus and NOT real hardware .
Is this correct ? |
|
![](templates/subSilver/images/spacer.gif) |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Sun Apr 07, 2019 8:44 am |
|
|
temtronic wrote: | OK, looks like you're using Proteus and NOT real hardware .
Is this correct ? |
Yes, but its the same in real. I tested |
|
![](templates/subSilver/images/spacer.gif) |
empty
Joined: 13 Jan 2018 Posts: 15
|
|
Posted: Sun Apr 07, 2019 10:47 am |
|
|
Look, if you're using this driver:
https://simple-circuit.com/ssd1306-oled-ccs-c-library/
just use the function: SSD1306_ROMBMP( ...
you can print your icon wherever you want, for example:
Code: |
const unsigned char bat_4 [32] = {
0xE0, 0xF0, 0xF8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xB8, 0xB8, 0x38, 0x38, 0xF0, 0xE0, 0x80,
0x07, 0x0F, 0x1F, 0x1C, 0x1C, 0x1D, 0x1F, 0x1F, 0x1D, 0x1D, 0x1D, 0x1D, 0x1C, 0x0F, 0x07, 0x01
};
void main(void)
{
SSD1306_Begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS);
SSD1306_ClearDisplay();
SSD1306_ROMBMP(0, 0, bat_4, 16, 16);
SSD1306_ROMBMP(40, 15, bat_4, 16, 16);
SSD1306_ROMBMP(80, 30, bat_4, 16, 16);
SSD1306_ROMBMP(111, 47, bat_4, 16, 16);
SSD1306_Display();
while (TRUE)
;
} |
This is simulation result:
![](https://i.ibb.co/8d4WzrW/Untitled-3.png) |
|
![](templates/subSilver/images/spacer.gif) |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Sun Apr 07, 2019 11:25 am |
|
|
empty wrote: | Look, if you're using this driver:
https://simple-circuit.com/ssd1306-oled-ccs-c-library/
just use the function: SSD1306_ROMBMP( ...
you can print your icon wherever you want, for example:
Code: |
const unsigned char bat_4 [32] = {
0xE0, 0xF0, 0xF8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xB8, 0xB8, 0x38, 0x38, 0xF0, 0xE0, 0x80,
0x07, 0x0F, 0x1F, 0x1C, 0x1C, 0x1D, 0x1F, 0x1F, 0x1D, 0x1D, 0x1D, 0x1D, 0x1C, 0x0F, 0x07, 0x01
};
void main(void)
{
SSD1306_Begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS);
SSD1306_ClearDisplay();
SSD1306_ROMBMP(0, 0, bat_4, 16, 16);
SSD1306_ROMBMP(40, 15, bat_4, 16, 16);
SSD1306_ROMBMP(80, 30, bat_4, 16, 16);
SSD1306_ROMBMP(111, 47, bat_4, 16, 16);
SSD1306_Display();
while (TRUE)
;
} |
This is simulation result:
![](https://i.ibb.co/8d4WzrW/Untitled-3.png) |
In that page these other lib , woooow I had the answer all time.
Thanks you!!! |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|