[Simulator] Dyanamic Simulator virtual hardware generation and many other improvements (#4260)

* Move simulator widgets to subfolder (no code changes).

* [Simulator] Major Simulator re-structuring to reduce code redundancies and allow for fully dynamic simulated hardware setup:
    SimulatorDialog is no longer sub-classed by individual radio UIs, instead a new class is added which handles just the "skin," LCD, and navigation controls (also makes setting up new models much quicker);
    All radio switches/knobs/sliders are populated dynamically based on loaded hardware configuration data (eeprom/bin), including control types and names (in case of no hardware config data, reasonable "factory defaults" are loaded);
    Starting Horus sim with alternate path for RADIO and MODEL data folders is now supported (.otx file is WIP);
    6-way switch now works properly and various other inconsistencies addressed (eg. some Horus analogs were backwards).

* Add missing OpenTX headers to new files.

* [Simulator] Fix loading of Horus hardware settings from Companion simulation.

* Update Travis CI build environment to Qt 5.7.

* [Simulator] Fix 9X missing colored side LCD images, an #include fix, and some cleanup.

* [TravisCI] Set up for parallel Travis builds and use Qt5.7 (#4263)

* Fix starting Simulator with non-existing file/folder structure (now properly creates new ones as needed, including Horus directories with default radio/model);  Temporarily remove option for using .otx file with Horus (until that feature is added).

* Load correct simulator skin for X7 when launching from Companion.

* X7 hardware defaults changed to match production hardware

* Fix minor compiler warning in mdichild.cpp, and some cleanup in eeprominterface.cpp.

* [Simulator] Centralize radio UI flavor determination.

* [Simulator] Updates:
    Add X7 UI flavor;
    Centralize LCD settings;
    Simplify drawing curved UI widgets;
    LCD color can be changed for any 1/4-bit display radio;
    Slight change on default LCD "off" color;
    Refactor LcdWidget to not use globals.

* [Companion] X7 EEPROM import fix

+ cosmetics
+ compilation error fixed on Manjaro

* [Companion] 9XR-PRO EEPROM import fix

+ cosmetics
+ compilation error fixed on Manjaro

* Navigation fix
French translations

* [X7] Main view cosmetics

* Fix switch/ana custom name import

* [Simulator] Add white border above/below X7 bezel, and use white-colored padding on sides; Adjust X7 default LCD color.

* Does this work? (#4269)

Read an Horus SD card produces a temporary .otx file now

* Bsongis/companion warning before automatic conversions (#4271)

* Does this work?

* Warning before automatic conversions

* Force different file name after conversion (#4272)

* Force different file name after conversion

* More detailed instructions

* [Companion] Files automatically named during XXX => Horus conversions
This commit is contained in:
Max Paperno
2017-01-24 07:54:12 +01:00
committed by Bertrand Songis
parent b3f4870da7
commit 17a03e6c18
43 changed files with 3561 additions and 5934 deletions
@@ -0,0 +1,207 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _LCDWIDGET_H_
#define _LCDWIDGET_H_
#include <QApplication>
#include <QWidget>
#include <QPainter>
#include <QClipboard>
#include <QDir>
#include <QDebug>
#include "appdata.h"
class LcdWidget : public QWidget
{
Q_OBJECT
public:
LcdWidget(QWidget * parent = 0):
QWidget(parent),
lcdBuf(NULL),
previousBuf(NULL),
lightEnable(false),
bgDefaultColor(QColor(198, 208, 199))
{
}
~LcdWidget()
{
if (previousBuf) {
free(previousBuf);
}
}
void setData(unsigned char *buf, int width, int height, int depth=1)
{
lcdBuf = buf;
lcdWidth = width;
lcdHeight = height;
lcdDepth = depth;
if (depth >= 8)
lcdSize = (width * height) * ((depth+7) / 8);
else
lcdSize = (width * ((height+7)/8)) * depth;
previousBuf = (unsigned char *)malloc(lcdSize);
memset(previousBuf, 0, lcdSize);
}
void setBgDefaultColor(QColor color)
{
bgDefaultColor = color;
}
void setBackgroundColor(QColor color)
{
_r = color.red();
_g = color.green();
_b = color.blue();
}
void makeScreenshot(const QString & fileName)
{
int width, height;
if (lcdDepth < 12) {
width = 2 * lcdWidth;
height = 2 * lcdHeight;
}
else {
width = lcdWidth;
height = lcdHeight;
}
QPixmap buffer(width, height);
QPainter p(&buffer);
doPaint(p);
if (fileName.isEmpty()) {
qDebug() << "Screenshot saved to clipboard";
QApplication::clipboard()->setPixmap( buffer );
}
else {
qDebug() << "Screenshot" << fileName;
buffer.toImage().save(fileName);
}
}
void onLcdChanged(bool light)
{
if (light != lightEnable || memcmp(previousBuf, lcdBuf, lcdSize)) {
lightEnable = light;
memcpy(previousBuf, lcdBuf, lcdSize);
update();
}
}
protected:
int lcdWidth;
int lcdHeight;
int lcdDepth;
int lcdSize;
unsigned char *lcdBuf;
unsigned char *previousBuf;
bool lightEnable;
int _r, _g, _b;
QColor bgDefaultColor;
inline void doPaint(QPainter & p)
{
QRgb rgb;
if (lcdDepth == 16) {
for (int x=0; x<lcdWidth; x++) {
for (int y=0; y<lcdHeight; y++) {
uint16_t z = ((uint16_t *)lcdBuf)[y * lcdWidth + x];
rgb = qRgb(255*((z&0xF800)>>11)/0x1F, 255*((z&0x07E0)>>5)/0x3F, 255*(z&0x001F)/0x1F);
p.setPen(rgb);
p.drawPoint(x, y);
}
}
}
else if (lcdDepth == 12) {
for (int x=0; x<lcdWidth; x++) {
for (int y=0; y<lcdHeight; y++) {
uint16_t z = ((uint16_t *)lcdBuf)[y * lcdWidth + x];
rgb = qRgb(255*((z&0xF00)>>8)/0x0f, 255*((z&0x0F0)>>4)/0x0f, 255*(z&0x00F)/0x0f);
p.setPen(rgb);
p.drawPoint(x, y);
}
}
}
else {
if (lightEnable)
rgb = qRgb(_r, _g, _b);
else
rgb = bgDefaultColor.rgba();
p.setBackground(QBrush(rgb));
p.eraseRect(0, 0, 2*lcdWidth, 2*lcdHeight);
if (lcdBuf) {
if (lcdDepth == 1) {
rgb = qRgb(0, 0, 0);
p.setPen(rgb);
p.setBrush(QBrush(rgb));
}
unsigned int previousDepth = 0xFF;
for (int y=0; y<lcdHeight; y++) {
unsigned int idx = (y*lcdDepth/8)*lcdWidth;
unsigned int mask = (1 << (y%8));
for (int x=0; x<lcdWidth; x++, idx++) {
if (lcdDepth == 1) {
if (lcdBuf[idx] & mask) {
p.drawRect(2*x, 2*y, 1, 1);
}
}
else {
unsigned int z = (y & 1) ? (lcdBuf[idx] >> 4) : (lcdBuf[idx] & 0x0F);
if (z) {
if (z != previousDepth) {
previousDepth = z;
if (lightEnable)
rgb = qRgb(_r-(z*_r)/15, _g-(z*_g)/15, _b-(z*_b)/15);
else
rgb = qRgb(161-(z*161)/15, 161-(z*161)/15, 161-(z*161)/15);
p.setPen(rgb);
p.setBrush(QBrush(rgb));
}
p.drawRect(2*x, 2*y, 1, 1);
}
}
}
}
}
}
}
void paintEvent(QPaintEvent*)
{
QPainter p(this);
doPaint(p);
}
};
#endif // _LCDWIDGET_H_