diff --git a/companion/src/firmwares/er9x/er9xsimulator.h b/companion/src/firmwares/er9x/er9xsimulator.h index 52de60575..7ec83fc1c 100644 --- a/companion/src/firmwares/er9x/er9xsimulator.h +++ b/companion/src/firmwares/er9x/er9xsimulator.h @@ -54,6 +54,10 @@ class Er9xSimulator : public SimulatorInterface { virtual const char * getError(); + virtual void sendTelemetry(uint8_t * data, unsigned int len) {}; + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value) {}; + protected: Er9xInterface * er9xInterface; diff --git a/companion/src/firmwares/ersky9x/ersky9xsimulator.h b/companion/src/firmwares/ersky9x/ersky9xsimulator.h index 93eaae105..291b5bb73 100644 --- a/companion/src/firmwares/ersky9x/ersky9xsimulator.h +++ b/companion/src/firmwares/ersky9x/ersky9xsimulator.h @@ -54,6 +54,10 @@ class Ersky9xSimulator : public SimulatorInterface { virtual const char * getError(); + virtual void sendTelemetry(uint8_t * data, unsigned int len) {}; + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value) {}; + protected: Ersky9xInterface * ersky9xInterface; diff --git a/companion/src/firmwares/opentx/opentxGruvin9xsimulator.h b/companion/src/firmwares/opentx/opentxGruvin9xsimulator.h index 57a8ac646..fa557d22d 100644 --- a/companion/src/firmwares/opentx/opentxGruvin9xsimulator.h +++ b/companion/src/firmwares/opentx/opentxGruvin9xsimulator.h @@ -56,6 +56,11 @@ class Open9xGruvin9xSimulator : public SimulatorInterface { virtual const char * getError(); + virtual void sendTelemetry(uint8_t * data, unsigned int len) {}; + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value) {}; + + virtual void installTraceHook(void (*callback)(const char *)) {}; }; #endif diff --git a/companion/src/firmwares/opentx/opentxM128simulator.h b/companion/src/firmwares/opentx/opentxM128simulator.h index dacdf9187..43f01948d 100644 --- a/companion/src/firmwares/opentx/opentxM128simulator.h +++ b/companion/src/firmwares/opentx/opentxM128simulator.h @@ -56,6 +56,11 @@ class OpenTxM128Simulator : public SimulatorInterface { virtual const char * getError(); + virtual void sendTelemetry(uint8_t * data, unsigned int len) {}; + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value) {}; + + virtual void installTraceHook(void (*callback)(const char *)) {}; }; #endif diff --git a/companion/src/firmwares/opentx/opentxM64simulator.h b/companion/src/firmwares/opentx/opentxM64simulator.h index 26827403b..2c4e18f3f 100644 --- a/companion/src/firmwares/opentx/opentxM64simulator.h +++ b/companion/src/firmwares/opentx/opentxM64simulator.h @@ -55,6 +55,11 @@ class OpenTxM64Simulator : public SimulatorInterface { virtual const char * getError(); + virtual void sendTelemetry(uint8_t * data, unsigned int len) {}; + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value) {}; + + virtual void installTraceHook(void (*callback)(const char *)) {}; }; #endif diff --git a/companion/src/firmwares/opentx/opentxSky9xsimulator.cpp b/companion/src/firmwares/opentx/opentxSky9xsimulator.cpp index 4f5da3d0c..8a1fd55a3 100644 --- a/companion/src/firmwares/opentx/opentxSky9xsimulator.cpp +++ b/companion/src/firmwares/opentx/opentxSky9xsimulator.cpp @@ -76,6 +76,7 @@ namespace Open9xSky9x { #include "radio/src/eeprom_raw.cpp" #include "radio/src/eeprom_conversions.cpp" #include "radio/src/opentx.cpp" +// #include "radio/src/debug.cpp" // only included once in Taranis simulator because functions are exported as C and don't support namespaces #include "radio/src/main_arm.cpp" #include "radio/src/strhelpers.cpp" #include "radio/src/switches.cpp" @@ -281,3 +282,13 @@ const char * Open9xSky9xSimulator::getError() #define GETERROR_IMPORT #include "simulatorimport.h" } + +void Open9xSky9xSimulator::setTrainerInput(unsigned int inputNumber, int16_t value) +{ +#define SETTRAINER_IMPORT +#include "simulatorimport.h" +} + +void Open9xSky9xSimulator::installTraceHook(void (*callback)(const char *)) { + ::traceCallback = callback; +} diff --git a/companion/src/firmwares/opentx/opentxSky9xsimulator.h b/companion/src/firmwares/opentx/opentxSky9xsimulator.h index 9af799f18..6d353574a 100644 --- a/companion/src/firmwares/opentx/opentxSky9xsimulator.h +++ b/companion/src/firmwares/opentx/opentxSky9xsimulator.h @@ -56,6 +56,11 @@ class Open9xSky9xSimulator : public SimulatorInterface { virtual const char * getError(); + virtual void sendTelemetry(uint8_t * data, unsigned int len) {}; + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value); + + virtual void installTraceHook(void (*callback)(const char *)); }; #endif diff --git a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp index 226ee53ba..ac826da9e 100644 --- a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp +++ b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp @@ -78,6 +78,7 @@ inline int geteepromsize() { #include "radio/src/eeprom_conversions.cpp" #include "radio/src/eeprom_rlc.cpp" #include "radio/src/opentx.cpp" +#include "radio/src/debug.cpp" #include "radio/src/main_arm.cpp" #include "radio/src/strhelpers.cpp" #include "radio/src/switches.cpp" @@ -321,3 +322,18 @@ const char * OpentxTaranisSimulator::getError() #define GETERROR_IMPORT #include "simulatorimport.h" } + +void OpentxTaranisSimulator::sendTelemetry(uint8_t * data, unsigned int len) +{ + processSportPacket(data); +} + +void OpentxTaranisSimulator::setTrainerInput(unsigned int inputNumber, int16_t value) +{ +#define SETTRAINER_IMPORT +#include "simulatorimport.h" +} + +void OpentxTaranisSimulator::installTraceHook(void (*callback)(const char *)) { + ::traceCallback = callback; +} diff --git a/companion/src/firmwares/opentx/opentxTaranisSimulator.h b/companion/src/firmwares/opentx/opentxTaranisSimulator.h index d5113db7a..459832ca2 100644 --- a/companion/src/firmwares/opentx/opentxTaranisSimulator.h +++ b/companion/src/firmwares/opentx/opentxTaranisSimulator.h @@ -56,6 +56,11 @@ class OpentxTaranisSimulator : public SimulatorInterface { virtual const char * getError(); + virtual void sendTelemetry(uint8_t * data, unsigned int len); + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value); + + virtual void installTraceHook(void (*callback)(const char *)); }; #endif diff --git a/companion/src/firmwares/opentx/opentxTaranisX9ESimulator.cpp b/companion/src/firmwares/opentx/opentxTaranisX9ESimulator.cpp index 505260ccc..d80d6239e 100755 --- a/companion/src/firmwares/opentx/opentxTaranisX9ESimulator.cpp +++ b/companion/src/firmwares/opentx/opentxTaranisX9ESimulator.cpp @@ -79,6 +79,7 @@ inline int geteepromsize() { #include "radio/src/eeprom_conversions.cpp" #include "radio/src/eeprom_rlc.cpp" #include "radio/src/opentx.cpp" +// #include "radio/src/debug.cpp" // only included once in Taranis simulator because functions are exported as C and don't support namespaces #include "radio/src/main_arm.cpp" #include "radio/src/strhelpers.cpp" #include "radio/src/switches.cpp" @@ -325,3 +326,18 @@ const char * OpentxTaranisX9ESimulator::getError() #define GETERROR_IMPORT #include "simulatorimport.h" } + +void OpentxTaranisX9ESimulator::sendTelemetry(uint8_t * data, unsigned int len) +{ + processSportPacket(data); +} + +void OpentxTaranisX9ESimulator::setTrainerInput(unsigned int inputNumber, int16_t value) +{ +#define SETTRAINER_IMPORT +#include "simulatorimport.h" +} + +void OpentxTaranisX9ESimulator::installTraceHook(void (*callback)(const char *)) { + ::traceCallback = callback; +} diff --git a/companion/src/firmwares/opentx/opentxTaranisX9ESimulator.h b/companion/src/firmwares/opentx/opentxTaranisX9ESimulator.h index 6141e3dcf..3ae14e303 100755 --- a/companion/src/firmwares/opentx/opentxTaranisX9ESimulator.h +++ b/companion/src/firmwares/opentx/opentxTaranisX9ESimulator.h @@ -56,6 +56,11 @@ class OpentxTaranisX9ESimulator : public SimulatorInterface { virtual const char * getError(); + virtual void sendTelemetry(uint8_t * data, unsigned int len); + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value); + + virtual void installTraceHook(void (*callback)(const char *)); }; #endif diff --git a/companion/src/simulation/CMakeLists.txt b/companion/src/simulation/CMakeLists.txt index 2b5f5cc6e..93b1fe6f4 100644 --- a/companion/src/simulation/CMakeLists.txt +++ b/companion/src/simulation/CMakeLists.txt @@ -1,10 +1,16 @@ set(simulation_SRCS simulatordialog.cpp + telemetrysimu.cpp + trainersimu.cpp + debugoutput.cpp ) set(simulation_UIS simulatordialog-9x.ui simulatordialog-taranis.ui + telemetrysimu.ui + trainersimu.ui + debugoutput.ui ) set(simulation_HDRS @@ -14,6 +20,9 @@ set(simulation_HDRS xcursorwidget.h xmenuwidget.h myslider.h + telemetrysimu.h + trainersimu.h + debugoutput.h ) if(SDL_FOUND) diff --git a/companion/src/simulation/debugoutput.cpp b/companion/src/simulation/debugoutput.cpp new file mode 100644 index 000000000..4f25a228c --- /dev/null +++ b/companion/src/simulation/debugoutput.cpp @@ -0,0 +1,45 @@ +#include +#include +#include "debugoutput.h" +#include "ui_debugoutput.h" + +DebugOutput::DebugOutput(QWidget * parent): + QDialog(parent), + ui(new Ui::DebugOutput) +{ + ui->setupUi(this); + +#ifdef __APPLE__ + QFont newFont("Courier", 13); + ui->Output->setFont(newFont); + ui->Output->setAttribute(Qt::WA_MacNormalSize); +#endif +#if defined WIN32 || !defined __GNUC__ + QFont newFont("Courier", 9); + ui->Output->setFont(newFont); +#endif + +} + +DebugOutput::~DebugOutput() +{ + delete ui; +} + +void DebugOutput::traceCallback(const QString & text) +{ + // ui->Output->appendPlainText(text); + QTextCursor cursor(ui->Output->textCursor()); + + // is the scrollbar at the end? + bool atEnd = (ui->Output->verticalScrollBar()->value() == ui->Output->verticalScrollBar()->maximum()); + + cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor, 1); + cursor.insertText(text); + + if (atEnd) { + ui->Output->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum); + } +} + + diff --git a/companion/src/simulation/debugoutput.h b/companion/src/simulation/debugoutput.h new file mode 100644 index 000000000..bd91e6a3e --- /dev/null +++ b/companion/src/simulation/debugoutput.h @@ -0,0 +1,32 @@ +#ifndef debugoutput_h +#define debugoutput_h + + +#include +#include "simulatorinterface.h" + +namespace Ui { + class DebugOutput; +} + + +class DebugOutput : public QDialog +{ + Q_OBJECT + + public: + explicit DebugOutput(QWidget * parent); + virtual ~DebugOutput(); + void traceCallback(const QString & text); + + protected: + + private: + Ui::DebugOutput * ui; + + private slots: + +}; + +#endif + diff --git a/companion/src/simulation/debugoutput.ui b/companion/src/simulation/debugoutput.ui new file mode 100644 index 000000000..f14929b02 --- /dev/null +++ b/companion/src/simulation/debugoutput.ui @@ -0,0 +1,50 @@ + + + DebugOutput + + + + 0 + 0 + 711 + 470 + + + + Debug Output + + + + :/icon.png:/icon.png + + + + + + + + + Courier New + 10 + + + + Qt::ScrollBarAlwaysOn + + + QPlainTextEdit::NoWrap + + + true + + + + + + + + + + + + diff --git a/companion/src/simulation/simulatordialog.cpp b/companion/src/simulation/simulatordialog.cpp index b11b985a8..a072baad2 100644 --- a/companion/src/simulation/simulatordialog.cpp +++ b/companion/src/simulation/simulatordialog.cpp @@ -9,6 +9,42 @@ #define RESX 1024 int SimulatorDialog::screenshotIdx = 0; +SimulatorDialog * traceCallbackInstance = 0; + +void traceCb(const char * text) { + // divert C callback into simulator instance + if (traceCallbackInstance) { + traceCallbackInstance->traceCallback(text); + } +} + +void SimulatorDialog::traceCallback(const char * text) +{ + // this function is called from other threads + traceMutex.lock(); + // limit the size of list + if (traceList.size() < 1000) { + traceList.append(QString(text)); + } + traceMutex.unlock(); +} + +void SimulatorDialog::updateDebugOutput() +{ + traceMutex.lock(); + while (!traceList.isEmpty()) { + QString text = traceList.takeFirst(); + traceBuffer.append(text); + // limit the size of traceBuffer + if (traceBuffer.size() > 10*1024) { + traceBuffer.remove(0, 1*1024); + } + if (DebugOut) { + DebugOut->traceCallback(QString(text)); + } + } + traceMutex.unlock(); +} SimulatorDialog::SimulatorDialog(QWidget * parent, unsigned int flags): QDialog(parent), @@ -19,10 +55,19 @@ SimulatorDialog::SimulatorDialog(QWidget * parent, unsigned int flags): simulator(NULL), lastPhase(-1), beepVal(0), + TelemetrySimu(0), + TrainerSimu(0), + DebugOut(0), buttonPressed(0), trimPressed (TRIM_NONE), middleButtonPressed(false) { + //shorcut for telemetry simulator + // new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_T), this, SLOT(openTelemetrySimulator())); + new QShortcut(QKeySequence(Qt::Key_F4), this, SLOT(openTelemetrySimulator())); + new QShortcut(QKeySequence(Qt::Key_F5), this, SLOT(openTrainerSimulator())); + new QShortcut(QKeySequence(Qt::Key_F6), this, SLOT(openDebugOutput())); + traceCallbackInstance = this; } uint32_t SimulatorDialog9X::switchstatus = 0; @@ -37,6 +82,9 @@ SimulatorDialog9X::SimulatorDialog9X(QWidget * parent, unsigned int flags): initUi(ui); + // install simulator TRACE hook + simulator->installTraceHook(traceCb); + backLight = g.backLight(); if (backLight > 4) backLight = 0; switch (backLight) { @@ -109,6 +157,10 @@ SimulatorDialogTaranis::SimulatorDialogTaranis(QWidget * parent, unsigned int fl lcdDepth = 4; initUi(ui); + + // install simulator TRACE hook + simulator->installTraceHook(traceCb); + dialP_4 = ui->dialP_4; ui->lcd->setBackgroundColor(47, 123, 227); @@ -154,6 +206,7 @@ SimulatorDialogTaranis::~SimulatorDialogTaranis() SimulatorDialog::~SimulatorDialog() { + traceCallbackInstance = 0; delete timer; delete simulator; } @@ -215,6 +268,28 @@ void SimulatorDialog::onTrimReleased() trimPressed = TRIM_NONE; } +void SimulatorDialog::openTelemetrySimulator() +{ + TelemetrySimu = new TelemetrySimulator(this, simulator); + TelemetrySimu->setAttribute(Qt::WA_DeleteOnClose, true); + TelemetrySimu->show(); +} + +void SimulatorDialog::openTrainerSimulator() +{ + TrainerSimu = new TrainerSimulator(this, simulator); + TrainerSimu->setAttribute(Qt::WA_DeleteOnClose, true); + TrainerSimu->show(); +} + +void SimulatorDialog::openDebugOutput() +{ + DebugOut = new DebugOutput(this); + DebugOut->setAttribute(Qt::WA_DeleteOnClose, true); + DebugOut->traceCallback(traceBuffer); + DebugOut->show(); +} + void SimulatorDialog::keyPressEvent (QKeyEvent *event) { switch (event->key()) { @@ -559,6 +634,8 @@ void SimulatorDialog::onTimerEvent() QApplication::beep(); } } + + updateDebugOutput(); } void SimulatorDialog::centerSticks() diff --git a/companion/src/simulation/simulatordialog.h b/companion/src/simulation/simulatordialog.h index 16ec799ee..1da6e5e3e 100644 --- a/companion/src/simulation/simulatordialog.h +++ b/companion/src/simulation/simulatordialog.h @@ -4,6 +4,9 @@ #include #include "modeledit/node.h" #include "eeprominterface.h" +#include "telemetrysimu.h" +#include "trainersimu.h" +#include "debugoutput.h" #ifdef JOYSTICKS #include "joystick.h" @@ -38,6 +41,7 @@ class SimulatorDialog : public QDialog void start(const char * filename); void start(QByteArray & eeprom); + virtual void traceCallback(const char * text); protected: template void initUi(T * ui); @@ -95,6 +99,14 @@ class SimulatorDialog : public QDialog int lcdWidth; int lcdDepth; + TelemetrySimulator * TelemetrySimu; + TrainerSimulator * TrainerSimu; + DebugOutput * DebugOut; + + QString traceBuffer; + QMutex traceMutex; + QList traceList; + void updateDebugOutput(); protected: virtual void closeEvent(QCloseEvent *); @@ -125,6 +137,9 @@ class SimulatorDialog : public QDialog void onTimerEvent(); void onTrimPressed(); void onTrimReleased(); + void openTelemetrySimulator(); + void openTrainerSimulator(); + void openDebugOutput(); #ifdef JOYSTICKS void onjoystickAxisValueChanged(int axis, int value); diff --git a/companion/src/simulation/simulatorimport.h b/companion/src/simulation/simulatorimport.h index 314eeffd4..0766ce683 100644 --- a/companion/src/simulation/simulatorimport.h +++ b/companion/src/simulation/simulatorimport.h @@ -101,4 +101,9 @@ return lcd_buf; return main_thread_error; #endif +#ifdef SETTRAINER_IMPORT +#undef SETTRAINER_IMPORT + ppmInValid = 100; + g_ppmIns[inputNumber] = LIMIT(-512, value, 512); +#endif diff --git a/companion/src/simulation/simulatorinterface.h b/companion/src/simulation/simulatorinterface.h index 10a258ba2..23d7b811c 100644 --- a/companion/src/simulation/simulatorinterface.h +++ b/companion/src/simulation/simulatorinterface.h @@ -80,6 +80,11 @@ class SimulatorInterface { virtual const char * getError() = 0; + virtual void sendTelemetry(uint8_t * data, unsigned int len) = 0; + + virtual void setTrainerInput(unsigned int inputNumber, int16_t value) = 0; + + virtual void installTraceHook(void (*callback)(const char *)) = 0; }; #endif diff --git a/companion/src/simulation/telemetrysimu.cpp b/companion/src/simulation/telemetrysimu.cpp new file mode 100644 index 000000000..36e6982ab --- /dev/null +++ b/companion/src/simulation/telemetrysimu.cpp @@ -0,0 +1,85 @@ +#include +#include "telemetrysimu.h" +#include "ui_telemetrysimu.h" +#include "radio/src/telemetry/frsky.h" + +TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator): + QDialog(parent), + ui(new Ui::TelemetrySimulator), + simulator(simulator) +{ + ui->setupUi(this); + + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent())); + timer->start(100); +} + +TelemetrySimulator::~TelemetrySimulator() +{ + timer->stop(); + delete ui; +} + +void TelemetrySimulator::onTimerEvent() +{ + if (ui->Simulate->isChecked()) { + generateTelemetryFrame(); + } +} + +void setSportPacketCrc(uint8_t * packet) +{ + short crc = 0; + for (int i=1; i> 8; //0-100 + crc &= 0x00ff; + crc += crc >> 8; //0-0FF + crc &= 0x00ff; + } + packet[FRSKY_SPORT_PACKET_SIZE-1] = 0xFF - (crc & 0x00ff); + //TRACE("crc set: %x", packet[FRSKY_SPORT_PACKET_SIZE-1]); +} + +void generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data) +{ + packet[0] = dataId; + packet[1] = prim; + *((uint16_t *)(packet+2)) = appId; + *((int32_t *)(packet+4)) = data; + setSportPacketCrc(packet); +} + +void TelemetrySimulator::generateTelemetryFrame() +{ + static int item = 0; + uint8_t buffer[FRSKY_SPORT_PACKET_SIZE]; + + switch(item++) { + case 0: + generateSportPacket(buffer, 1, DATA_FRAME, RSSI_ID, LIMIT(0, ui->Rssi->text().toInt(), 0xFF)); + break; + + case 1: + generateSportPacket(buffer, 1, DATA_FRAME, XJT_VERSION_ID, 11); + break; + + case 2: + generateSportPacket(buffer, 1, DATA_FRAME, SWR_ID, LIMIT(0, ui->Swr->text().toInt(), 0xFF)); + break; + + case 3: + generateSportPacket(buffer, 1, DATA_FRAME, ADC1_ID, LIMIT(0, ui->A1->text().toInt(), 0xFF)); + break; + + case 4: + generateSportPacket(buffer, 1, DATA_FRAME, ADC2_ID, LIMIT(0, ui->A2->text().toInt(), 0xFF)); + break; + + default: + item = 0; + return; + } + simulator->sendTelemetry(buffer, 9); +} \ No newline at end of file diff --git a/companion/src/simulation/telemetrysimu.h b/companion/src/simulation/telemetrysimu.h new file mode 100644 index 000000000..2d89d9613 --- /dev/null +++ b/companion/src/simulation/telemetrysimu.h @@ -0,0 +1,38 @@ +#ifndef telemetrysimu_h +#define telemetrysimu_h + + +#include +#include +#include "simulatorinterface.h" + +namespace Ui { + class TelemetrySimulator; +} + + +class TelemetrySimulator : public QDialog +{ + Q_OBJECT + + public: + explicit TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator); + virtual ~TelemetrySimulator(); + + + protected: + + private: + Ui::TelemetrySimulator * ui; + QTimer * timer; + SimulatorInterface *simulator; + + void generateTelemetryFrame(); + + private slots: + void onTimerEvent(); + +}; + +#endif + diff --git a/companion/src/simulation/telemetrysimu.ui b/companion/src/simulation/telemetrysimu.ui new file mode 100644 index 000000000..6f6a661a4 --- /dev/null +++ b/companion/src/simulation/telemetrysimu.ui @@ -0,0 +1,72 @@ + + + TelemetrySimulator + + + + 0 + 0 + 184 + 165 + + + + Telemetry Simulator + + + + + + + + + + + + + + RSSI + + + + + + + + + + A1 + + + + + + + SWR + + + + + + + simulate + + + + + + + A2 + + + + + + + + + + + + + diff --git a/companion/src/simulation/trainersimu.cpp b/companion/src/simulation/trainersimu.cpp new file mode 100644 index 000000000..e96369230 --- /dev/null +++ b/companion/src/simulation/trainersimu.cpp @@ -0,0 +1,113 @@ +#include +#include "trainersimu.h" +#include "ui_trainersimu.h" +#include "helpers.h" + +#define GBALL_SIZE 20 +#define RESX 512 + +TrainerSimulator::TrainerSimulator(QWidget * parent, SimulatorInterface * simulator): + QDialog(parent), + ui(new Ui::TrainerSimulator), + simulator(simulator) +{ + ui->setupUi(this); + leftStick = ui->leftStick; + rightStick = ui->rightStick; + + setupSticks(); + + // resize(0, 0); // to force min height, min width + setFixedSize(width(), height()); + + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent())); + timer->start(10); +} + +TrainerSimulator::~TrainerSimulator() +{ + timer->stop(); + delete ui; +} + +void TrainerSimulator::centerSticks() +{ + if (leftStick->scene()) + nodeLeft->stepToCenter(); + + if (rightStick->scene()) + nodeRight->stepToCenter(); +} + +void TrainerSimulator::setupSticks() +{ + QGraphicsScene *leftScene = new QGraphicsScene(leftStick); + leftScene->setItemIndexMethod(QGraphicsScene::NoIndex); + leftStick->setScene(leftScene); + + // leftStick->scene()->addLine(0,10,20,30); + + QGraphicsScene *rightScene = new QGraphicsScene(rightStick); + rightScene->setItemIndexMethod(QGraphicsScene::NoIndex); + rightStick->setScene(rightScene); + + // rightStick->scene()->addLine(0,10,20,30); + + nodeLeft = new Node(); + nodeLeft->setPos(-GBALL_SIZE/2,-GBALL_SIZE/2); + nodeLeft->setBallSize(GBALL_SIZE); + leftScene->addItem(nodeLeft); + + nodeRight = new Node(); + nodeRight->setPos(-GBALL_SIZE/2,-GBALL_SIZE/2); + nodeRight->setBallSize(GBALL_SIZE); + rightScene->addItem(nodeRight); +} + +void TrainerSimulator::resizeEvent(QResizeEvent *event) +{ + if (leftStick->scene()) { + QRect qr = leftStick->contentsRect(); + qreal w = (qreal)qr.width() - GBALL_SIZE; + qreal h = (qreal)qr.height() - GBALL_SIZE; + qreal cx = (qreal)qr.width()/2; + qreal cy = (qreal)qr.height()/2; + leftStick->scene()->setSceneRect(-cx,-cy,w,h); + + QPointF p = nodeLeft->pos(); + p.setX(qMin(cx, qMax(p.x(), -cx))); + p.setY(qMin(cy, qMax(p.y(), -cy))); + nodeLeft->setPos(p); + } + + if (rightStick->scene()) { + QRect qr = rightStick->contentsRect(); + qreal w = (qreal)qr.width() - GBALL_SIZE; + qreal h = (qreal)qr.height() - GBALL_SIZE; + qreal cx = (qreal)qr.width()/2; + qreal cy = (qreal)qr.height()/2; + rightStick->scene()->setSceneRect(-cx,-cy,w,h); + + QPointF p = nodeRight->pos(); + p.setX(qMin(cx, qMax(p.x(), -cx))); + p.setY(qMin(cy, qMax(p.y(), -cy))); + nodeRight->setPos(p); + } + QDialog::resizeEvent(event); +} + + +void TrainerSimulator::onTimerEvent() +{ + centerSticks(); + setTrainerInputs(); +} + +void TrainerSimulator::setTrainerInputs() +{ + simulator->setTrainerInput(0, int( 512* nodeLeft->getX())); // LEFT HORZ + simulator->setTrainerInput(1, int(-512* nodeLeft->getY())); // LEFT VERT + simulator->setTrainerInput(2, int(-512*nodeRight->getY())); // RGHT VERT + simulator->setTrainerInput(3, int( 512*nodeRight->getX())); // RGHT HORZ +} \ No newline at end of file diff --git a/companion/src/simulation/trainersimu.h b/companion/src/simulation/trainersimu.h new file mode 100644 index 000000000..0bfc646dd --- /dev/null +++ b/companion/src/simulation/trainersimu.h @@ -0,0 +1,46 @@ +#ifndef trainersimu_h +#define trainersimu_h + + +#include +#include +#include "modeledit/node.h" +#include "simulatorinterface.h" + +namespace Ui { + class TrainerSimulator; +} + + +class TrainerSimulator : public QDialog +{ + Q_OBJECT + + public: + explicit TrainerSimulator(QWidget * parent, SimulatorInterface * simulator); + virtual ~TrainerSimulator(); + + + protected: + + private: + Ui::TrainerSimulator * ui; + QTimer * timer; + SimulatorInterface *simulator; + + QGraphicsView * leftStick, * rightStick; + Node *nodeLeft; + Node *nodeRight; + + void centerSticks(); + void setupSticks(); + void resizeEvent(QResizeEvent *event = 0); + void setTrainerInputs(); + + private slots: + void onTimerEvent(); + +}; + +#endif + diff --git a/companion/src/simulation/trainersimu.ui b/companion/src/simulation/trainersimu.ui new file mode 100644 index 000000000..d4e0ca2b5 --- /dev/null +++ b/companion/src/simulation/trainersimu.ui @@ -0,0 +1,95 @@ + + + TrainerSimulator + + + + 0 + 0 + 566 + 268 + + + + Trainer simulator + + + + + 0 + 0 + 563 + 267 + + + + QFrame::Panel + + + QFrame::Raised + + + 2 + + + + 5 + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 17 + 20 + + + + + + + + + 245 + 245 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + 245 + 245 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + + + + diff --git a/radio/src/Makefile b/radio/src/Makefile index c4a132bb8..98286a8fc 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -389,6 +389,7 @@ ifeq ($(PCB), $(filter $(PCB), STD 9X 9XR)) EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp LCDSRC = lcd_common.cpp lcd_default.cpp PULSESSRC = pulses/pulses_avr.cpp + CPPSRC += debug.cpp ifeq ($(PCB), 9XR) FLAVOUR = 9xr @@ -456,6 +457,7 @@ ifeq ($(PCB), $(filter $(PCB), STD128 9X128 9XR128)) EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp LCDSRC = lcd_common.cpp lcd_default.cpp PULSESSRC = pulses/pulses_avr.cpp + CPPSRC += debug.cpp ifeq ($(PCB), 9XR128) FLAVOUR = 9xr128 @@ -519,6 +521,7 @@ ifeq ($(PCB), $(filter $(PCB), 9X2561)) EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp LCDSRC = lcd_common.cpp lcd_default.cpp PULSESSRC = pulses/pulses_avr.cpp + CPPSRC += debug.cpp ifeq ($(PCB), 9XR2561) FLAVOUR = 9xr2561 @@ -584,7 +587,7 @@ ifeq ($(PCB), GRUVIN9X) EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp LCDSRC = lcd_common.cpp lcd_default.cpp PULSESSRC = pulses/pulses_avr.cpp - CPPSRC += audio_avr.cpp haptic.cpp + CPPSRC += audio_avr.cpp haptic.cpp debug.cpp ifeq ($(SDCARD), YES) CPPDEFS += -DRTCLOCK @@ -626,7 +629,7 @@ ifeq ($(PCB), MEGA2560) EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp LCDSRC = lcd_common.cpp lcd_default.cpp PULSESSRC = pulses/pulses_avr.cpp - CPPSRC += audio_avr.cpp + CPPSRC += audio_avr.cpp debug.cpp ifeq ($(PCBREV), ST7565P) EXTRABOARDSRC = targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp @@ -711,7 +714,7 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO)) PULSESSRC = pulses/pulses_arm.cpp pulses/ppm_arm.cpp pulses/pxx_arm.cpp pulses/dsm2_arm.cpp CPPSRC += tasks_arm.cpp audio_arm.cpp haptic.cpp gui/view_about.cpp gui/view_text.cpp telemetry/telemetry.cpp CPPSRC += targets/sky9x/telemetry_driver.cpp targets/sky9x/second_serial_driver.cpp targets/sky9x/pwr_driver.cpp targets/sky9x/adc_driver.cpp targets/sky9x/eeprom_driver.cpp targets/sky9x/pulses_driver.cpp targets/sky9x/keys_driver.cpp targets/sky9x/audio_driver.cpp targets/sky9x/buzzer_driver.cpp targets/sky9x/haptic_driver.cpp targets/sky9x/sdcard_driver.cpp targets/sky9x/massstorage.cpp - CPPSRC += loadboot.cpp + CPPSRC += loadboot.cpp debug.cpp ifeq ($(SDCARD), YES) CPPDEFS += -DVOICE INCDIRS += FatFs FatFs/option @@ -731,7 +734,6 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO)) CPPSRC += targets/sky9x/bluetooth.cpp endif ifeq ($(DEBUG), YES) - CPPSRC += debug.cpp SRC += targets/sky9x/syscalls.c endif endif @@ -814,7 +816,7 @@ ifeq ($(PCB), TARANIS) PULSESSRC = pulses/pulses_arm.cpp pulses/ppm_arm.cpp pulses/pxx_arm.cpp CPPSRC += tasks_arm.cpp audio_arm.cpp sbus.cpp telemetry/telemetry.cpp CPPSRC += targets/taranis/pulses_driver.cpp targets/taranis/keys_driver.cpp targets/taranis/adc_driver.cpp targets/taranis/trainer_driver.cpp targets/taranis/audio_driver.cpp targets/taranis/uart3_driver.cpp targets/taranis/telemetry_driver.cpp - CPPSRC += bmp.cpp gui/view_channels.cpp gui/view_about.cpp gui/view_text.cpp loadboot.cpp + CPPSRC += bmp.cpp gui/view_channels.cpp gui/view_about.cpp gui/view_text.cpp loadboot.cpp debug.cpp SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/misc.c SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c @@ -879,9 +881,6 @@ ifeq ($(PCB), TARANIS) CPPDEFS += -DRTCLOCK CPPSRC += rtc.cpp targets/taranis/rtc_driver.cpp endif - ifeq ($(DEBUG), YES) - CPPSRC += debug.cpp - endif ifeq ($(DSM2), PPM) CPPSRC += pulses/dsm2_arm.cpp endif diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 306f11da8..22789a2f5 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -407,7 +407,7 @@ bool isAudioFileReferenced(uint32_t i, char * filename) uint8_t event = i & 0xFF; #if 0 - printf("isAudioFileReferenced(%08x)\n", i); fflush(stdout); + TRACE("isAudioFileReferenced(%08x)", i); #endif if (category == SYSTEM_AUDIO_CATEGORY) { @@ -846,7 +846,7 @@ void AudioQueue::playTone(uint16_t freq, uint16_t len, uint16_t pause, uint8_t f void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id) { #if defined(SIMU) - printf("playFile(\"%s\", flags=%x, id=%d)\n", filename, flags, id); + TRACE("playFile(\"%s\", flags=%x, id=%d)", filename, flags, id); if (strlen(filename) > AUDIO_FILENAME_MAXLEN) { TRACE("file name too long! maximum length is %d characters", AUDIO_FILENAME_MAXLEN); } @@ -893,7 +893,7 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id) void AudioQueue::stopPlay(uint8_t id) { #if defined(SIMU) - printf("stopPlay(id=%d)\n", id); fflush(stdout); + TRACE("stopPlay(id=%d)", id); #endif // For the moment it's only needed to stop the background music diff --git a/radio/src/debug.cpp b/radio/src/debug.cpp index 4ed6d4c3d..b60631207 100644 --- a/radio/src/debug.cpp +++ b/radio/src/debug.cpp @@ -34,28 +34,44 @@ * */ -#include "../opentx.h" +#include "opentx.h" #include #include -#if !defined(SIMU) && defined(DEBUG) +#if (defined(DEBUG) && defined(CPUARM)) || defined(SIMU) -Fifo<512> debugRxFifo; +#if defined(SIMU) +traceCallbackFunc traceCallback = 0; +#endif + +#if defined(SIMU) + #define PRINTF_BUFFER_SIZE 1024 +#else + #define PRINTF_BUFFER_SIZE 256 +#endif // Outputs a string to the UART void debugPuts(const char *format, ...) { va_list arglist; - char tmp[256]; + char tmp[PRINTF_BUFFER_SIZE]; va_start(arglist, format); - vsnprintf(tmp, 256, format, arglist); + vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist); va_end(arglist); +#if defined(SIMU) + fputs(tmp, stdout); + fflush(stdout); + if (traceCallback) { + traceCallback(tmp); + } +#else const char *t = tmp; while (*t) { debugPutc(*t++); } +#endif } void dump(unsigned char *data, unsigned int size) @@ -73,9 +89,13 @@ void dump(unsigned char *data, unsigned int size) debugPuts("\n\r"); } + +#if !defined(SIMU) + uint32_t Mem_address ; uint32_t Next_mem_address ; uint32_t Memaddmode ; +Fifo<512> debugRxFifo; void crlf() { @@ -86,55 +106,55 @@ void crlf() // Send a single 4 bit value to the RS232 port as a hex digit void hex_digit_send( unsigned char c ) { - c &= 0x0F ; - if ( c > 9 ) - { - c += 7 ; - } - c += '0' ; - debugPutc( c ) ; + c &= 0x0F ; + if ( c > 9 ) + { + c += 7 ; + } + c += '0' ; + debugPutc( c ) ; } // Send the 8 bit value to the RS232 port as 2 hex digits void p2hex( unsigned char c ) { -// asm("swap %c") ; - hex_digit_send( c >> 4 ) ; -// asm("swap %c") ; - hex_digit_send( c ) ; +// asm("swap %c") ; + hex_digit_send( c >> 4 ) ; +// asm("swap %c") ; + hex_digit_send( c ) ; } // Send the 16 bit value to the RS232 port as 4 hex digits void p4hex( uint16_t value ) { - p2hex( value >> 8 ) ; - p2hex( value ) ; + p2hex( value >> 8 ) ; + p2hex( value ) ; } // Send the 32 bit value to the RS232 port as 8 hex digits void p8hex( uint32_t value ) { - p4hex( value >> 16 ) ; - p4hex( value ) ; + p4hex( value >> 16 ) ; + p4hex( value ) ; } static void dispw_256( register uint32_t address, register uint32_t lines ) { - register uint32_t i ; - register uint32_t j ; - address &= 0xFFFFFFFC ; - for ( i = 0 ; i < lines ; i += 1 ) - { - p8hex( address ) ; - for ( j = 0 ; j < 4 ; j += 1 ) - { - debugPutc(' ') ; - p8hex( *( (uint32_t *)address ) ) ; - address += 4 ; - } - crlf() ; - } + register uint32_t i ; + register uint32_t j ; + address &= 0xFFFFFFFC ; + for ( i = 0 ; i < lines ; i += 1 ) + { + p8hex( address ) ; + for ( j = 0 ; j < 4 ; j += 1 ) + { + debugPutc(' ') ; + p8hex( *( (uint32_t *)address ) ) ; + address += 4 ; + } + crlf() ; + } } extern Fifo<512> uart3TxFifo; @@ -221,7 +241,8 @@ void debugTask(void* pdata) } } -#endif +#endif // #if !defined(SIMU) +#endif // #if (defined(DEBUG) && defined(CPUARM)) || defined(SIMU) #if defined(DEBUG_TRACE_BUFFER) diff --git a/radio/src/debug.h b/radio/src/debug.h index dc5880eec..998b5550e 100644 --- a/radio/src/debug.h +++ b/radio/src/debug.h @@ -40,44 +40,17 @@ #include #include "rtc.h" -#if defined(SIMU) - -#include - -#define TRACE(...) do { printf(__VA_ARGS__); printf("\n"); fflush(stdout); } while(0) -#define TRACE_DEBUG(...) do { printf("-D- " __VA_ARGS__); fflush(stdout); } while(0) -#define TRACE_DEBUG_WP(...) do { printf(__VA_ARGS__); fflush(stdout); } while(0) -#define TRACE_INFO(...) do { printf("-I- " __VA_ARGS__); fflush(stdout); } while(0) -#define TRACE_INFO_WP(...) do { printf(__VA_ARGS__); fflush(stdout); } while(0) -#define TRACE_WARNING(...) do { printf("-W- " __VA_ARGS__); fflush(stdout); } while(0) -#define TRACE_WARNING_WP(...) do { printf(__VA_ARGS__); fflush(stdout); } while(0) -#define TRACE_ERROR(...) do { printf("-E- " __VA_ARGS__); fflush(stdout); } while(0) -#define FLUSH() - -inline void dump(void * data, unsigned int size) -{ - unsigned char *uchar_data = (unsigned char *)data; - - printf("DUMP %d bytes ...\n\r", size); - unsigned int i = 0, j=0; - while (i*32+j < size) { - printf("%.2X ", uchar_data[i*32+j]); - j++; - if (j==32) { - i++; j=0; - printf("\n\r"); - } - } - printf("\n\r"); -} -#define DUMP(data, size) dump(data, size) - -#elif defined(DEBUG) && defined(CPUARM) +#if (defined(DEBUG) && defined(CPUARM)) || defined(SIMU) #ifdef __cplusplus extern "C" { #endif +#if defined(SIMU) +typedef void (*traceCallbackFunc)(const char * text); +extern traceCallbackFunc traceCallback; +#endif + void debugPuts(const char *string, ...); void dump(unsigned char *data, unsigned int size); void debugFlush(); @@ -95,8 +68,13 @@ void debugFlush(); #define TRACE_WARNING(...) debugPuts("-W- " __VA_ARGS__) #define TRACE_WARNING_WP(...) debugPuts(__VA_ARGS__) #define TRACE_ERROR(...) debugPuts("-E- " __VA_ARGS__) + +#if !defined(SIMU) #define FLUSH() debugFlush(); void debugTask(void* pdata); +#else +#define FLUSH() +#endif #else diff --git a/radio/src/eeprom_rlc.cpp b/radio/src/eeprom_rlc.cpp index 987126643..fe5a1a3e6 100644 --- a/radio/src/eeprom_rlc.cpp +++ b/radio/src/eeprom_rlc.cpp @@ -293,12 +293,10 @@ inline bool EeFsOpen() #ifdef SIMU if (eeFs.version != EEFS_VERS) { - printf("bad eeFs.version (%d instead of %d)\n", eeFs.version, EEFS_VERS); - fflush(stdout); + TRACE("bad eeFs.version (%d instead of %d)", eeFs.version, EEFS_VERS); } if (eeFs.mySize != sizeof(eeFs)) { - printf("bad eeFs.mySize (%d instead of %d)\n", (int)eeFs.mySize, (int)sizeof(eeFs)); - fflush(stdout); + TRACE("bad eeFs.mySize (%d instead of %d)", (int)eeFs.mySize, (int)sizeof(eeFs)); } #endif @@ -605,7 +603,7 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc) strcpy_P(&buf[len], STR_MODELS_EXT); #ifdef SIMU - printf("SD-card backup filename=%s\n", buf); fflush(stdout); + TRACE("SD-card backup filename=%s", buf); #endif result = f_open(&g_oLogFile, buf, FA_CREATE_ALWAYS | FA_WRITE); diff --git a/radio/src/main_avr.cpp b/radio/src/main_avr.cpp index e0a58f2c5..1d9eb119d 100644 --- a/radio/src/main_avr.cpp +++ b/radio/src/main_avr.cpp @@ -116,7 +116,7 @@ void perMain() if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on checkBacklight(); -#if (defined(FRSKY) || defined(MAVLINK)) +#if defined(FRSKY) || defined(MAVLINK) || defined(SIMU) telemetryWakeup(); #endif diff --git a/radio/src/maths.cpp b/radio/src/maths.cpp index be249a81c..ea4135457 100644 --- a/radio/src/maths.cpp +++ b/radio/src/maths.cpp @@ -194,7 +194,7 @@ void getGpsPilotPosition() uint32_t angle2 = (lat*lat) / 10000; uint32_t angle4 = angle2 * angle2; frskyData.hub.distFromEarthAxis = 139*(((uint32_t)10000000-((angle2*(uint32_t)123370)/81)+(angle4/25))/12500); - // printf("frskyData.hub.distFromEarthAxis=%d\n", frskyData.hub.distFromEarthAxis); fflush(stdout); + // TRACE("frskyData.hub.distFromEarthAxis=%d", frskyData.hub.distFromEarthAxis); } void getGpsDistance() diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index c9ea5d762..338324fa0 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -159,7 +159,7 @@ void simuSetKey(uint8_t key, bool state) void simuSetTrim(uint8_t trim, bool state) { - // printf("trim=%d state=%d\n", trim, state); fflush(stdout); + // TRACE("trim=%d state=%d", trim, state); switch (trim) { TRIM_CASE(0, GPIO_TRIM_LH_L, PIN_TRIM_LH_L) @@ -176,7 +176,7 @@ void simuSetTrim(uint8_t trim, bool state) // TODO use a better numbering to allow google tests to work on Taranis void simuSetSwitch(uint8_t swtch, int8_t state) { - // printf("swtch=%d state=%d\n", swtch, state); fflush(stdout); + // TRACE("swtch=%d state=%d", swtch, state); switch (swtch) { #if defined(PCBTARANIS) && defined(REV9E) SWITCH_3_CASE(0, GPIO_PIN_SW_A_L, GPIO_PIN_SW_A_H, PIN_SW_A_L, PIN_SW_A_H) @@ -443,7 +443,7 @@ void eeprom_read_block (void *pointer_ram, const void *pointer_eeprom, size_t si assert(size); if (fp) { - // printf("EEPROM read (pos=%d, size=%d)\n", pointer_eeprom, size); fflush(stdout); + // TRACE("EEPROM read (pos=%d, size=%d)", pointer_eeprom, size); if (fseek(fp, (long)pointer_eeprom, SEEK_SET)==-1) perror("error in fseek"); if (fread(pointer_ram, size, 1, fp) <= 0) perror("error in fread"); } @@ -458,7 +458,7 @@ void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t si assert(size); if (fp) { - // printf("EEPROM write (pos=%d, size=%d)\n", pointer_eeprom, size); fflush(stdout); + // TRACE("EEPROM write (pos=%d, size=%d)", pointer_eeprom, size); if (fseek(fp, (long)pointer_eeprom, SEEK_SET)==-1) perror("error in fseek"); if (fwrite(pointer_ram, size, 1, fp) <= 0) perror("error in fwrite"); } @@ -623,7 +623,7 @@ FRESULT f_readdir (DIR * rep, FILINFO * fil) FRESULT f_mkfs (const TCHAR *path, BYTE, UINT) { - printf("Format SD...\n"); fflush(stdout); + TRACE("Format SD..."); return FR_OK; } diff --git a/radio/src/targets/sky9x/keys_driver.cpp b/radio/src/targets/sky9x/keys_driver.cpp index bc68484e5..6b7c5c9d7 100644 --- a/radio/src/targets/sky9x/keys_driver.cpp +++ b/radio/src/targets/sky9x/keys_driver.cpp @@ -81,7 +81,7 @@ uint32_t readKeys() result |= 0x02 << KEY_MENU; #endif - // printf("readKeys(): %x => %x\n", x, result); fflush(stdout); + // TRACE("readKeys(): %x => %x", x, result); return result; } diff --git a/radio/src/targets/sky9x/telemetry_driver.cpp b/radio/src/targets/sky9x/telemetry_driver.cpp index 9dcf99481..30fb80b96 100644 --- a/radio/src/targets/sky9x/telemetry_driver.cpp +++ b/radio/src/targets/sky9x/telemetry_driver.cpp @@ -181,8 +181,10 @@ uint32_t telemetryTransmitPending() void telemetryPortInit(uint32_t baudrate) { +#if !defined(SIMU) UART2_Configure(baudrate, Master_frequency); startPdcUsartReceive(); +#endif } void telemetryTransmitBuffer(uint8_t * buffer, uint32_t size) diff --git a/radio/src/targets/stock/voice.cpp b/radio/src/targets/stock/voice.cpp index 7857469ea..bf2d6013e 100644 --- a/radio/src/targets/stock/voice.cpp +++ b/radio/src/targets/stock/voice.cpp @@ -41,7 +41,7 @@ struct t_voice Voice ; void pushPrompt(uint16_t value) { #ifdef SIMU - printf("playFile(\"%04d.ad4\")\n", value); fflush(stdout); + TRACE("playFile(\"%04d.ad4\")", value); #endif struct t_voice *vptr; diff --git a/radio/src/targets/taranis/keys_driver.cpp b/radio/src/targets/taranis/keys_driver.cpp index fdff59814..30ed8ffc2 100644 --- a/radio/src/targets/taranis/keys_driver.cpp +++ b/radio/src/targets/taranis/keys_driver.cpp @@ -72,7 +72,7 @@ uint32_t readKeys() if (d & PIN_BUTTON_EXIT) result |= 0x02 << KEY_EXIT; - // printf("readKeys(): %x %x => %x\n", d, e, result); fflush(stdout); + // TRACE("readKeys(): %x %x => %x", d, e, result); return result; } @@ -112,7 +112,7 @@ uint32_t readTrims() if (~c & PIN_TRIM_RH_R) result |= 0x80; // RH_R - // printf("readTrims(): %x %x => %x\n", c, e, result); fflush(stdout); + // TRACE("readTrims(): %x %x => %x", c, e, result); return result; } diff --git a/radio/src/tasks_arm.cpp b/radio/src/tasks_arm.cpp index 2e25744e7..1bf547408 100644 --- a/radio/src/tasks_arm.cpp +++ b/radio/src/tasks_arm.cpp @@ -132,7 +132,7 @@ void mixerTask(void * pdata) doMixerCalculations(); CoLeaveMutexSection(mixerMutex); -#if defined(FRSKY) || defined(MAVLINK) +#if defined(FRSKY) || defined(MAVLINK) || defined(SIMU) telemetryWakeup(); #endif diff --git a/radio/src/telemetry/frsky_sport.cpp b/radio/src/telemetry/frsky_sport.cpp index 6260a9278..cf0d29697 100644 --- a/radio/src/telemetry/frsky_sport.cpp +++ b/radio/src/telemetry/frsky_sport.cpp @@ -88,6 +88,7 @@ bool checkSportPacket(uint8_t *packet) crc += crc >> 8; // 0-1FF crc &= 0x00ff; // 0-FF } + // TRACE("crc: 0x%02x", crc); return (crc == 0x00ff); } @@ -103,6 +104,8 @@ void processSportPacket(uint8_t *packet) uint16_t appId = *((uint16_t *)(packet+2)); if (!checkSportPacket(packet)) { + TRACE("processSportPacket(): checksumm error "); + DUMP(packet, FRSKY_SPORT_PACKET_SIZE); return; }