pour le parametre typeset, j'ai modifié car je faisait typeset & 7 alors que c'est typeset & 0xF,mais ca na rien changé.
Je met le code mais il y beaucoup de code en commentaire pour test.
////////////////////////////////////////////////////////////////////////
// DEBUT DU PROGRAMME
////////////////////////////////////////////////////////////////////////
/*enum CONTEXT {
BACKGROUND = 0,
FLASH,
FOREGROUND,
INVERSE,
INSERT,
DOUBLEHEIGHT,
MASQUE,
DOUBLEWIDTH,
TYPEANDSET
};*/
//static uint16_t buf_attr[25];
/*struct __attribute__((packed)) Attributs {
uint16_t background : 3; // Bits 0-2
uint16_t flash : 1; // Bit 1
uint16_t foreground : 3; // Bits 4-6
uint16_t inverse : 1; // Bit 7
uint16_t insert : 1; // Bit 8
uint16_t dh : 1; // Bit 9
uint16_t conceal : 1; // Bit 10
uint16_t dw : 1; // Bit 11
uint16_t typeset : 4; // Bits 12-15
} ;*/
struct __attribute__((packed)) Attributs {
uint16_t typeset : 4; // Bits 12-15
uint16_t dw : 1; // Bit 11
uint16_t conceal : 1; // Bit 10
uint16_t dh : 1; // Bit 9
uint16_t insert : 1; // Bit 8
uint16_t inverse : 1; // Bit 7
uint16_t foreground : 3; // Bits 4-6
uint16_t flash : 1; // Bit 3
uint16_t background : 3; // Bits 0-2
} ;
Attributs attributs[25] ;
//static uint16_t save_code_attr = 0;
////////////////////////////////////////////////////////////////////////
void setup() {
//Serial2.begin(1200, SERIAL_7E1, 17, 16);
// Le premier port série matériel de l'ATMega (Serial / RXD0 TXD0)
// ou de l'ESP32 (Serial / U0RXD U0TXD) est utilisé pour la connexion
// avec le PC.
Serial.begin(115200);
uint8_t typeset = 2;
uint8_t dw = 1;
uint8_t conceal = 1;
uint8_t dh = 1;
uint8_t insert = 1;
uint8_t inverse = 1;
uint8_t foreground = 2;
uint8_t flash = 1;
uint8_t background = 7;
definirAttributs(attributs[5], typeset & 0xF, dw & 1, conceal & 1, dh & 1, insert & 1, inverse & 1, foreground & 7, flash & 1, background & 7);
printAttributs(attributs[5]);
foreground = 4;
inverse = 0;
definirAttributs(attributs[5], typeset & 0xF, dw & 1, conceal & 1, dh & 1, insert & 1, inverse & 1, foreground & 7, flash & 1, background & 7);
printAttributs(attributs[5]);
typeset = 5;
definirAttributs(attributs[5], typeset & 0xF, dw & 1, conceal & 1, dh & 1, insert & 1, inverse & 1, foreground & 7, flash & 1, background & 7);
printAttributs(attributs[5]);
/*uint8_t typeset = 2;
uint8_t dw = 1;
uint8_t conceal = 1;
uint8_t dh = 1;
uint8_t insert = 1;
uint8_t inverse = 1;
uint8_t foreground = 2;
uint8_t flash = 1;
uint8_t background = 7;
saveContext(&typeset, &dw, &conceal, &dh, &insert, &inverse, &foreground, &flash, &background);
foreground = 4;
inverse = 0;
saveContext(nullptr, nullptr, nullptr, nullptr, nullptr, &inverse, &foreground, nullptr, &background);
typeset = 4;
saveContext(&typeset, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
Serial.printf("\r\n\r\ntypeset = %d\r\n", readContext(TYPEANDSET));
Serial.printf("double width = %d\r\n", readContext(DOUBLEWIDTH));
Serial.printf("Conceal = %d\r\n", readContext(MASQUE));
Serial.printf("double height = %d\r\n", readContext(DOUBLEHEIGHT));
Serial.printf("insert = %d\r\n", readContext(INSERT));
Serial.printf("inverse = %d\r\n", readContext(INVERSE));
Serial.printf("foreground = %d\r\n", readContext(FOREGROUND));
Serial.printf("flash = %d\r\n", readContext(FLASH));
Serial.printf("background = %d\r\n", readContext(BACKGROUND));
Serial.printf("buf_attr[5] = 0x%04X\r\n", buf_attr[5]);*/
}
void prinlntBits(uint16_t value, uint8_t numBits) {
for (int8_t i = numBits - 1; i >= 0; i--) Serial.write(bitRead(value, i) ? '1' : '0');
Serial.println();
Serial.println();
}
void printAttributs(const Attributs &attribut) {
Serial.printf("\r\n\r\ntypeset: %d\r\n", attribut.typeset);
Serial.printf("dw: %d\r\n", attribut.dw);
Serial.printf("conceal: %d\r\n", attribut.conceal);
Serial.printf("dh: %d\r\n", attribut.dh);
Serial.printf("insert: %d\r\n", attribut.insert);
Serial.printf("inverse: %d\r\n", attribut.inverse);
Serial.printf("foreground: %d\r\n", attribut.foreground);
Serial.printf("flash: %d\r\n", attribut.flash);
Serial.printf("background: %d\r\n", attribut.background);
}
/*void printAttributs(const Attributs &attribut) {
Serial.print("typeset: "); prinlntBits(attribut.typeset, 3);
Serial.print("dw: "); prinlntBits(attribut.dw, 1);
Serial.print("conceal: "); prinlntBits(attribut.conceal, 1);
Serial.print("dh: "); prinlntBits(attribut.dh, 1);
Serial.print("insert: "); prinlntBits(attribut.insert, 1);
Serial.print("inverse: "); prinlntBits(attribut.inverse, 1);
Serial.print("foreground: "); prinlntBits(attribut.foreground, 2);
Serial.print("flash: "); prinlntBits(attribut.flash, 1);
Serial.print("background: "); prinlntBits(attribut.background, 4);
}*/
void definirAttributs(Attributs &attribut, uint8_t typeset, uint8_t dw, uint8_t conceal, uint8_t dh, uint8_t insert, uint8_t inverse, uint8_t foreground, uint8_t flash, uint8_t background) {
attribut.background = background; // Bits 0-2
attribut.flash = flash; // Bit 3
attribut.foreground = foreground; // Bits 4-6
attribut.inverse = inverse; // Bit 7
attribut.insert = insert; // Bit 8
attribut.dh = dh; // Bit 9
attribut.conceal = conceal; // Bit 10
attribut.dw = dw; // Bit 11
attribut.typeset = typeset; // Bits 12-15
}
/*uint8_t readContext(CONTEXT ctx)
{
uint8_t value = 0;
//uint8_t line = getCursorY();
uint16_t codeAttr = buf_attr[5];
switch(ctx) {
case BACKGROUND: value = codeAttr & 0x07; break;
case FLASH: value = bitRead(codeAttr, 3); break;
case FOREGROUND: value = (codeAttr >> 4) & 7; break;
case INVERSE: value = bitRead(codeAttr, 7); break;
case INSERT: value = bitRead(codeAttr, 8); break;
case DOUBLEHEIGHT: value = bitRead(codeAttr, 9); break;
case MASQUE: value = bitRead(codeAttr, 10); break;
case DOUBLEWIDTH: value = bitRead(codeAttr, 11); break;
case TYPEANDSET: value = (codeAttr >> 12) & 0xF; break;
}
return value;
}
void saveContext(uint8_t *typeSet, uint8_t *doubleWidth, uint8_t *masque,uint8_t *doubleHeight,uint8_t *insert,uint8_t *inverse,uint8_t *fg_color, uint8_t *blink,uint8_t *bg_color)
{
//uint16_t code_attr = buf_attr[5];
if(bg_color != nullptr) {
buf_attr[5] |= ((buf_attr[5] & 7) | (*bg_color & 7));
} // backgroune color
if (blink != nullptr) {
if (*blink & 1) buf_attr[5] |= (1 << 3); else buf_attr[5] &= ~(1 << 3); //bitSet(buf_attr[5], 3); else bitClear(buf_attr[5], 3);
} // blink
if (fg_color != nullptr)
{
buf_attr[5] |= ((buf_attr[5] & ( 0 << 4)) | ((*fg_color & 7) << 4));
} //Foregrounf color
if(inverse != nullptr) {
if (*inverse & 1) bitSet(buf_attr[5], 7); else bitClear(buf_attr[5], 7);
} // inverse
if(insert != nullptr) {
if (*insert & 1) bitSet(buf_attr[5], 8); else bitClear(buf_attr[5], 8);
} // insert
if(doubleHeight != nullptr) {
if (*doubleHeight & 1) bitSet(buf_attr[5], 9); else bitClear(buf_attr[5], 9);
} // double height
if(masque != nullptr) {
if( *masque & 1) bitSet(buf_attr[5], 10); else bitClear(buf_attr[5], 10);
} // masquage (Conceal)
if(doubleWidth != nullptr) {
if (*doubleWidth & 1) bitSet(buf_attr[5], 11); else bitClear(buf_attr[5], 11);
} // double width
if (typeSet != nullptr) {
//buf_attr[5] |= (*typeSet & 7) << 12;
buf_attr[5] |= ((buf_attr[5] & ( 7 << 12)) | ((*typeSet & 0xF) << 12));
} // type set
//buf_attr[5] = code_attr;
Serial.printf("\r\n\r\nTypeset: %d\r\n", (buf_attr[5] >> 12) & 0xF); // type set
Serial.printf("Double width: %d\r\n", bitRead(buf_attr[5], 11)); // double width
Serial.printf("Conceal: %d\r\n", bitRead(buf_attr[5], 10)); // madquage
Serial.printf("Double height: %d\r\n", bitRead(buf_attr[5], 9)); // double height
Serial.printf("Insert: %d\r\n", bitRead(buf_attr[5], 8)); // insert
Serial.printf("Inverse: %d\r\n", bitRead(buf_attr[5], 7)); // inverse
Serial.printf("Foreground: %d\r\n", (buf_attr[5] >> 4) & 7); // Foreground
Serial.printf("Flash: %d\r\n", bitRead(buf_attr[5], 3)); // blink
Serial.printf("Background: %d\r\n\r\n", buf_attr[5] & 0x07); // Background
Serial.print(buf_attr[5], HEX);
Serial.printf("\r\nbuf_attr[5] = 0x%04X\r\n", buf_attr[5]);
}*/
/*void saveContext(uint8_t typeSet, uint8_t doubleWidth, uint8_t masque,uint8_t doubleHeight,uint8_t insert,uint8_t inverse,uint8_t fg_color, uint8_t blink,uint8_t bg_color)
{
uint16_t code_attr;
code_attr = 0;
code_attr = bg_color & 7; // backgroune color
if (blink & 1) bitSet(code_attr, 3); else bitClear(code_attr, 3); // blink
code_attr |= (fg_color & 7) << 4 ; //Foregrounf color
if (inverse & 1) bitSet(code_attr, 7); else bitClear(code_attr, 7); // inverse
if (insert & 1) bitSet(code_attr, 8); else bitClear(code_attr, 8); // insert
if (doubleHeight & 1) bitSet(code_attr, 9); else bitClear(code_attr, 9); // double height
if( masque & 1) bitSet(code_attr, 10); else bitClear(code_attr, 10); // masquage (Conceal)
if (doubleWidth & 1) bitSet(code_attr, 11); else bitClear(code_attr, 11); // double width
code_attr |= (typeSet & 7) << 12; // type set
code_attr = code_attr;
Serial.printf("\r\n\r\nTypeset: %d\r\n", (code_attr >> 12) & 0xF); // type set
Serial.printf("Double width: %d\r\n", bitRead(code_attr, 11)); // double width
Serial.printf("Conceal: %d\r\n", bitRead(code_attr, 10)); // madquage
Serial.printf("Double height: %d\r\n", bitRead(code_attr, 9)); // double height
Serial.printf("Insert: %d\r\n", bitRead(code_attr, 8)); // insert
Serial.printf("Inverse: %d\r\n", bitRead(code_attr, 7)); // inverse
Serial.printf("Foreground: %d\r\n", (code_attr >> 4) & 7); // Foreground
Serial.printf("Insert: %d\r\n", bitRead(code_attr, 3)); // blink
Serial.printf("Background: %d\r\n\r\n", code_attr & 0x07); // Background
Serial.print(code_attr, HEX);
Serial.printf("\r\ncode_attr = %04X\r\n", code_attr);
}*/
/*void saveContext(uint8_t *typeSet, uint8_t *doubleWidth, uint8_t *masque,uint8_t *doubleHeight,uint8_t *insert,uint8_t *inverse,uint8_t *fg_color, uint8_t *blink,uint8_t *bg_color)
{
if(bg_color != nullptr) {
buf_attr[5] = *bg_color & 7;
} // backgroune color
if (blink != nullptr) {
if (*blink & 1) bitSet(buf_attr[5], 3); else bitClear(buf_attr[5], 3);
} // blink
if (fg_color != nullptr)
{
buf_attr[5] |= (*fg_color & 7) << 4 ;
} //Foregrounf color
if(inverse != nullptr) {
if (*inverse & 1) bitSet(buf_attr[5], 7); else bitClear(buf_attr[5], 7);
} // inverse
if(insert != nullptr) {
if (*insert & 1) bitSet(buf_attr[5], 8); else bitClear(buf_attr[5], 8);
} // insert
if(doubleHeight != nullptr) {
if (*doubleHeight & 1) bitSet(buf_attr[5], 9); else bitClear(buf_attr[5], 9);
} // double height
if(masque != nullptr) {
if( *masque & 1) bitSet(buf_attr[5], 10); else bitClear(buf_attr[5], 10);
} // masquage (Conceal)
if(doubleWidth != nullptr) {
if (*doubleWidth & 1) bitSet(buf_attr[5], 11); else bitClear(buf_attr[5], 11);
} // double width
if (typeSet != nullptr) {
buf_attr[5] |= (*typeSet & 7) << 12;
} // type set
Serial.printf("\r\n\r\nTypeset: %d\r\n", (buf_attr[5] >> 12) & 0xF); // type set
Serial.printf("Double width: %d\r\n", bitRead(buf_attr[5], 11)); // double width
Serial.printf("Conceal: %d\r\n", bitRead(buf_attr[5], 10)); // madquage
Serial.printf("Double height: %d\r\n", bitRead(buf_attr[5], 9)); // double height
Serial.printf("Insert: %d\r\n", bitRead(buf_attr[5], 8)); // insert
Serial.printf("Inverse: %d\r\n", bitRead(buf_attr[5], 7)); // inverse
Serial.printf("Foreground: %d\r\n", (buf_attr[5] >> 4) & 7); // Foreground
Serial.printf("Insert: %d\r\n", bitRead(buf_attr[5], 3)); // blink
Serial.printf("Background: %d\r\n\r\n", buf_attr[5] & 0x07); // Background
Serial.print(buf_attr[5], HEX);
Serial.printf("\r\nbuf_attr[5] = 0x%04X\r\n", buf_attr[5]);*/
/* Serial.printf("\r\n\r\nTypeset: %d\r\n", (code_attr >> 12) & 0xF); // type set
Serial.printf("Double width: %d\r\n", bitRead(code_attr, 11)); // double width
Serial.printf("Conceal: %d\r\n", bitRead(code_attr, 10)); // madquage
Serial.printf("Double height: %d\r\n", bitRead(code_attr, 9)); // double height
Serial.printf("Insert: %d\r\n", bitRead(code_attr, 8)); // insert
Serial.printf("Inverse: %d\r\n", bitRead(code_attr, 7)); // inverse
Serial.printf("Foreground: %d\r\n", (code_attr >> 4) & 7); // Foreground
Serial.printf("Insert: %d\r\n", bitRead(code_attr, 3)); // blink
Serial.printf("Background: %d\r\n\r\n", code_attr & 0x07); // Background
Serial.print(code_attr, HEX);
Serial.printf("\r\ncode_attr = 0x%04X\r\n", code_attr);*/
//}
////////////////////////////////////////////////////////////////////////
void loop() {
}
////////////////////////////////////////////////////////////////////////