Ejemplo n.º 1
0
void GenericHID::onMicrocontrollerImportAndProgram()
{
    // Get the filename
    QString sFilename = QFileDialog::getOpenFileName( this, "Open GenericHID device", m_sLastExportFile, "Microcontroller Config Description file (*.mcd);;All files (*)" );
    if ( sFilename.isNull() || sFilename.isEmpty() )
        return;

    // read the device xml
    QFile file(sFilename.toAscii().constData());
    if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
    {
        QMessageBox::critical( this, "Can't open", QString("Failed to open file '%1':%2").arg(sFilename).arg(file.errorString()) );
        return;
    }
    m_sLastExportFile = sFilename;

    QString s;
    {
        // Unclear on how to close a file when the stream is using it, hence the scope.
        QTextStream stream(&file);
        s = stream.readAll();
    }
    file.close();

    if ( s.isEmpty() )
    {
        QMessageBox msg(QMessageBox::Critical, "Errors Found", QString("Data file '%1' is empty, or failed to read file (%2)").arg(sFilename).arg(file.errorString()), QMessageBox::Ok, this );
        msg.exec();
        return;
    }

    // make eeprom
    MakeEEPROM eeprom;
    if ( !eeprom.loadXML( s ) )
    {
        QMessageBox::critical( this, "Error", eeprom.lastError() );
        return;
    }

    ByteArray buf = eeprom.makeEEPROM();
    if ( buf.isEmpty() )
    {
        QMessageBox::critical( this, "Error", eeprom.lastError() );
        return;
    }

    QString sIntelHex = MakeEEPROM::MakeIntelHexFormat( DYNAMIC_HIDDATA_ADDRESS, buf );

    DoProgram( sIntelHex );
}
Ejemplo n.º 2
0
void GenericHID::onMicrocontrollerProgram()
{
    RetrieveProperties();

    // Verify
    QString sError;
    if ( !m_pScene->VerifyShapes( sError ) )
    {
        QMessageBox msg(QMessageBox::Critical, "Errors Found", "Errors were found processing the device configuration", QMessageBox::Ok, this );
        msg.setDetailedText( sError );
        msg.exec();
        return;
    }
    // make xml
    QString s = m_pScene->MakeDeviceXML();
    if ( s.isEmpty() )
    {
        QMessageBox msg(QMessageBox::Critical, "Errors Found", "Failed to create the device configuration", QMessageBox::Ok, this );
        msg.exec();
        return;
    }

    // make eeprom
    MakeEEPROM eeprom;
    if ( !eeprom.loadXML( s ) )
    {
        QMessageBox::critical( this, "Error", eeprom.lastError() );
        return;
    }

    ByteArray buf = eeprom.makeEEPROM();
    if ( buf.isEmpty() )
    {
        QMessageBox::critical( this, "Error", eeprom.lastError() );
        return;
    }

    QString sIntelHex = MakeEEPROM::MakeIntelHexFormat( DYNAMIC_HIDDATA_ADDRESS, buf );

    LOG_DEBUG( m_Logger, "Program HexFile - " );
    LOG_DEBUG( m_Logger, sIntelHex );

    // program
    DoProgram( sIntelHex );
}
Ejemplo n.º 3
0
int main()
{
    Init();
    DoProgram();
    return 0;
}