mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-27 02:05:10 +03:00
Fixes #2544
This commit is contained in:
parent
4ea9e5c11f
commit
7d2e48a99b
2 changed files with 59 additions and 57 deletions
|
@ -45,28 +45,30 @@ int getFileType(const QString &fullFileName)
|
||||||
|
|
||||||
FirmwareInterface::FirmwareInterface(const QString &filename):
|
FirmwareInterface::FirmwareInterface(const QString &filename):
|
||||||
flash(MAX_FSIZE, 0),
|
flash(MAX_FSIZE, 0),
|
||||||
flash_size(0),
|
flashSize(0),
|
||||||
versionId(0),
|
versionId(0),
|
||||||
splash_offset(0),
|
eepromVersion(0),
|
||||||
splash_size(0),
|
eepromVariant(0),
|
||||||
splash_width(0),
|
splashOffset(0),
|
||||||
splash_height(0),
|
splashSize(0),
|
||||||
|
splashWidth(0),
|
||||||
|
splashHeight(0),
|
||||||
isValidFlag(false)
|
isValidFlag(false)
|
||||||
{
|
{
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { // reading HEX TEXT file
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { // reading HEX TEXT file
|
||||||
QTextStream inputStream(&file);
|
QTextStream inputStream(&file);
|
||||||
flash_size = HexInterface(inputStream).load((uint8_t *)flash.data(), MAX_FSIZE);
|
flashSize = HexInterface(inputStream).load((uint8_t *)flash.data(), MAX_FSIZE);
|
||||||
file.close();
|
file.close();
|
||||||
if (flash_size == 0) {
|
if (flashSize == 0) {
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
flash_size = file.read((char *)flash.data(), MAX_FSIZE);
|
flashSize = file.read((char *)flash.data(), MAX_FSIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_size > 0) {
|
if (flashSize > 0) {
|
||||||
flavour = seekLabel(FW_MARK);
|
flavour = seekLabel(FW_MARK);
|
||||||
version = seekLabel(VERS_MARK);
|
version = seekLabel(VERS_MARK);
|
||||||
if (version.startsWith("opentx-")) {
|
if (version.startsWith("opentx-")) {
|
||||||
|
@ -153,8 +155,8 @@ bool FirmwareInterface::SeekSplash(QByteArray splash)
|
||||||
{
|
{
|
||||||
int start = flash.indexOf(splash);
|
int start = flash.indexOf(splash);
|
||||||
if (start>0) {
|
if (start>0) {
|
||||||
splash_offset = start;
|
splashOffset = start;
|
||||||
splash_size = splash.size();
|
splashSize = splash.size();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -170,8 +172,8 @@ bool FirmwareInterface::SeekSplash(QByteArray sps, QByteArray spe, int size)
|
||||||
if (start>0) {
|
if (start>0) {
|
||||||
int end = start + sps.size() + size;
|
int end = start + sps.size() + size;
|
||||||
if (end == flash.indexOf(spe, end)) {
|
if (end == flash.indexOf(spe, end)) {
|
||||||
splash_offset = start + sps.size();
|
splashOffset = start + sps.size();
|
||||||
splash_size = end - start - sps.size();
|
splashSize = end - start - sps.size();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -190,10 +192,10 @@ bool FirmwareInterface::SeekSplash(QByteArray sps, QByteArray spe, int size)
|
||||||
|
|
||||||
void FirmwareInterface::SeekSplash(void)
|
void FirmwareInterface::SeekSplash(void)
|
||||||
{
|
{
|
||||||
splash_size = 0;
|
splashSize = 0;
|
||||||
splash_offset = 0;
|
splashOffset = 0;
|
||||||
splash_width = SPLASH_WIDTH;
|
splashWidth = SPLASH_WIDTH;
|
||||||
splash_height = SPLASH_HEIGHT;
|
splashHeight = SPLASH_HEIGHT;
|
||||||
splash_format = QImage::Format_Mono;
|
splash_format = QImage::Format_Mono;
|
||||||
|
|
||||||
if (SeekSplash(QByteArray((const char *)gr9x_splash, sizeof(gr9x_splash))) || SeekSplash(QByteArray((const char *)gr9xv4_splash, sizeof(gr9xv4_splash)))) {
|
if (SeekSplash(QByteArray((const char *)gr9x_splash, sizeof(gr9x_splash))) || SeekSplash(QByteArray((const char *)gr9xv4_splash, sizeof(gr9xv4_splash)))) {
|
||||||
|
@ -209,8 +211,8 @@ void FirmwareInterface::SeekSplash(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SeekSplash(QByteArray((const char *)opentxtaranis_splash, sizeof(opentxtaranis_splash)))) {
|
if (SeekSplash(QByteArray((const char *)opentxtaranis_splash, sizeof(opentxtaranis_splash)))) {
|
||||||
splash_width = SPLASHX9D_WIDTH;
|
splashWidth = SPLASHX9D_WIDTH;
|
||||||
splash_height = SPLASHX9D_HEIGHT;
|
splashHeight = SPLASHX9D_HEIGHT;
|
||||||
splash_format = QImage::Format_Indexed8;
|
splash_format = QImage::Format_Indexed8;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -224,8 +226,8 @@ void FirmwareInterface::SeekSplash(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SeekSplash(QByteArray(OTX_SPS_TARANIS, OTX_SPS_SIZE), QByteArray(OTX_SPE, OTX_SPE_SIZE), 6784)) {
|
if (SeekSplash(QByteArray(OTX_SPS_TARANIS, OTX_SPS_SIZE), QByteArray(OTX_SPE, OTX_SPE_SIZE), 6784)) {
|
||||||
splash_width = SPLASHX9D_WIDTH;
|
splashWidth = SPLASHX9D_WIDTH;
|
||||||
splash_height = SPLASHX9D_HEIGHT;
|
splashHeight = SPLASHX9D_HEIGHT;
|
||||||
splash_format = QImage::Format_Indexed8;
|
splash_format = QImage::Format_Indexed8;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -235,14 +237,14 @@ void FirmwareInterface::SeekSplash(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SeekSplash(QByteArray(ERSPLASH_MARKER, sizeof(ERSPLASH_MARKER)))) {
|
if (SeekSplash(QByteArray(ERSPLASH_MARKER, sizeof(ERSPLASH_MARKER)))) {
|
||||||
splash_offset += sizeof(ERSPLASH_MARKER);
|
splashOffset += sizeof(ERSPLASH_MARKER);
|
||||||
splash_size = sizeof(er9x_splash);
|
splashSize = sizeof(er9x_splash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FirmwareInterface::setSplash(const QImage & newsplash)
|
bool FirmwareInterface::setSplash(const QImage & newsplash)
|
||||||
{
|
{
|
||||||
if (splash_offset == 0 || splash_size == 0) {
|
if (splashOffset == 0 || splashSize == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,9 +252,9 @@ bool FirmwareInterface::setSplash(const QImage & newsplash)
|
||||||
QColor color;
|
QColor color;
|
||||||
QByteArray splash;
|
QByteArray splash;
|
||||||
if (splash_format == QImage::Format_Indexed8) {
|
if (splash_format == QImage::Format_Indexed8) {
|
||||||
for (unsigned int y=0; y<splash_height; y++) {
|
for (unsigned int y=0; y<splashHeight; y++) {
|
||||||
unsigned int idx = (y/2)*splash_width;
|
unsigned int idx = (y/2)*splashWidth;
|
||||||
for (unsigned int x=0; x<splash_width; x++, idx++) {
|
for (unsigned int x=0; x<splashWidth; x++, idx++) {
|
||||||
QRgb gray = qGray(newsplash.pixel(x, y));
|
QRgb gray = qGray(newsplash.pixel(x, y));
|
||||||
uint8_t z = ((255-gray)*15)/255;
|
uint8_t z = ((255-gray)*15)/255;
|
||||||
if (y & 1) z <<= 4;
|
if (y & 1) z <<= 4;
|
||||||
|
@ -263,27 +265,27 @@ bool FirmwareInterface::setSplash(const QImage & newsplash)
|
||||||
else {
|
else {
|
||||||
QColor black = QColor(0,0,0);
|
QColor black = QColor(0,0,0);
|
||||||
QImage blackNwhite = newsplash.convertToFormat(QImage::Format_MonoLSB);
|
QImage blackNwhite = newsplash.convertToFormat(QImage::Format_MonoLSB);
|
||||||
for (uint y=0; y<splash_height; y++) {
|
for (uint y=0; y<splashHeight; y++) {
|
||||||
for (uint x=0; x<splash_width; x++) {
|
for (uint x=0; x<splashWidth; x++) {
|
||||||
color = QColor(blackNwhite.pixel(x,y));
|
color = QColor(blackNwhite.pixel(x,y));
|
||||||
b[splash_width*(y/8) + x] |= ((color==black ? 1: 0)<<(y % 8));
|
b[splashWidth*(y/8) + x] |= ((color==black ? 1: 0)<<(y % 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
splash.clear();
|
splash.clear();
|
||||||
splash.append(b, splash_size);
|
splash.append(b, splashSize);
|
||||||
flash.replace(splash_offset, splash_size, splash);
|
flash.replace(splashOffset, splashSize, splash);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FirmwareInterface::getSplashWidth()
|
int FirmwareInterface::getSplashWidth()
|
||||||
{
|
{
|
||||||
return splash_width;
|
return splashWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint FirmwareInterface::getSplashHeight()
|
uint FirmwareInterface::getSplashHeight()
|
||||||
{
|
{
|
||||||
return splash_height;
|
return splashHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage::Format FirmwareInterface::getSplashFormat()
|
QImage::Format FirmwareInterface::getSplashFormat()
|
||||||
|
@ -293,17 +295,17 @@ QImage::Format FirmwareInterface::getSplashFormat()
|
||||||
|
|
||||||
QImage FirmwareInterface::getSplash()
|
QImage FirmwareInterface::getSplash()
|
||||||
{
|
{
|
||||||
if (splash_offset == 0 || splash_size == 0) {
|
if (splashOffset == 0 || splashSize == 0) {
|
||||||
return QImage(); // empty image
|
return QImage(); // empty image
|
||||||
}
|
}
|
||||||
|
|
||||||
if (splash_format == QImage::Format_Indexed8) {
|
if (splash_format == QImage::Format_Indexed8) {
|
||||||
QImage image(splash_width, splash_height, QImage::Format_RGB888);
|
QImage image(splashWidth, splashHeight, QImage::Format_RGB888);
|
||||||
if (splash_offset > 0) {
|
if (splashOffset > 0) {
|
||||||
for (unsigned int y=0; y<splash_height; y++) {
|
for (unsigned int y=0; y<splashHeight; y++) {
|
||||||
unsigned int idx = (y/2)*splash_width;
|
unsigned int idx = (y/2)*splashWidth;
|
||||||
for (unsigned int x=0; x<splash_width; x++, idx++) {
|
for (unsigned int x=0; x<splashWidth; x++, idx++) {
|
||||||
uint8_t byte = flash.at(splash_offset+idx);
|
uint8_t byte = flash.at(splashOffset+idx);
|
||||||
unsigned int z = (y & 1) ? (byte >> 4) : (byte & 0x0F);
|
unsigned int z = (y & 1) ? (byte >> 4) : (byte & 0x0F);
|
||||||
z = 255-(z*255)/15;
|
z = 255-(z*255)/15;
|
||||||
QRgb rgb = qRgb(z, z, z);
|
QRgb rgb = qRgb(z, z, z);
|
||||||
|
@ -314,11 +316,11 @@ QImage FirmwareInterface::getSplash()
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QImage image(splash_width, splash_height, QImage::Format_Mono);
|
QImage image(splashWidth, splashHeight, QImage::Format_Mono);
|
||||||
if (splash_offset > 0) {
|
if (splashOffset > 0) {
|
||||||
for (unsigned int y=0; y<splash_height; y++) {
|
for (unsigned int y=0; y<splashHeight; y++) {
|
||||||
for(unsigned int x=0; x<splash_width; x++) {
|
for(unsigned int x=0; x<splashWidth; x++) {
|
||||||
image.setPixel(x, y, (flash.at(splash_offset+(splash_width*(y/8)+x)) & (1<<(y % 8))) ? 0 : 1);
|
image.setPixel(x, y, (flash.at(splashOffset+(splashWidth*(y/8)+x)) & (1<<(y % 8))) ? 0 : 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,7 +330,7 @@ QImage FirmwareInterface::getSplash()
|
||||||
|
|
||||||
bool FirmwareInterface::hasSplash()
|
bool FirmwareInterface::hasSplash()
|
||||||
{
|
{
|
||||||
return (splash_offset > 0 ? true : false);
|
return (splashOffset > 0 ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FirmwareInterface::isValid()
|
bool FirmwareInterface::isValid()
|
||||||
|
@ -339,7 +341,7 @@ bool FirmwareInterface::isValid()
|
||||||
unsigned int FirmwareInterface::save(QString fileName)
|
unsigned int FirmwareInterface::save(QString fileName)
|
||||||
{
|
{
|
||||||
uint8_t binflash[MAX_FSIZE];
|
uint8_t binflash[MAX_FSIZE];
|
||||||
memcpy(&binflash, flash.constData(), flash_size);
|
memcpy(&binflash, flash.constData(), flashSize);
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
|
|
||||||
int fileType = getFileType(fileName);
|
int fileType = getFileType(fileName);
|
||||||
|
@ -350,16 +352,16 @@ unsigned int FirmwareInterface::save(QString fileName)
|
||||||
}
|
}
|
||||||
QTextStream outputStream(&file);
|
QTextStream outputStream(&file);
|
||||||
HexInterface hex=HexInterface(outputStream);
|
HexInterface hex=HexInterface(outputStream);
|
||||||
hex.save(binflash, flash_size);
|
hex.save(binflash, flashSize);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) { //reading HEX TEXT file
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) { //reading HEX TEXT file
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
file.write((char*)binflash, flash_size);
|
file.write((char*)binflash, flashSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
return flash_size;
|
return flashSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class FirmwareInterface
|
||||||
FirmwareInterface(const QString &filename);
|
FirmwareInterface(const QString &filename);
|
||||||
inline QString getDate() { return date; }
|
inline QString getDate() { return date; }
|
||||||
inline QString getTime() { return time; }
|
inline QString getTime() { return time; }
|
||||||
int getSize() { return flash_size; }
|
int getSize() { return flashSize; }
|
||||||
QString getFlavour() const;
|
QString getFlavour() const;
|
||||||
bool isHardwareCompatible(const FirmwareInterface &previousFirmware) const;
|
bool isHardwareCompatible(const FirmwareInterface &previousFirmware) const;
|
||||||
inline QString getVersion() { return version; }
|
inline QString getVersion() { return version; }
|
||||||
|
@ -64,7 +64,7 @@ class FirmwareInterface
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray flash;
|
QByteArray flash;
|
||||||
uint flash_size;
|
uint flashSize;
|
||||||
QString seekString(const QString & string);
|
QString seekString(const QString & string);
|
||||||
QString seekLabel(const QString & label);
|
QString seekLabel(const QString & label);
|
||||||
void SeekSplash();
|
void SeekSplash();
|
||||||
|
@ -80,10 +80,10 @@ class FirmwareInterface
|
||||||
int eepromVersion;
|
int eepromVersion;
|
||||||
int eepromVariant;
|
int eepromVariant;
|
||||||
QByteArray splash;
|
QByteArray splash;
|
||||||
uint splash_offset;
|
uint splashOffset;
|
||||||
uint splash_size;
|
uint splashSize;
|
||||||
uint splash_width;
|
uint splashWidth;
|
||||||
uint splash_height;
|
uint splashHeight;
|
||||||
QImage::Format splash_format;
|
QImage::Format splash_format;
|
||||||
bool isValidFlag;
|
bool isValidFlag;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue