void WedgeI2CBus::selectQsfpImpl(unsigned int port) { auto oldValues = getSwitchValues(selectedPort_); auto newValues = getSwitchValues(port); // One of the new values should be 0. Set this one first, // to ensure that we never have more than one port selected at a time. if (newValues.first == 0) { if (newValues.first != oldValues.first) { dev_->writeByte(ADDR_SWITCH_1, newValues.first); } selectedPort_ = NO_PORT; // In case the second write throws if (newValues.second != oldValues.second) { dev_->writeByte(ADDR_SWITCH_2, newValues.second); } } else { if (newValues.second != oldValues.second) { dev_->writeByte(ADDR_SWITCH_2, newValues.second); } selectedPort_ = NO_PORT; // In case the second write throws if (newValues.first != oldValues.first) { dev_->writeByte(ADDR_SWITCH_1, newValues.first); } } selectedPort_ = port; }
bool Switches::getSwitch(int num) { if (num >= 1 && num <= 4) { return getSwitchValues() & (1 << (num-1)); } else { return false; } }