diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-01 20:43:39 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-01 20:43:39 -0500 |
commit | 963501ff41849e6bbcaa7a5c12c6e04b37a8a130 (patch) | |
tree | a92d85facc6b5168890d78e9ad8944fd96d5507a /clients/tde/src/part/fpgaview/part.cpp | |
parent | e9dafbb9d016a1aa5e90bb12c63c12b8521cf059 (diff) | |
download | ulab-963501ff41849e6bbcaa7a5c12c6e04b37a8a130.tar.gz ulab-963501ff41849e6bbcaa7a5c12c6e04b37a8a130.zip |
Fix crashes in servers
Start work on FPGA client
Diffstat (limited to 'clients/tde/src/part/fpgaview/part.cpp')
-rw-r--r-- | clients/tde/src/part/fpgaview/part.cpp | 139 |
1 files changed, 133 insertions, 6 deletions
diff --git a/clients/tde/src/part/fpgaview/part.cpp b/clients/tde/src/part/fpgaview/part.cpp index 6161562..269c05e 100644 --- a/clients/tde/src/part/fpgaview/part.cpp +++ b/clients/tde/src/part/fpgaview/part.cpp @@ -37,24 +37,52 @@ #include <tqmutex.h> #include <tqeventloop.h> #include <tqapplication.h> +#include <tqgroupbox.h> #include <unistd.h> //access() #include <stdint.h> - - #include "tracewidget.h" #include "floatspinbox.h" #include "layout.h" +#define SERVER_TIMEOUT_MS 10000 + +FPGALed::FPGALed(TQWidget *parent, const char *name) + : KLed(parent, name), m_clickable(true) +{ + connect(this, SIGNAL(clicked()), this, SLOT(toggle())); + + setColor(green); + setOffColor(TQApplication::palette(this).active().base().dark(200)); +} + +void FPGALed::setClickable(bool clickable) { + if ((!clickable) && (m_clickable)) { + disconnect(this, SIGNAL(clicked()), this, SLOT(toggle())); + } + else if ((clickable) && (!m_clickable)) { + connect(this, SIGNAL(clicked()), this, SLOT(toggle())); + } + m_clickable = clickable; +} + +void FPGALed::mouseReleaseEvent(TQMouseEvent *e) { + if (e->button() == TQMouseEvent::LeftButton) { + emit(clicked()); + } +} + namespace RemoteLab { typedef KParts::GenericFactory<RemoteLab::FPGAViewPart> Factory; #define CLIENT_LIBRARY "libremotelab_fpgaviewer" K_EXPORT_COMPONENT_FACTORY(libremotelab_fpgaviewer, RemoteLab::Factory) +#define LED_SIZE 20,20 FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList&) - : RemoteInstrumentPart( parent, name ), m_socket(0), m_base(0), connToServerConnecting(false), connToServerState(-1), connToServerTimeoutTimer(NULL), m_interfaceMode(BasicInterfaceMode) + : RemoteInstrumentPart( parent, name ), m_socket(0), m_base(0), connToServerConnecting(false), connToServerState(-1), connToServerTimeoutTimer(NULL), m_interfaceMode(BasicInterfaceMode), + remoteInputModeEnabled(false), m_8bitInputValue(0), m_8bitOutputValue(0) { // Initialize mutex m_connectionMutex = new TQMutex(false); @@ -82,7 +110,60 @@ FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObj m_modeAdvancedEnabled = new KToggleAction(i18n("Advanced"), KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(switchToAdvancedMode()), ac, "mode_advanced_enabled"); m_modeSubMenu->insert(m_modeAdvancedEnabled); - processLockouts(); + // Initialize widgets + m_base->group8BitInputLED7->setFixedSize(LED_SIZE); + m_base->group8BitInputLED6->setFixedSize(LED_SIZE); + m_base->group8BitInputLED5->setFixedSize(LED_SIZE); + m_base->group8BitInputLED4->setFixedSize(LED_SIZE); + m_base->group8BitInputLED3->setFixedSize(LED_SIZE); + m_base->group8BitInputLED2->setFixedSize(LED_SIZE); + m_base->group8BitInputLED1->setFixedSize(LED_SIZE); + m_base->group8BitInputLED0->setFixedSize(LED_SIZE); + m_base->group8BitOutputLED7->setFixedSize(LED_SIZE); + m_base->group8BitOutputLED6->setFixedSize(LED_SIZE); + m_base->group8BitOutputLED5->setFixedSize(LED_SIZE); + m_base->group8BitOutputLED4->setFixedSize(LED_SIZE); + m_base->group8BitOutputLED3->setFixedSize(LED_SIZE); + m_base->group8BitOutputLED2->setFixedSize(LED_SIZE); + m_base->group8BitOutputLED1->setFixedSize(LED_SIZE); + m_base->group8BitOutputLED0->setFixedSize(LED_SIZE); + + m_base->group8BitInputLED7->setState(KLed::Off); + m_base->group8BitInputLED6->setState(KLed::Off); + m_base->group8BitInputLED5->setState(KLed::Off); + m_base->group8BitInputLED4->setState(KLed::Off); + m_base->group8BitInputLED3->setState(KLed::Off); + m_base->group8BitInputLED2->setState(KLed::Off); + m_base->group8BitInputLED1->setState(KLed::Off); + m_base->group8BitInputLED0->setState(KLed::Off); + m_base->group8BitOutputLED7->setState(KLed::Off); + m_base->group8BitOutputLED6->setState(KLed::Off); + m_base->group8BitOutputLED5->setState(KLed::Off); + m_base->group8BitOutputLED4->setState(KLed::Off); + m_base->group8BitOutputLED3->setState(KLed::Off); + m_base->group8BitOutputLED2->setState(KLed::Off); + m_base->group8BitOutputLED1->setState(KLed::Off); + m_base->group8BitOutputLED0->setState(KLed::Off); + + m_base->group8BitOutputLED7->setClickable(false); + m_base->group8BitOutputLED6->setClickable(false); + m_base->group8BitOutputLED5->setClickable(false); + m_base->group8BitOutputLED4->setClickable(false); + m_base->group8BitOutputLED3->setClickable(false); + m_base->group8BitOutputLED2->setClickable(false); + m_base->group8BitOutputLED1->setClickable(false); + m_base->group8BitOutputLED0->setClickable(false); + + connect(m_base->group8BitInputLED7, SIGNAL(clicked()), this, SLOT(process8BitInputChanges())); + connect(m_base->group8BitInputLED6, SIGNAL(clicked()), this, SLOT(process8BitInputChanges())); + connect(m_base->group8BitInputLED5, SIGNAL(clicked()), this, SLOT(process8BitInputChanges())); + connect(m_base->group8BitInputLED4, SIGNAL(clicked()), this, SLOT(process8BitInputChanges())); + connect(m_base->group8BitInputLED3, SIGNAL(clicked()), this, SLOT(process8BitInputChanges())); + connect(m_base->group8BitInputLED2, SIGNAL(clicked()), this, SLOT(process8BitInputChanges())); + connect(m_base->group8BitInputLED1, SIGNAL(clicked()), this, SLOT(process8BitInputChanges())); + connect(m_base->group8BitInputLED0, SIGNAL(clicked()), this, SLOT(process8BitInputChanges())); + + processAllGraphicsUpdates(); TQTimer::singleShot(0, this, TQT_SLOT(postInit())); } @@ -96,6 +177,52 @@ FPGAViewPart::~FPGAViewPart() { delete m_connectionMutex; } +void FPGAViewPart::processAllGraphicsUpdates() { + // This is an expensive operation + // Use it sparingly! + + process8BitInputChanges(); + process8BitOutputChanges(); + + processLockouts(); +} + +void FPGAViewPart::process8BitInputChanges() { + // Read LED status into m_8bitInputValue + m_8bitInputValue = 0; + if (m_base->group8BitInputLED7->state() == KLed::On) m_8bitInputValue |= 0x80; + if (m_base->group8BitInputLED6->state() == KLed::On) m_8bitInputValue |= 0x40; + if (m_base->group8BitInputLED5->state() == KLed::On) m_8bitInputValue |= 0x20; + if (m_base->group8BitInputLED4->state() == KLed::On) m_8bitInputValue |= 0x10; + if (m_base->group8BitInputLED3->state() == KLed::On) m_8bitInputValue |= 0x08; + if (m_base->group8BitInputLED2->state() == KLed::On) m_8bitInputValue |= 0x04; + if (m_base->group8BitInputLED1->state() == KLed::On) m_8bitInputValue |= 0x02; + if (m_base->group8BitInputLED0->state() == KLed::On) m_8bitInputValue |= 0x01; + + m_base->group8BitInputValueText->setText(TQString("0x%1").arg(m_8bitInputValue, 0, 16)); + + if (remoteInputModeEnabled) { + m_base->group8BitInput->setTitle(i18n("8-Bit Input Values") + " [" + i18n("Remote Input Mode") + "]"); + } + else { + m_base->group8BitInput->setTitle(i18n("8-Bit Input Values") + " [" + i18n("Local Input Mode") + "]"); + } +} + +void FPGAViewPart::process8BitOutputChanges() { + // Write m_8bitOutputValue to LEDs + m_base->group8BitOutputLED7->setState((m_8bitInputValue & 0x80)?KLed::On:KLed::Off); + m_base->group8BitOutputLED6->setState((m_8bitInputValue & 0x80)?KLed::On:KLed::Off); + m_base->group8BitOutputLED5->setState((m_8bitInputValue & 0x80)?KLed::On:KLed::Off); + m_base->group8BitOutputLED4->setState((m_8bitInputValue & 0x80)?KLed::On:KLed::Off); + m_base->group8BitOutputLED3->setState((m_8bitInputValue & 0x80)?KLed::On:KLed::Off); + m_base->group8BitOutputLED2->setState((m_8bitInputValue & 0x80)?KLed::On:KLed::Off); + m_base->group8BitOutputLED1->setState((m_8bitInputValue & 0x80)?KLed::On:KLed::Off); + m_base->group8BitOutputLED0->setState((m_8bitInputValue & 0x80)?KLed::On:KLed::Off); + + m_base->group8BitOutputValueText->setText(TQString("0x%1").arg(m_8bitOutputValue, 0, 16)); +} + void FPGAViewPart::processLockouts() { TQWidget* mainWidget = widget(); if (mainWidget) { @@ -183,7 +310,7 @@ void FPGAViewPart::finishConnectingToServer() { case 0: if (!connToServerTimeoutTimer) { connToServerTimeoutTimer = new TQTimer; - connToServerTimeoutTimer->start(5000, TRUE); + connToServerTimeoutTimer->start(SERVER_TIMEOUT_MS, TRUE); } if ((m_socket->state() == TQSocket::Connecting) || (m_socket->state() == TQSocket::HostLookup)) { if (!connToServerTimeoutTimer->isActive()) { @@ -196,7 +323,7 @@ void FPGAViewPart::finishConnectingToServer() { else { if (m_socket->state() == TQSocket::Connected) { printf("[DEBUG] Initial connection established...\n\r"); fflush(stdout); - m_socket->setDataTimeout(5000); + m_socket->setDataTimeout(SERVER_TIMEOUT_MS); m_socket->setUsingKerberos(true); connToServerState = 1; } |