示例#1
0
文件: swap.cpp 项目: mgehre/panstamp
/**
 * nvolatToFactoryDefaults
 * 
 * Write default config values in non-volatile memory
 */
void SWAP::nvolatToFactoryDefaults(void)
{
  STORAGE nvMem;

  // Signature
  uint8_t signature[] = {NVOLAT_SIGNATURE_HIGH, NVOLAT_SIGNATURE_LOW};
  nvMem.write(signature, DEFAULT_NVOLAT_SECTION, NVOLAT_SIGNATURE, sizeof(signature));
  
  // Frequency channel
  uint8_t channel[] = {CCDEF_CHANNR};
  nvMem.write(channel, DEFAULT_NVOLAT_SECTION, NVOLAT_FREQ_CHANNEL, sizeof(channel));
  
  // Sync word
  uint8_t syncW[] = {CCDEF_SYNC1, CCDEF_SYNC0};
  nvMem.write(syncW, DEFAULT_NVOLAT_SECTION, NVOLAT_SYNC_WORD, sizeof(syncW));

  // SWAP address (pseudo-random number)
  uint16_t random = panstamp.GET_RANDOM();
  uint8_t addr[] = {(random >> 8) & 0xFF, random & 0xFF};
  nvMem.write(addr, DEFAULT_NVOLAT_SECTION, NVOLAT_DEVICE_ADDR, sizeof(addr));
  
  // TX interval
  uint8_t txInt[] = {0xFF, 0};
  nvMem.write(txInt, DEFAULT_NVOLAT_SECTION, NVOLAT_TX_INTERVAL, sizeof(txInt));
}
uint8_t Encoder<POT,STORAGE, LOG>::saveSettings(STORAGE& storage, int addr) {
  uint8_t rvalue = true;
  storage.write(addr, 179);
  addr++;
  JTIncrementalEncoder::saveSettings(storage, this->state.channels.a, addr);
  JTIncrementalEncoder::saveSettings(storage, this->state.channels.b, addr);
  return rvalue;
}
/**
 * setData
 * 
 * Set register value
 * 
 * @param data New register value
 */
void REGISTER::setData(unsigned char *data) 
{
  // Update register value
  if (setValue != NULL)
    setValue(id, data);

  // Send SWAP status message
  sendSwapStatus();

  // Does the value need to be saved in info memory (flash)?
  if (eepromAddress >= 0)
  {
    STORAGE nvMem;   
    // Write info memory
    nvMem.write(value, eepromBank, eepromAddress, length);
  }
}
static inline void eepromWriteInt(STORAGE& storage, int addr, int value) {
  uint8_t low = lowByte(value);
  uint8_t high = highByte(value);
  storage.write(addr++, low);
  storage.write(addr, high);
}