/**
 * Initialize the device.
 *
 * @param descriptor Device information
 */
void deviceInit(DeviceDescriptor& descriptor) {
#ifdef DEBUG
  debug_serial.begin(DEBUG_BAUDRATE);
#endif

  EEPROM.setMemPool(0, EEPROM_SIZE);

  device = &descriptor;
  device->messenger = &messenger;

  if (device->ledPin > 0) {
    pinMode(device->ledPin, OUTPUT);
    digitalWrite(device->ledPin, LOW);
  }
  blinkPattern = NULL;

  if (device->buttonPin > 0) {
    pinMode(device->buttonPin, INPUT);
    digitalWrite(device->buttonPin, HIGH);
  }

  messenger.attach(MSG_REGISTER_RESPONSE, onServerRegisterResponse);
  messenger.attach(MSG_PING, onPing);
  if (device->registerMessageHandlers) {
    (*device->registerMessageHandlers)();
  }

  wifly_serial.begin(WIFLY_BAUDRATE);
}
Пример #2
0
void setup()
{
  Serial.begin(115200);
  strip.begin();
  strip.setBrightness(40);
  strip.show();
  cmdMessenger.attach(kSetLED, OnSetLed);
}
Пример #3
0
void initCommands()
{
    Serial.println("Init command...");
    Serial1.begin(57600);
    cmdMessenger.printLfCr();
    
    cmdMessenger.attach(onUnknownCommand);
    cmdMessenger.attach(kSetAnglePID, onSetAnglePID);
    cmdMessenger.attach(kSetAngleOutputLimits, onSetAngleOutputLimits);
    cmdMessenger.attach(kSetAcceleration, onSetAcceleration);
    cmdMessenger.attach(kSetSpeed, onSetSpeed);
    cmdMessenger.attach(kSetAverage, onSetAverage);
    cmdMessenger.attach(kRecalibrate, onRecalibrate);
    Timer3.getAvailable().attachInterrupt(processCommands).setPeriod(100000).start();
    cmdMessenger.sendCmd(kStatus, "System ready");
}
Пример #4
0
void attachCommandCallbacks()
{
	cmdMessenger.attach(kQStatus, onReturnStatus);
	cmdMessenger.attach(kQDeviceInfo, onReturnDeviceInfo);
	cmdMessenger.attach(kSSaveSettings, onSaveSettings);
	cmdMessenger.attach(kSDataPushMode, onDataSetPushMode);
	cmdMessenger.attach(kQDataPushMode, onDataReturnPushMode);
	cmdMessenger.attach(kSDataQueryInt, onDataSetQueryInt);
	cmdMessenger.attach(kQDataQueryInt, onDataReturnQueryInt);
	cmdMessenger.attach(kQTemp, onReturnTempQuery);
	cmdMessenger.attach(kQHumi, onReturnHumiQuery);
	cmdMessenger.attach(kQPres, onReturnPresQuery);
	cmdMessenger.attach(kQLux, onReturnLuxQuery);
	cmdMessenger.attach(kQPS, onReturnPSQuery);
	cmdMessenger.attach(kSLedMode, onLedSetMode);
	cmdMessenger.attach(kQLedMode, onLedReturnMode);
	cmdMessenger.attach(kSLedModeRestore, onLedRestoreMode);
	cmdMessenger.attach(kSLedFadeMinMax, onLedSetFadeLimits);
	cmdMessenger.attach(kQLedFadeMinMax, onLedReturnFadeLimits);
	cmdMessenger.attach(kSLedCmdFadeTo, onLedFadeTo);
	cmdMessenger.attach(kSCalibratePS, onCalibratePS);
	cmdMessenger.attach(kSReset, onSoftReset);
}