📄 onewirecontainer1f.java
字号:
* * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() * @see #hasLevelSensing() */ public boolean getLevel (int channel, byte[] state) throws OneWireException { return (Bit.arrayReadBit(1 + channel * 2, STATUS_OFFSET, state) == 1); } /** * Checks the latch state of the indicated channel. * * @param channel channel to execute this operation, in the range [0 to (<code>getNumberChannels(byte[])</code> - 1)] * @param state current state of the device returned from <code>readDevice()</code> * * @return <code>true</code> if channel latch is 'on' * or conducting and <code>false</code> if channel latch is 'off' and not * conducting. Note that the actual output when the latch is 'on' * is returned from the <code>isHighSideSwitch()</code> method. * * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() * @see #isHighSideSwitch() * @see #setLatchState(int,boolean,boolean,byte[]) */ public boolean getLatchState (int channel, byte[] state) { return (Bit.arrayReadBit(channel * 2, STATUS_OFFSET, state) == 0); } /** * Checks if the indicated channel has experienced activity. * This occurs when the level on the PIO pins changes. To clear * the activity that is reported, call <code>clearActivity()</code>. * To avoid an exception, verify that this device supports activity * sensing by calling the method <code>hasActivitySensing()</code>. * * @param channel channel to execute this operation, in the range [0 to (<code>getNumberChannels(byte[])</code> - 1)] * @param state current state of the device returned from <code>readDevice()</code> * * @return <code>true</code> if activity was detected and <code>false</code> if no activity was detected * * @throws OneWireException if this device does not have activity sensing * * @see #hasActivitySensing() * @see #clearActivity() */ public boolean getSensedActivity (int channel, byte[] state) throws OneWireException { return (Bit.arrayReadBit(4 + channel, STATUS_OFFSET, state) == 1); } //-------- //-------- DS2409 Specific Switch 'get' Methods //-------- /** * Checks if the control I/O pin mode is automatic (see DS2409 data sheet). * * @param state current state of the device returned from <code>readDevice()</code> * * @return <code>true</code> if control mode is automatic */ public boolean isModeAuto (byte[] state) { return (Bit.arrayReadBit(7, STATUS_OFFSET, state) == 0); } /** * Checks the channel association of the control pin. * This value only makes sense if * the control mode is automatic (see <CODE>isModeAuto</CODE>). * * @param state current state of the device returned from <code>readDevice()</code> * * @return <code>int</code> the channel number that is associated * with the control pin */ public int getControlChannelAssociation (byte[] state) { return Bit.arrayReadBit(6, STATUS_OFFSET, state); } /** * Checks the control data value. * This value only makes sense if * the control mode is manual (see <CODE>isModeAuto</CODE>). * 0 = output transistor off, 1 = output transistor on * * @param state current state of the device returned from <code>readDevice()</code> * * @return <code>int</code> the control output transistor state */ public int getControlData (byte[] state) { return Bit.arrayReadBit(6, STATUS_OFFSET, state); } /** * Gets flag that indicates if a device was present when doing the * last smart on. Note that this flag is only valid if the DS2409 * flag was cleared with an ALL_LINES_OFF command and the last writeDevice * performed a 'smart-on' on one of the channels. * * @return <code>true</code> if device detected on branch */ public boolean getLastSmartOnDeviceDetect () { return devicesOnBranch; } //-------- //-------- Switch 'set' Methods //-------- /** * Sets the latch state of the indicated channel. * The method <code>writeDevice(byte[])</code> must be called to finalize * changes to the device. Note that multiple 'set' methods can * be called before one call to <code>writeDevice(byte[])</code>. * * @param channel channel to execute this operation, in the range [0 to (<code>getNumberChannels(byte[])</code> - 1)] * @param latchState <code>true</code> to set the channel latch 'on' * (conducting) and <code>false</code> to set the channel latch 'off' (not * conducting). Note that the actual output when the latch is 'on' * is returned from the <code>isHighSideSwitch()</code> method. * @param doSmart If latchState is 'on'/<code>true</code> then doSmart indicates * if a 'smart on' is to be done. To avoid an exception * check the capabilities of this device using the * <code>hasSmartOn()</code> method. * @param state current state of the device returned from <code>readDevice()</code> * * @see #hasSmartOn() * @see #getLatchState(int,byte[]) * @see com.dalsemi.onewire.container.OneWireSensor#writeDevice(byte[]) */ public void setLatchState (int channel, boolean latchState, boolean doSmart, byte[] state) { // set the state flag if (latchState) state [channel + 1] = ( byte ) ((doSmart) ? SWITCH_SMART : SWITCH_ON); else state [channel + 1] = ( byte ) SWITCH_OFF; // indicate in bitmap the the state has changed Bit.arrayWriteBit(1, channel + 1, BITMAP_OFFSET, state); } /** * Clears the activity latches the next time possible. For * example, on a DS2406/07, this happens the next time the * status is read with <code>readDevice()</code>. * * @throws OneWireException if this device does not support activity sensing * * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() * @see #getSensedActivity(int,byte[]) */ public void clearActivity () throws OneWireException { clearActivityOnWrite = true; } //-------- //-------- DS2409 Specific Switch 'set' Methods //-------- /** * Sets the control pin mode. * The method <code>writeDevice(byte[])</code> must be called to finalize * changes to the device. Note that multiple 'set' methods can * be called before one call to <code>writeDevice(byte[])</code>. * * @param makeAuto <CODE>true</CODE> to set to auto mode, false for manual mode * @param state current state of the device returned from <code>readDevice()</code> */ public void setModeAuto (boolean makeAuto, byte[] state) { // set the bit Bit.arrayWriteBit((makeAuto ? 0 : 1), 7, STATUS_OFFSET, state); // indicate in bitmap the the state has changed Bit.arrayWriteBit(1, STATUS_OFFSET, BITMAP_OFFSET, state); } /** * Sets the control pin channel association. This only makes sense * if the contol pin is in automatic mode. * The method <code>writeDevice(byte[])</code> must be called to finalize * changes to the device. Note that multiple 'set' methods can * be called before one call to <code>writeDevice(byte[])</code>. * * @param channel channel to associate with control pin * @param state current state of the device returned from <code>readDevice()</code> * * @throws OneWireException when trying to set channel association in manual mode */ public void setControlChannelAssociation (int channel, byte[] state) throws OneWireException { // check for invalid mode if (!isModeAuto(state)) throw new OneWireException(address, "Trying to set channel association in manual mode"); // set the bit Bit.arrayWriteBit(channel, 6, STATUS_OFFSET, state); // indicate in bitmap the the state has changed Bit.arrayWriteBit(1, STATUS_OFFSET, BITMAP_OFFSET, state); } /** * Sets the control pin data to a value. Note this * method only works if the control pin is in manual mode. * The method <code>writeDevice(byte[])</code> must be called to finalize * changes to the device. Note that multiple 'set' methods can * be called before one call to <code>writeDevice(byte[])</code>. * * @param data <CODE>true</CODE> for on and <CODE>false</CODE> for off * @param state current state of the device returned from <code>readDevice()</code> * * @throws OneWireException when trying to set control data in automatic mode */ public void setControlData (boolean data, byte[] state) throws OneWireException { // check for invalid mode if (isModeAuto(state)) throw new OneWireException(address, "Trying to set control data when control is in automatic mode"); // set the bit Bit.arrayWriteBit((data ? 1 : 0), 6, STATUS_OFFSET, state); // indicate in bitmap the the state has changed Bit.arrayWriteBit(1, STATUS_OFFSET, BITMAP_OFFSET, state); } //-------- //-------- Private methods //-------- /** * Do a DS2409 specidific operation. * * @param command code to send * @param sendByte data byte to send * @param extra number of extra bytes to send * * @return block of the complete resulting transaction * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. This could be * caused by a physical interruption in the 1-Wire Network due to * shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. * @throws OneWireException on a communication or setup error with the 1-Wire * adapter */ private byte[] deviceOperation (byte command, byte sendByte, int extra) throws OneWireIOException, OneWireException { OneWireIOException exc = null; for(int attemptCounter=2; attemptCounter>0; attemptCounter--) { // Variables. byte[] raw_buf = new byte [extra + 2]; // build block. raw_buf [0] = ( byte ) command; raw_buf [1] = ( byte ) sendByte; for (int i = 2; i < raw_buf.length; i++) raw_buf [i] = ( byte ) 0xFF; // Select the device. if (adapter.select(address)) { // send the block adapter.dataBlock(raw_buf, 0, raw_buf.length); // verify if (command == READ_WRITE_STATUS_COMMAND) { if (( byte ) raw_buf [raw_buf.length - 1] != ( byte ) raw_buf [raw_buf.length - 2]) { if(exc==null) exc = new OneWireIOException(address, "OneWireContainer1F verify on command incorrect"); continue; } } else { if (( byte ) raw_buf [raw_buf.length - 1] != ( byte ) command) { if(exc==null) exc = new OneWireIOException(address, "OneWireContainer1F verify on command incorrect"); continue; } } return raw_buf; } else throw new OneWireIOException(address, "OneWireContainer1F failure - Device not found."); } // get here after a few attempts throw exc; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -