Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

DarkDucke

Criar matriz de byte atraves de uma String

Recommended Posts

Galera, seguinte tenho uma imagem que é guardada em uma matriz do tipo byte, ela é assim:

 

const byte RPrint [] = {

0x01, 0x01, 0x01, 0x31, 0x00, 0x30, 0x38, 0x30, 0x02, 0x20, 0x89, 0xE0, 0xE3, 0xF0, 0xF9, 0xFD,

0xFD, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,

0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,

0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,

0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,

0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,

0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,

0xFE, 0xFC, 0xF8, 0xF8, 0xF0, 0xE2, 0xE4, 0xDE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x50, 0x80, 0x20, 0x04, 0x03, 0x84, 0xF3, 0xFA, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,

0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x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amicamente, este conteudo está nums string tipo

 

StringImagem = ' 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x7F, 0x3F, 0x3F, 0xBF, 0x3F, 0x7F, 0x3F, 0x3F' ....

 

como faria para montar cada codigo hexa dentro de uma posição de minha matriz

tipo eu tenho ela criada zerada byte RPrint [];

tem alguma maneira de fazer isso?

pq eu uso a variavel RPrint para imprimir a imagem....

 

Obrigado desde jah!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não, creio que você não entendeu, memset vai zerar a variavel, eu preciso pegar o conteudo da string que esta entre as virgulas "," e coloca em cada posição de minha matriz byte, isto dinamicamente!

 

Obrigado msms assim!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Que eu saiba,memset só zera a memoria se você mandar encher de zero e não existe tipo byte em C.

 

Use strtok e malloc.

Compartilhar este post


Link para o post
Compartilhar em outros sites

eu sou leigo em C, em outro forum um colega postou uma função, deu certo +- agora o problema acho que ta no tipo de variavel, veja a função:

 

/* FUNÇÃO PARA IMPRESSÃO DE LOGO DINAMICA */ 
void MENU_LOGOS(void) 
{ 
	  
   int n; 
   char frase[] = "0x01, 0x01, 0x01, 0x31, ..."; 
   const byte aRPrint [] = {0x00, 0x00, 0x00, 0x00, 0x00,...}; 
   char * palavra; 
   byte xRPrint [] = {0x00, 0x00, 0x00, 0x00, 0x00,...}; 
	
   int i = 0; 
   palavra = strtok(frase, ", "); 
   while (palavra!=NULL) { 
	  xRPrint[i] = (byte)palavra; 
	  i++; 
	  palavra = strtok(NULL, ", "); 
   } 

 PrintImage((byte *)aRPrint, 5, 128, 8); 
 PrintImage((byte *)xRPrint, 5, 128, 8); 
} 
/* FIM IMPRESSÃO LOGO DINAMICA */

a Imagem que ta na variavel aRPrint imprime normalmente, a imagem que ta na variavel xRPrint imprime um monte de sujeira após passar o conteudo da string frase para ela... creio que os codigos hexa não estão indo como hexa, a função PrintImage(); não consegue imprimir a imagem...

 

alguma ideia? conseguirao me entender agora?

 

Obrigado novamente!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Entendi!

 

Você está querendo é transformar a string "0x01" em byte!!!!

 

Isso não funciona! Você primeiro terá que achar o valor em byte do valor hexadecimal (string).

 

E depois passar para o array!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.