Exemplo n.º 1
0
    Value Eeprom::readEeprom(const EepromLocation& location)
    {
        //get the type and location from the EepromLocation object
        ValueType type = location.valueType();
        uint16 eepromLoc = location.location();

        //determine which readEeprom function to call, based on the valueType
        switch(type)
        {
            case valueType_uint16:
                return Value(type, readEeprom(eepromLoc));

            case valueType_float:
                return Value(type, readEeprom_float(eepromLoc));

            case valueType_uint32:
                return Value(type, readEeprom_uint32(eepromLoc));

            case valueType_int16:
                return Value(type, readEeprom_int16(eepromLoc));

            default:
                assert(false);    //we are trying to read a value with an invalid type? 
                return Value(type, readEeprom(eepromLoc));    //just default to uint16
        }
    }
Exemplo n.º 2
0
    uint32 Eeprom::readEeprom_uint32(uint16 location)
    {
        //try to read the first part of the float
        uint16 msw = readEeprom(location);

        //try to read the second part of the float
        uint16 lsw = readEeprom(location + 2);

        //make a uint32 and return
        return Utils::make_uint32(Utils::msb(msw), Utils::lsb(msw), Utils::msb(lsw), Utils::lsb(lsw));
    }
Exemplo n.º 3
0
    float Eeprom::readEeprom_float(uint16 location)
    {
        //try to read the first part of the float
        uint16 msw = readEeprom(location);

        //try to read the second part of the float
        uint16 lsw = readEeprom(location + 2);

        //split the words into bytes
        uint8 b1, b2, b3, b4;
        Utils::split_uint16(msw, b1, b2);
        Utils::split_uint16(lsw, b3, b4);

        //convert the values into a float and return
        return Utils::make_float(b1, b2, b3, b4, Utils::littleEndian);    //note that this just swapped endianness by passing the msb as the lsb
    }
Exemplo n.º 4
0
void startUp()
{
  readEeprom();
  setFanSpeed(255);
  _delay_us(100);
  restoreState();
}
Exemplo n.º 5
0
//************************************************************************
uint8_t EEPROMClass::read(unsigned int address)
{
	uint8_t data;

    readEeprom((uint32_t)address, &data);

	return data;
}
Exemplo n.º 6
0
void Thermal_init(){
    I2C_init(THERMAL_I2C_ID,I2C_CLOCK_FREQ);
    count = 0;

    readEeprom();
    writeTrimmingValue();
    writeConfigReg();
    readConfigReg();
    configCalculationData();

    Timer_new(TIMER_THERMAL,READ_DELAY);
}
Exemplo n.º 7
0
void startUp()
{
  readEeprom();
  for(char i = 0; i < 12; i++)
  {
    crossfade[i] = save_compbuff[i];
  }
  setFanSpeed(255);
  _delay_us(100);
  setFanSpeed(save_fanspeed);
  crossFade(100);
  for(char i = 0; i < 12; i++)
  {
    crossfade[i] = 0;
  }
}
Exemplo n.º 8
0
void setup() {
  EEPROM.setMemPool(0, EEPROM_SIZE);
  readEeprom();

  pinMode(PIN_GREEN, OUTPUT);
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_YELLOW, OUTPUT);

  green = false;
  red = false;
  yellow = false;
  mute = false;
  contentLength = 0;

  selfTest();
  updateLeds();
  Serial.begin(57600);
  wdt_enable(WDTO_4S);
}
Exemplo n.º 9
0
 int16 Eeprom::readEeprom_int16(uint16 location)
 {
     return static_cast<int16>(readEeprom(location));
 }
Exemplo n.º 10
0
void FlashFirmwareDialog::startFlash(const QString &filename)
{
  bool backup = g.backupOnFlash();

  close();

  ProgressDialog progressDialog(this, tr("Write Firmware to Radio"), CompanionIcon("write_flash.png"));

  // check hardware compatibility if requested
  if (g.checkHardwareCompatibility()) {
    QString tempFirmware = generateProcessUniqueTempFileName("flash-check.bin");
    if (!readFirmware(tempFirmware, progressDialog.progress())) {
      QMessageBox::warning(this, tr("Firmware check failed"), tr("Could not check firmware from radio"));
      return;
    }
    FirmwareInterface previousFirmware(tempFirmware);
    qunlink(tempFirmware);
    FirmwareInterface newFirmware(filename);
    qDebug() << "startFlash: checking firmware compatibility between " << tempFirmware << "and" << filename;
    if (!newFirmware.isHardwareCompatible(previousFirmware)) {
      QMessageBox::warning(this, tr("Firmware check failed"), tr("New firmware is not compatible with the one currently installed!"));
      if (isTempFileName(filename)) {
        qDebug() << "startFlash: removing temporary file" << filename;
        qunlink(filename);
      }
      return;
    }
  }

  // backup if requested
  bool result = true;
  QString backupFilename;
  QString backupPath;
  if (backup) {
    backupPath = g.profile[g.id()].pBackupDir();
    if (backupPath.isEmpty()) {
      backupPath=g.backupDir();
    }     
    backupFilename = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin";
    result = readEeprom(backupFilename, progressDialog.progress());
    sleep(2);
  }

  // flash
  result = (result && writeFirmware(filename, progressDialog.progress()));

  // restore if backup requested
  if (backup && result) {
    sleep(2);
    QString restoreFilename = generateProcessUniqueTempFileName("restore.bin");
    if (!convertEEprom(backupFilename, restoreFilename, filename)) {
      QMessageBox::warning(this, tr("Conversion failed"), tr("Cannot convert Models and Settings for use with this firmware, original data will be used"));
      restoreFilename = backupFilename;
    }
    if (!writeEeprom(restoreFilename, progressDialog.progress())) {
      QMessageBox::warning(this, tr("Restore failed"), tr("Could not restore Models and Settings to Radio. The models and settings data file can be found at: %1").arg(backupFilename));
    }
  }

  progressDialog.progress()->setInfo(tr("Flashing done"));
  progressDialog.exec();

  if (isTempFileName(filename)) {
    qDebug() << "startFlash: removing temporary file" << filename;
    qunlink(filename);
  }
}
Exemplo n.º 11
0
    AutoBalanceResult WirelessNode_Impl::autoBalance(const ChannelMask& mask, float targetPercent)
    {
        Utils::checkBounds_min(targetPercent, 0.0f);
        Utils::checkBounds_max(targetPercent, 100.0f);

        //attempt a few pings first 
        //(legacy (v1) autobalance doesn't have a response packet, so need to check communication)
        uint8 retryCounter = 0;
        bool pingSuccess = false;
        while(!pingSuccess && retryCounter < 3)
        {
            pingSuccess = ping().success();
            retryCounter++;
        }

        if(!pingSuccess)
        {
            throw Error_NodeCommunication(nodeAddress());
        }

        //find the eeprom location that the autobalance will adjust
        //Note: this also verifies that it is supported for this mask
        const EepromLocation& eepromLoc = features().findEeprom(WirelessTypes::chSetting_autoBalance, mask);

        //currently, autobalance is always per channel, so get the channel from the mask
        uint8 channelNumber = mask.lastChEnabled();

        AutoBalanceResult result;

        //perform the autobalance command with the parent base station
        m_baseStation.node_autoBalance(protocol(), m_address, channelNumber, targetPercent, result);

        //clear the cache of the hardware offset eeprom location we adjusted
        eeprom().clearCacheLocation(eepromLoc.location());

        Utils::threadSleep(200);

        //if we used the legacy command, we don't get result info, need to do more work to get it
        if(result.m_errorCode == WirelessTypes::autobalance_legacyNone)
        {
            result.m_errorCode = WirelessTypes::autobalance_maybeInvalid;

            //force the read eeprom retries to a minimum of 3
            uint8 startRetries = m_eepromSettings.numRetries;

            //when this goes out of scope, it will change back the original retries value
            ScopeHelper writebackRetries(std::bind(&WirelessNode_Impl::setReadWriteRetries, this, startRetries));

            //if there are less than 10 retries
            if(startRetries < 10)
            {
                //we want to retry at least a few times
                setReadWriteRetries(10);
            }
            else
            {
                //don't need to write back the retries since we didn't make a change
                writebackRetries.cancel();
            }

            //read the updated hardware offset from the node
            result.m_hardwareOffset = readEeprom(eepromLoc).as_uint16();

            bool readSensorSuccess = false;

            uint8 readSensorTry = 0;
            do
            {
                //perform the read single sensor command
                uint16 sensorVal = 0;
                readSensorSuccess = m_baseStation.node_readSingleSensor(m_address, channelNumber, sensorVal);

                if(readSensorSuccess)
                {
                    //find the max bits value of the node
                    uint32 maxBitsVal = 0;
                    switch(model())
                    {
                        case WirelessModels::node_vLink:
                        case WirelessModels::node_sgLink_rgd:
                        case WirelessModels::node_shmLink:
                            maxBitsVal = 65536;
                            break;

                        default:
                            maxBitsVal = 4096;
                            break;
                    }

                    //calculate and store the percent achieved
                    result.m_percentAchieved = static_cast<float>(sensorVal) / static_cast<float>(maxBitsVal) * 100.0f;
                }

                readSensorTry++;
            }
            while(!readSensorSuccess && readSensorTry <= 3);

            if(readSensorSuccess)
            {
                //mark as questionable if not close enough to the target percentage
                if(std::abs(result.m_percentAchieved - targetPercent) > 5.0)
                {
                    result.m_errorCode = WirelessTypes::autobalance_maybeInvalid;
                }
                else
                {
                    result.m_errorCode = WirelessTypes::autobalance_success;
                }
            }
        }

        return result;
    }