Skip to content

Commit

Permalink
(Incomplete) code for battery-backed memory display
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbourassa committed Nov 27, 2016
1 parent 15a395b commit e3ffac9
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 29 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cmake_minimum_required (VERSION 2.8.11)
project (rovergauge)

set (ROVERGAUGE_VER_MAJOR 0)
set (ROVERGAUGE_VER_MINOR 8)
set (ROVERGAUGE_VER_PATCH 9)
set (ROVERGAUGE_VER_MINOR 9)
set (ROVERGAUGE_VER_PATCH 0)

set (CMAKE_INCLUDE_CURRENT_DIR ON)
set (CMAKE_AUTOMOC ON)
Expand Down Expand Up @@ -51,6 +51,7 @@ include_directories ("${CMAKE_SOURCE_DIR}"

qt5_wrap_ui (UI_SOURCE mainwindow.ui)
qt5_wrap_ui (UI_SOURCE optionsdialog.ui)
qt5_wrap_ui (UI_SOURCE batterybackeddisplay.ui)
message (STATUS "Generated: ${UI_SOURCE}")
qt5_add_resources (RG_RESOURCE rovergauge_resources.qrc)
message (STATUS "Generated: ${RG_RESOURCE}")
Expand All @@ -71,6 +72,7 @@ add_executable (rovergauge main.cpp
faultcodedialog.cpp
aboutbox.cpp
optionsdialog.cpp
batterybackeddisplay.cpp
qledindicator/qledindicator.cpp
analogwidgets/led.cpp
analogwidgets/functions.cpp
Expand Down
31 changes: 31 additions & 0 deletions batterybackeddisplay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "ui_batterybackeddisplay.h"
#include "batterybackeddisplay.h"

/**
* Constructor
*/
BatteryBackedDisplay::BatteryBackedDisplay(QString title, QByteArray *batteryBackedMemory, uint16_t startOffset, QWidget* parent) : QDialog(parent),
m_ui(new Ui::BatteryBackedDisplay)
{
m_ui->setupUi(this);
this->setLayout(m_ui->m_mainLayout);

this->setWindowTitle(title);

QTableWidgetItem* item;

for (unsigned int idx = 0; idx < batteryBackedMemory->size(); ++idx)
{
m_ui->m_batteryBackedTable->insertRow(idx);

item = new QTableWidgetItem(QString("%1").arg(startOffset + idx, 0, 16).toUpper());
m_ui->m_batteryBackedTable->setItem(idx, 0, item);
item = new QTableWidgetItem(QString("%1").arg(batteryBackedMemory->at(idx), 0, 16).toUpper());
m_ui->m_batteryBackedTable->setItem(idx, 1, item);
}
}

void BatteryBackedDisplay::refresh()
{
//TODO
}
27 changes: 27 additions & 0 deletions batterybackeddisplay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef BATTERYBACKEDDISPLAY_H
#define BATTERYBACKEDDISPLAY_H

#include <QDialog>
#include <QByteArray>

namespace Ui
{
class BatteryBackedDisplay;
}

class BatteryBackedDisplay : public QDialog
{
Q_OBJECT

public:
BatteryBackedDisplay(QString title, QByteArray* batteryBackedMemory, uint16_t startOffset, QWidget* parent = 0);

private slots:
void refresh();

private:
Ui::BatteryBackedDisplay* m_ui;
};

#endif // BATTERYBACKEDDISPLAY_H

91 changes: 91 additions & 0 deletions batterybackeddisplay.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BatteryBackedDisplay</class>
<widget class="QDialog" name="BatteryBackedDisplay">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>350</width>
<height>300</height>
</size>
</property>
<property name="windowTitle">
<string>Options</string>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>331</width>
<height>302</height>
</rect>
</property>
<layout class="QGridLayout" name="m_mainLayout">
<property name="leftMargin">
<number>20</number>
</property>
<property name="topMargin">
<number>20</number>
</property>
<property name="rightMargin">
<number>20</number>
</property>
<property name="bottomMargin">
<number>20</number>
</property>
<item row="1" column="0" colspan="2">
<widget class="Line" name="m_horizontalLineC">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="m_closeButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="m_refreshButton">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QTableWidget" name="m_batteryBackedTable">
<column>
<property name="text">
<string>Offset</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
28 changes: 28 additions & 0 deletions cuxinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CUXInterface::CUXInterface(QString device, unsigned int baud, SpeedUnits sUnits,
m_baudRate(baud),
m_stopPolling(false),
m_shutdownThread(false),
m_batteryBackedMem(0),
m_readCanceled(false),
m_readTuneId(false),
m_lambdaTrimType(C14CUX_LambdaTrimType_ShortTerm),
Expand Down Expand Up @@ -106,6 +107,33 @@ void CUXInterface::onFaultCodesRequested()
}
}

/**
* Reads battery-backed memory from the 14CUX and stores in a member structure
*/
void CUXInterface::onBatteryBackedMemRequested()
{
if (m_initComplete && c14cux_isConnected(&m_cuxinfo))
{
if (m_batteryBackedMem == 0)
{
m_batteryBackedMem = new QByteArray(20, 0x00);
}

if (c14cux_readMem(&m_cuxinfo, 0x0040, 20, (uint8_t*)m_batteryBackedMem->data()))
{
emit batteryBackedMemReady();
}
else
{
emit batteryBackedMemReadFailed();
}
}
else
{
emit notConnected();
}
}

/**
* Clears the block of fault codes.
*/
Expand Down
9 changes: 9 additions & 0 deletions cuxinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class CUXInterface : public QObject
{
return m_faultCodes;
}
QByteArray* getBatteryBackedMem()
{
return m_batteryBackedMem;
}

float getMainVoltage()
{
return m_mainVoltage;
Expand Down Expand Up @@ -211,6 +216,7 @@ public slots:
void onParentThreadStarted();
void onFaultCodesRequested();
void onFaultCodesClearRequested();
void onBatteryBackedMemRequested();
void onFuelMapRequested(unsigned int fuelMapId);
void onReadROMImageRequested();
void onStartPollingRequest();
Expand All @@ -234,6 +240,8 @@ public slots:
void faultCodesReadFailed();
void faultCodesClearSuccess(c14cux_faultcodes faultCodes);
void faultCodesClearFailure();
void batteryBackedMemReady();
void batteryBackedMemReadFailed();
void fuelMapReady(unsigned int fuelMapId);
void fuelMapReadFailed(unsigned int fuelMapId);
void rpmLimitReady(int rpmLimiter);
Expand Down Expand Up @@ -263,6 +271,7 @@ public slots:
bool m_stopPolling;
bool m_shutdownThread;
c14cux_faultcodes m_faultCodes;
QByteArray* m_batteryBackedMem;
bool m_readCanceled;
bool m_readTuneId;
QHash<SampleType, bool> m_enabledSamples;
Expand Down
72 changes: 49 additions & 23 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ MainWindow::MainWindow(QWidget* parent)
m_cuxThread(0),
m_cux(0),
m_options(0),
m_batteryBackedDisplay(0),
m_aboutBox(0),
m_pleaseWaitBox(0),
m_helpViewerDialog(0),
Expand Down Expand Up @@ -73,24 +74,26 @@ MainWindow::MainWindow(QWidget* parent)
connect(m_shortcutStopLogging, SIGNAL(activated()), this, SLOT(onStopLogging()));
connect(m_shortcutExit, SIGNAL(activated()), this, SLOT(onExitSelected()));

connect(m_cux, SIGNAL(dataReady()), this, SLOT(onDataReady()));
connect(m_cux, SIGNAL(connected()), this, SLOT(onConnect()));
connect(m_cux, SIGNAL(disconnected()), this, SLOT(onDisconnect()));
connect(m_cux, SIGNAL(readError()), this, SLOT(onReadError()));
connect(m_cux, SIGNAL(readSuccess()), this, SLOT(onReadSuccess()));
connect(m_cux, SIGNAL(failedToConnect(QString)), this, SLOT(onFailedToConnect(QString)));
connect(m_cux, SIGNAL(faultCodesReady()), this, SLOT(onFaultCodesReady()));
connect(m_cux, SIGNAL(faultCodesReadFailed()), this, SLOT(onFaultCodesReadFailed()));
connect(m_cux, SIGNAL(fuelMapReady(unsigned int)), this, SLOT(onFuelMapDataReady(unsigned int)));
connect(m_cux, SIGNAL(dataReady()), this, SLOT(onDataReady()));
connect(m_cux, SIGNAL(connected()), this, SLOT(onConnect()));
connect(m_cux, SIGNAL(disconnected()), this, SLOT(onDisconnect()));
connect(m_cux, SIGNAL(readError()), this, SLOT(onReadError()));
connect(m_cux, SIGNAL(readSuccess()), this, SLOT(onReadSuccess()));
connect(m_cux, SIGNAL(failedToConnect(QString)), this, SLOT(onFailedToConnect(QString)));
connect(m_cux, SIGNAL(faultCodesReady()), this, SLOT(onFaultCodesReady()));
connect(m_cux, SIGNAL(faultCodesReadFailed()), this, SLOT(onFaultCodesReadFailed()));
connect(m_cux, SIGNAL(batteryBackedMemReady()), this, SLOT(onBatteryBackedMemReady()));
connect(m_cux, SIGNAL(batteryBackedMemReadFailed()), this, SLOT(onBatteryBackedMemReadFailed()));
connect(m_cux, SIGNAL(fuelMapReady(unsigned int)), this, SLOT(onFuelMapDataReady(unsigned int)));
connect(m_cux, SIGNAL(revisionNumberReady(int, int, int)), this, SLOT(onTuneRevisionReady(int, int, int)));
connect(m_cux, SIGNAL(interfaceReadyForPolling()), this, SLOT(onInterfaceReady()));
connect(m_cux, SIGNAL(notConnected()), this, SLOT(onNotConnected()));
connect(m_cux, SIGNAL(romImageReady()), this, SLOT(onROMImageReady()));
connect(m_cux, SIGNAL(romImageReadFailed()), this, SLOT(onROMImageReadFailed()));
connect(m_cux, SIGNAL(rpmLimitReady(int)), this, SLOT(onRPMLimitReady(int)));
connect(m_cux, SIGNAL(rpmTableReady()), this, SLOT(onRPMTableReady()));
connect(m_cux, SIGNAL(interfaceReadyForPolling()), this, SLOT(onInterfaceReady()));
connect(m_cux, SIGNAL(notConnected()), this, SLOT(onNotConnected()));
connect(m_cux, SIGNAL(romImageReady()), this, SLOT(onROMImageReady()));
connect(m_cux, SIGNAL(romImageReadFailed()), this, SLOT(onROMImageReadFailed()));
connect(m_cux, SIGNAL(rpmLimitReady(int)), this, SLOT(onRPMLimitReady(int)));
connect(m_cux, SIGNAL(rpmTableReady()), this, SLOT(onRPMTableReady()));
connect(m_cux, SIGNAL(feedbackModeHasChanged(c14cux_feedback_mode)), this, SLOT(onFeedbackModeChanged(c14cux_feedback_mode)));
connect(m_cux, SIGNAL(fuelMapIndexHasChanged(uint)), this, SLOT(onFuelMapIndexChanged(uint)));
connect(m_cux, SIGNAL(fuelMapIndexHasChanged(uint)), this, SLOT(onFuelMapIndexChanged(uint)));
#ifdef ENABLE_FORCE_OPEN_LOOP
connect(m_cux, SIGNAL(forceOpenLoopState(bool)), this, SLOT(onForceOpenLoopStateReceived(bool)));
#endif
Expand Down Expand Up @@ -131,6 +134,7 @@ MainWindow::~MainWindow()
delete m_options;
delete m_cux;
delete m_cuxThread;
delete m_batteryBackedDisplay;
}

/**
Expand Down Expand Up @@ -171,13 +175,14 @@ void MainWindow::setupWidgets()
m_ui->m_stopLoggingButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));

// connect menu item signals
connect(m_ui->m_saveROMImageAction, SIGNAL(triggered()), this, SLOT(onSaveROMImageSelected()));
connect(m_ui->m_exitAction, SIGNAL(triggered()), this, SLOT(onExitSelected()));
connect(m_ui->m_showFaultCodesAction, SIGNAL(triggered()), m_cux, SLOT(onFaultCodesRequested()));
connect(m_ui->m_idleAirControlAction, SIGNAL(triggered()), this, SLOT(onIdleAirControlClicked()));
connect(m_ui->m_editSettingsAction, SIGNAL(triggered()), this, SLOT(onEditOptionsClicked()));
connect(m_ui->m_helpContentsAction, SIGNAL(triggered()), this, SLOT(onHelpContentsClicked()));
connect(m_ui->m_helpAboutAction, SIGNAL(triggered()), this, SLOT(onHelpAboutClicked()));
connect(m_ui->m_saveROMImageAction, SIGNAL(triggered()), this, SLOT(onSaveROMImageSelected()));
connect(m_ui->m_exitAction, SIGNAL(triggered()), this, SLOT(onExitSelected()));
connect(m_ui->m_showFaultCodesAction, SIGNAL(triggered()), m_cux, SLOT(onFaultCodesRequested()));
connect(m_ui->m_idleAirControlAction, SIGNAL(triggered()), this, SLOT(onIdleAirControlClicked()));
connect(m_ui->m_batteryBackedAction, SIGNAL(triggered(bool)), m_cux, SLOT(onBatteryBackedMemRequested()));
connect(m_ui->m_editSettingsAction, SIGNAL(triggered()), this, SLOT(onEditOptionsClicked()));
connect(m_ui->m_helpContentsAction, SIGNAL(triggered()), this, SLOT(onHelpContentsClicked()));
connect(m_ui->m_helpAboutAction, SIGNAL(triggered()), this, SLOT(onHelpAboutClicked()));

#ifdef ENABLE_FORCE_OPEN_LOOP
connect(m_ui->m_forceOpenLoopCheckbox, SIGNAL(clicked(bool)), m_cux, SLOT(onForceOpenLoopRequest(bool)));
Expand Down Expand Up @@ -419,6 +424,27 @@ void MainWindow::onFaultCodesReadFailed()
QMessageBox::Ok);
}

/**
* Opens the battery-backed memory dialog.
*/
void MainWindow::onBatteryBackedMemReady()
{
QByteArray* batteryBackedMemory = m_cux->getBatteryBackedMem();
BatteryBackedDisplay batteryDialog(this->windowTitle(), batteryBackedMemory, 0x0040, this);
batteryDialog.exec();
}

/**
* Responds to a signal from the worker thread that indicates there was a
* problem reading the battery-backed memory. Displays a message box indicating the same.
*/
void MainWindow::onBatteryBackedMemReadFailed()
{
QMessageBox::warning(this, "Error",
"Unable to read battery-backed memory from ECU.",
QMessageBox::Ok);
}

/**
* Uses a fuel map array to populate a 16x8 grid that shows all the fueling
* values.
Expand Down
4 changes: 4 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "fueltrimbar.h"
#include "commonunits.h"
#include "helpviewer.h"
#include "batterybackeddisplay.h"
#ifdef ENABLE_SIM_MODE
#include "simulationmodedialog.h"
#endif
Expand Down Expand Up @@ -58,6 +59,8 @@ public slots:
void onFailedToConnect(QString dev);
void onFaultCodesReady();
void onFaultCodesReadFailed();
void onBatteryBackedMemReady();
void onBatteryBackedMemReadFailed();
void onFuelMapDataReady(unsigned int fuelMapId);
void onTuneRevisionReady(int tuneRevisionNum, int checksumFixer, int ident);
void onRPMLimitReady(int rpmLimit);
Expand Down Expand Up @@ -95,6 +98,7 @@ public slots:
CUXInterface* m_cux;
OptionsDialog* m_options;
IdleAirControlDialog* m_iacDialog;
BatteryBackedDisplay* m_batteryBackedDisplay;
AboutBox* m_aboutBox;
QMessageBox* m_pleaseWaitBox;
HelpViewer* m_helpViewerDialog;
Expand Down
Loading

0 comments on commit e3ffac9

Please sign in to comment.