int MemMapper::addRange(int virtAddress, int length) { int virtPage = virtAddress >> 8; if ((virtAddress & 0xff) || virtPage < 0 || virtPage >= FLASH_PAGE_SIZE) { return MEM_MAPPER_INVALID_ADDRESS; } if ((length & 0xff) != 0) { return MEM_MAPPER_INVALID_LENGTH; } byte pages = length >> 8; for (int page = virtPage; page < (pages + virtPage); page++) { byte flashPageNum = allocTable[page] ^ 0xff; if (flashPageNum == 0) { // not yet allocated in flash memory int result = allocatePage(page); if (result != MEM_MAPPER_SUCCESS) { return result; } flashMemModified = true; doFlash(); } } allocTableModified = true; doFlash(); return MEM_MAPPER_SUCCESS; }
int MemMapper::readMem(int virtAddress, byte &data, bool forceFlash) { int flashPageNum = getFlashPageNum(virtAddress); if (flashPageNum < 0) { data = 0x00; return flashPageNum; } if (forceFlash) { doFlash(); } if (flashPageNum == 0) { data = 0x00; return MEM_MAPPER_NOT_MAPPED; } else if ((flashPageNum == writePage) && !forceFlash) { data = writeBuf[virtAddress & 0xff]; } else { data = ((byte*) (flashPageNum << 8))[virtAddress & 0xff]; } return MEM_MAPPER_SUCCESS; }
int MemMapper::writeMem(int virtAddress, byte data) { int flashPageNum = getFlashPageNum(virtAddress); if (flashPageNum < 0) { return flashPageNum; } if (writePage != flashPageNum) { doFlash(); writePage = flashPageNum; if (writePage != 0) { // swap flash page into write buffer memcpy(writeBuf, (byte *)(writePage << 8), FLASH_PAGE_SIZE); } } if (flashPageNum == 0) { // not yet allocated in flash memory if (autoAddPage) { int result = allocatePage(virtAddress >> 8); if (result != MEM_MAPPER_SUCCESS) { return result; } allocTableModified = true; } } writeBuf[(virtAddress & 0xff)] = data; flashMemModified = true; return MEM_MAPPER_SUCCESS; }
void WbDlg::activated() { if(pending_ > 0) { pending_ = 0; updateCaption(); } doFlash(false); }
void ChatDlg::activated() { TabbableWidget::activated(); if (pending_ > 0) { pending_ = 0; messagesRead(jid()); invalidateTab(); } doFlash(false); chatEdit()->setFocus(); }
/** * Runs all the gumph necessary before hiding a chat. * (checking new messages, setting the autodelete, cancelling composing etc) * \return ChatDlg is ready to be hidden. */ bool ChatDlg::readyToHide() { // really lame way of checking if we are encrypting if (!chatEdit()->isEnabled()) { return false; } if (keepOpen_) { QMessageBox mb(QMessageBox::Information, tr("Warning"), tr("A new chat message was just received.\nDo you still want to close the window?"), QMessageBox::Cancel, this); mb.addButton(tr("Close"), QMessageBox::AcceptRole); if (mb.exec() == QMessageBox::Cancel) { return false; } } // destroy the dialog if delChats is dcClose if (PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "instant") { setAttribute(Qt::WA_DeleteOnClose); } else { if (PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "hour") { setSelfDestruct(60); } else if (PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "day") { setSelfDestruct(60 * 24); } } // Reset 'contact is composing' & cancel own composing event resetComposing(); setChatState(StateGone); if (contactChatState_ == StateComposing || contactChatState_ == StateInactive) { setContactChatState(StatePaused); } if (pending_ > 0) { pending_ = 0; messagesRead(jid()); invalidateTab(); } doFlash(false); chatEdit()->setFocus(); return true; }
byte* MemMapper::memoryPtr(int virtAddress, bool forceFlash) const { int flashPageNum = getFlashPageNum(virtAddress); if (flashPageNum < 0) { return NULL; } if (forceFlash) { doFlash(); } if (flashPageNum == 0) { return NULL; } else if ((flashPageNum == writePage) && !forceFlash) { return writeBuf + (virtAddress & 0xff); } return ((byte*) (flashPageNum << 8) + (virtAddress & 0xff)); }
ThymioFlasherDialog::ThymioFlasherDialog() { typedef std::map<int, std::pair<std::string, std::string> > PortsMap; const PortsMap ports = SerialPortEnumerator::getPorts(); QSettings settings; // Create the gui ... setWindowTitle(tr("Thymio Firmware Updater")); resize(600,500); QVBoxLayout* mainLayout = new QVBoxLayout(this); // make sure the port list is enabled only if serial ports are found unsigned sectionEnabled(ports.empty() ? 1 : 0); // serial port serialGroupBox = new QGroupBox(tr("Serial connection")); serialGroupBox->setCheckable(true); QHBoxLayout* serialLayout = new QHBoxLayout(); serial = new QListWidget(); bool serialPortSet(false); for (PortsMap::const_iterator it = ports.begin(); it != ports.end(); ++it) { const QString text(it->second.second.c_str()); QListWidgetItem* item = new QListWidgetItem(text); item->setData(Qt::UserRole, QVariant(QString::fromUtf8(it->second.first.c_str()))); serial->addItem(item); if (it->second.second.compare(0,9,"Thymio-II") == 0) { serial->setCurrentItem(item); serialPortSet = true; } } if (sectionEnabled == 0 && !serialPortSet) sectionEnabled = 1; serialGroupBox->setChecked(sectionEnabled == 0); serial->setSelectionMode(QAbstractItemView::SingleSelection); serialLayout->addWidget(serial); connect(serial, SIGNAL(itemSelectionChanged()), SLOT(setupFlashButtonState())); serialGroupBox->setLayout(serialLayout); connect(serialGroupBox, SIGNAL(clicked()), SLOT(serialGroupChecked())); mainLayout->addWidget(serialGroupBox); // custom target customGroupBox = new QGroupBox(tr("Custom connection")); customGroupBox->setCheckable(true); customGroupBox->setChecked(sectionEnabled == 1); QHBoxLayout* customLayout = new QHBoxLayout(); QLineEdit* custom = new QLineEdit(settings.value("custom target", ASEBA_DEFAULT_TARGET).toString()); customLayout->addWidget(custom); customGroupBox->setLayout(customLayout); connect(customGroupBox, SIGNAL(clicked()), SLOT(customGroupChecked())); mainLayout->addWidget(customGroupBox); // file selector QGroupBox* fileGroupBox = new QGroupBox(tr("Firmware file")); QHBoxLayout *fileLayout = new QHBoxLayout(); lineEdit = new QLineEdit(this); fileButton = new QPushButton(tr("Select..."), this); fileLayout->addWidget(fileButton); fileLayout->addWidget(lineEdit); fileGroupBox->setLayout(fileLayout); mainLayout->addWidget(fileGroupBox); // progress bar progressBar = new QProgressBar(this); progressBar->setValue(0); progressBar->setRange(0, 100); mainLayout->addWidget(progressBar); // flash and quit buttons QHBoxLayout *flashLayout = new QHBoxLayout(); flashButton = new QPushButton(tr("Update"), this); flashButton->setEnabled(false); flashLayout->addWidget(flashButton); quitButton = new QPushButton(tr("Quit"), this); flashLayout->addWidget(quitButton); mainLayout->addItem(flashLayout); // connections connect(fileButton, SIGNAL(clicked()), SLOT(openFile())); connect(flashButton, SIGNAL(clicked()), SLOT(doFlash())); connect(quitButton, SIGNAL(clicked()), SLOT(close())); connect(&flashFutureWatcher, SIGNAL(finished()), SLOT(flashFinished())); show(); }
void ChatDlg::appendMessage(const Message &m, bool local) { // figure out the encryption state bool encChanged = false; bool encEnabled = false; if (lastWasEncrypted_ != m.wasEncrypted()) { encChanged = true; } lastWasEncrypted_ = m.wasEncrypted(); encEnabled = lastWasEncrypted_; if (encChanged) { if (encEnabled) { appendSysMsg(QString("<icon name=\"psi/cryptoYes\"> ") + tr("Encryption Enabled")); if (!local) { setPGPEnabled(true); } } else { appendSysMsg(QString("<icon name=\"psi/cryptoNo\"> ") + tr("Encryption Disabled")); if (!local) { setPGPEnabled(false); // enable warning warnSend_ = true; QTimer::singleShot(3000, this, SLOT(setWarnSendFalse())); } } } QString txt = messageText(m); ChatDlg::SpooledType spooledType = m.spooled() ? ChatDlg::Spooled_OfflineStorage : ChatDlg::Spooled_None; if (isEmoteMessage(m)) appendEmoteMessage(spooledType, m.timeStamp(), local, txt); else appendNormalMessage(spooledType, m.timeStamp(), local, txt); appendMessageFields(m); if (local) { deferredScroll(); } // if we're not active, notify the user by changing the title if (!isActiveTab()) { ++pending_; invalidateTab(); if (PsiOptions::instance()->getOption("options.ui.flash-windows").toBool()) { doFlash(true); } if (PsiOptions::instance()->getOption("options.ui.chat.raise-chat-windows-on-new-messages").toBool()) { if (isTabbed()) { TabDlg* tabSet = getManagingTabDlg(); tabSet->selectTab(this); ::bringToFront(tabSet, false); } else { ::bringToFront(this, false); } } } //else { // messagesRead(jid()); //} if (!local) { keepOpen_ = true; QTimer::singleShot(1000, this, SLOT(setKeepOpenFalse())); } }
void flashOff() { doFlash(false); }
void flashOn() { doFlash(true); }