示例#1
0
DigitalIODevice::DigitalIODevice(StaticDeviceContainer *aClassContainerP, const string &aDeviceConfig) :
  StaticDevice((DeviceClassContainer *)aClassContainerP),
  digitalIoType(digitalio_unknown)
{
  // last : separates behaviour from pin specification
  size_t i = aDeviceConfig.rfind(":");
  string ioname = aDeviceConfig;
  bool inverted = false;
  if (i!=string::npos) {
    ioname = aDeviceConfig.substr(0,i);
    string mode = aDeviceConfig.substr(i+1,string::npos);
    if (mode[0]=='!') {
      inverted = true;
      mode.erase(0,1);
    }
    if (mode=="button")
      digitalIoType = digitalio_button;
    else if (mode=="input")
      digitalIoType = digitalio_input;
    else if (mode=="light")
      digitalIoType = digitalio_light;
    else if (mode=="relay") {
      digitalIoType = digitalio_relay;
    }
    else {
      LOG(LOG_ERR,"unknown digital IO type: %s\n", mode.c_str());
    }
  }
  // basically act as black device so we can configure colors
  if (digitalIoType==digitalio_button) {
    primaryGroup = group_black_joker;
    // Standard device settings without scene table
    installSettings();
    // Digital input as button
    buttonInput = ButtonInputPtr(new ButtonInput(ioname.c_str(), inverted));
    buttonInput->setButtonHandler(boost::bind(&DigitalIODevice::buttonHandler, this, _1, _2), true);
    // - create one button input
    ButtonBehaviourPtr b = ButtonBehaviourPtr(new ButtonBehaviour(*this));
    b->setHardwareButtonConfig(0, buttonType_undefined, buttonElement_center, false, 0, false); // mode not restricted
    b->setGroup(group_yellow_light); // pre-configure for light
    addBehaviour(b);
  }
  else if (digitalIoType==digitalio_input) {
    primaryGroup = group_black_joker;
    // Standard device settings without scene table
    installSettings();
    // Digital input as binary input (AKM, automation block type)
    buttonInput = ButtonInputPtr(new ButtonInput(ioname.c_str(), inverted));
    buttonInput->setButtonHandler(boost::bind(&DigitalIODevice::inputHandler, this, _1, _2), true);
    // - create one binary input
    BinaryInputBehaviourPtr b = BinaryInputBehaviourPtr(new BinaryInputBehaviour(*this));
    b->setHardwareInputConfig(binInpType_none, usage_undefined, true, Never);
    addBehaviour(b);
  }
  else if (digitalIoType==digitalio_light) {
    // Digital output as light on/off switch
    primaryGroup = group_yellow_light;
    indicatorOutput = IndicatorOutputPtr(new IndicatorOutput(ioname.c_str(), inverted, false));
    // - use light settings, which include a scene table
    installSettings(DeviceSettingsPtr(new LightDeviceSettings(*this)));
    // - add simple single-channel light behaviour
    LightBehaviourPtr l = LightBehaviourPtr(new LightBehaviour(*this));
    l->setHardwareOutputConfig(outputFunction_switch, usage_undefined, false, -1);
    addBehaviour(l);
  }
  else if (digitalIoType==digitalio_relay) {
    primaryGroup = group_black_joker;
    // - standard device settings with scene table
    installSettings(DeviceSettingsPtr(new SceneDeviceSettings(*this)));
    // Digital output
    indicatorOutput = IndicatorOutputPtr(new IndicatorOutput(ioname.c_str(), inverted, false));
    // - add generic output behaviour
    OutputBehaviourPtr o = OutputBehaviourPtr(new OutputBehaviour(*this));
    o->setHardwareOutputConfig(outputFunction_switch, usage_undefined, false, -1);
    o->setGroupMembership(group_black_joker, true); // put into joker group by default
    o->addChannel(ChannelBehaviourPtr(new DigitalChannel(*o)));
    addBehaviour(o);
  }
	deriveDsUid();
}
示例#2
0
EnoceanDevicePtr EnoceanRemoteControlHandler::newDevice(
  EnoceanDeviceContainer *aClassContainerP,
  EnoceanAddress aAddress,
  EnoceanSubDevice &aSubDeviceIndex,
  EnoceanProfile aEEProfile, EnoceanManufacturer aEEManufacturer,
  bool aNeedsTeachInResponse
) {
  EnoceanDevicePtr newDev; // none so far
  if (EEP_RORG(aEEProfile)==PSEUDO_RORG_REMOTECONTROL) {
    // is a remote control device
    if (EEP_FUNC(aEEProfile)==PSEUDO_FUNC_SWITCHCONTROL && aSubDeviceIndex<1) {
      // device using F6 RPS messages to control actors
      if (EEP_TYPE(aEEProfile)==PSEUDO_TYPE_ON_OFF) {
        // simple on/off relay device
        newDev = EnoceanDevicePtr(new EnoceanRelayControlDevice(aClassContainerP));
        // standard single-value scene table (SimpleScene)
        newDev->installSettings(DeviceSettingsPtr(new SceneDeviceSettings(*newDev)));
        // assign channel and address
        newDev->setAddressingInfo(aAddress, aSubDeviceIndex);
        // assign EPP information
        newDev->setEEPInfo(aEEProfile, aEEManufacturer);
        // is joker
        newDev->setPrimaryGroup(group_black_joker);
        // function
        newDev->setFunctionDesc("on/off relay");
        // is always updateable (no need to wait for incoming data)
        newDev->setAlwaysUpdateable();
        // - add standard output behaviour
        OutputBehaviourPtr o = OutputBehaviourPtr(new OutputBehaviour(*newDev.get()));
        o->setHardwareOutputConfig(outputFunction_switch, outputmode_binary, usage_undefined, false, -1);
        o->setGroupMembership(group_black_joker, true); // put into joker group by default
        o->addChannel(ChannelBehaviourPtr(new DigitalChannel(*o)));
        // does not need a channel handler at all, just add behaviour
        newDev->addBehaviour(o);
        // count it
        aSubDeviceIndex++;
      }
      else if (EEP_TYPE(aEEProfile)==PSEUDO_TYPE_SWITCHED_LIGHT) {
        // simple on/off relay device
        newDev = EnoceanDevicePtr(new EnoceanRelayControlDevice(aClassContainerP));
        // light device scene
        newDev->installSettings(DeviceSettingsPtr(new LightDeviceSettings(*newDev)));
        // assign channel and address
        newDev->setAddressingInfo(aAddress, aSubDeviceIndex);
        // assign EPP information
        newDev->setEEPInfo(aEEProfile, aEEManufacturer);
        // is light
        newDev->setPrimaryGroup(group_yellow_light);
        // function
        newDev->setFunctionDesc("on/off light");
        // is always updateable (no need to wait for incoming data)
        newDev->setAlwaysUpdateable();
        // - add standard output behaviour
        LightBehaviourPtr l = LightBehaviourPtr(new LightBehaviour(*newDev.get()));
        l->setHardwareOutputConfig(outputFunction_switch, outputmode_binary, usage_undefined, false, -1);
        // does not need a channel handler at all, just add behaviour
        newDev->addBehaviour(l);
        // count it
        aSubDeviceIndex++;
      }
      else if (EEP_TYPE(aEEProfile)==PSEUDO_TYPE_BLIND) {
        // full-featured blind controller
        newDev = EnoceanDevicePtr(new EnoceanBlindControlDevice(aClassContainerP));
        // standard single-value scene table (SimpleScene) with Shadow defaults
        newDev->installSettings(DeviceSettingsPtr(new ShadowDeviceSettings(*newDev)));
        // assign channel and address
        newDev->setAddressingInfo(aAddress, aSubDeviceIndex);
        // assign EPP information
        newDev->setEEPInfo(aEEProfile, aEEManufacturer);
        // is shadow
        newDev->setPrimaryGroup(group_grey_shadow);
        // function
        newDev->setFunctionDesc("blind control");
        // is always updateable (no need to wait for incoming data)
        newDev->setAlwaysUpdateable();
        // - add shadow behaviour
        ShadowBehaviourPtr sb = ShadowBehaviourPtr(new ShadowBehaviour(*newDev.get()));
        sb->setHardwareOutputConfig(outputFunction_positional, outputmode_gradual, usage_undefined, false, -1);
        sb->setHardwareName("blind");
        sb->setDeviceParams(shadowdevice_jalousie, false, MIN_MOVE_TIME, MAX_SHORT_MOVE_TIME, MIN_LONG_MOVE_TIME);
        sb->position->syncChannelValue(100); // assume fully up at beginning
        sb->angle->syncChannelValue(100); // assume fully open at beginning
        // does not need a channel handler at all, just add behaviour
        newDev->addBehaviour(sb);
        // count it
        aSubDeviceIndex++;
      }
    }
  }
  // remote control devices never need a teach-in response
  // return device (or empty if none created)
  return newDev;
}