📄 onewirecontainer30.java
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999,2000 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */package com.dalsemi.onewire.container;import com.dalsemi.onewire.utils.CRC16;import com.dalsemi.onewire.*;import com.dalsemi.onewire.adapter.*;import java.util.Vector;import java.util.Enumeration;/** *<P>1-Wire® container that encapsulates the functionality of the 1-Wire * family type <B>30</B> (hex), Dallas Semiconductor part number: <B>DS2760, * High Precision Li-ion Battery Monitor</B>.</P> * * <H3>Features</H3> * <UL> * <LI>Li-ion safety circuit * <UL> * <LI>Overvoltage protection * <LI>Overcurrent/short circuit protection * <LI>Undervoltage protection * </UL> * <LI>Two sense resistor configurations * <UL> * <LI>Internal 25 mOhm sense resistor * <LI>External user-selectable sense resistor * </UL> * <LI>12-bit bi-directional current measurement * <LI>Current accumulation * <LI>Voltage measurement * <LI>Direct-to-digital temperature measurement * <LI>32 bytes of lockable EEPROM * <LI>16 bytes of general purpose SRAM * <LI>Low power consumption * <UL> * <LI>Active current: 80 µA max * <LI>Sleep current: 2 µA max * </UL> * </UL> * * <H3>Data sheet</H3> * * <A HREF="http://pdfserv.maxim-ic.com/arpdf/DS2760.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS2760.pdf</A> * * * * @version 0.00, 28 Aug 2000 * @author COlmstea * * Converted to use interfaces, general rework KLA */public class OneWireContainer30 extends OneWireContainer implements ADContainer, TemperatureContainer{ /** * Memory functions. */ private static final byte WRITE_DATA_COMMAND = ( byte ) 0x6C; private static final byte READ_DATA_COMMAND = ( byte ) 0x69; private static final byte COPY_DATA_COMMAND = ( byte ) 0x48; private static final byte RECALL_DATA_COMMAND = ( byte ) 0xB8; private static final byte LOCK_COMMAND = ( byte ) 0x6A; /** * Address of the Protection Register. Used to set/check flags with * <CODE>setFlag()/getFlag()</CODE>. */ public static final byte PROTECTION_REGISTER = 0; /** * Address of the Status Register. Used to set/check flags with * <CODE>setFlag()/getFlag()</CODE>. */ public static final byte STATUS_REGISTER = 1; /** * Address of the EEPROM Register. Used to set/check flags with * <CODE>setFlag()/getFlag()</CODE>. */ public static final byte EEPROM_REGISTER = 7; /** * Address of the Special Feature Register (SFR). Used to check flags with * <CODE>getFlag()</CODE>. */ public static final byte SPECIAL_FEATURE_REGISTER = 8; /** * PROTECTION REGISTER FLAG: When this flag is <CODE>true</CODE>, it * indicates that the battery pack has experienced an overvoltage * condition. * This flag must be reset! * Accessed with <CODE>getFlag()</CODE>. */ public static final byte OVERVOLTAGE_FLAG = ( byte ) 128; /** * PROTECTION REGISTER FLAG: When this flag is <CODE>true</CODE>, the * battery pack has experienced an undervoltage. * This flag must be reset! * Accessed with <CODE>getFlag()</CODE> */ public static final byte UNDERVOLTAGE_FLAG = 64; /** * PROTECTION REGISTER FLAG: When this flag is <CODE>true</CODE> the * battery has experienced a charge-direction overcurrent condition. * This flag must be reset! * Accessed with <CODE>getFlag()</CODE> */ public static final byte CHARGE_OVERCURRENT_FLAG = 32; /** * PROTECTION REGISTER FLAG: When this flag is <CODE>true</CODE> the * battery has experienced a discharge-direction overcurrent condition. * This flag must be <CODE>reset()</CODE>! * Accessed with <CODE>getFlag()</CODE> */ public static final byte DISCHARGE_OVERCURRENT_FLAG = 16; /** * PROTECTION REGISTER FLAG: Mirrors the !CC output pin. * Accessed with <CODE>getFlag()</CODE> */ public static final byte CC_PIN_STATE_FLAG = 8; /** * PROTECTION REGISTER FLAG: Mirrors the !DC output pin. * Accessed with <CODE>getFlag()</CODE> */ public static final byte DC_PIN_STATE_FLAG = 4; /** * PROTECTION REGISTER FLAG: Reseting this flag will disable charging * regardless of cell or pack conditions. * Accessed with <CODE>getFlag()/setFlag()</CODE>. */ public static final byte CHARGE_ENABLE_FLAG = 2; /** * PROTECTION REGISTER FLAG: Reseting this flag will disable discharging. * Accessed with <CODE>getFlag()/setFlag()</CODE>. */ public static final byte DISCHARGE_ENABLE_FLAG = 1; /** * STATUS REGISTER FLAG: Enables/disables the DS2760 to enter sleep mode * when the DQ line goes low for greater than 2 seconds. * Accessed with <CODE>getFlag()/setFlag()</CODE>. */ public static final byte SLEEP_MODE_ENABLE_FLAG = 32; /** * STATUS REGISTER FLAG: If set, the opcode for the Read Net Address command * will be set to 33h. If it is not set the opcode is set to 39h. * Accessed with <CODE>getFlag()/setFlag()</CODE>. */ public static final byte READ_NET_ADDRESS_OPCODE_FLAG = 16; /** * EEPROM REGISTER FLAG: This flag will be <CODE>true</CODE> if the Copy * Data Command is in progress. Data may be written to EEPROM when this * reads <CODE>false</CODE>. * Accessed with <CODE>getFlag()/setFlag()</CODE>. */ public static final byte EEPROM_COPY_FLAG = ( byte ) 128; /** * EEPROM REGISTER FLAG: When this flag is <CODE>true</CODE>, the Lock * Command is enabled. The lock command is used to make memory permanently * read only. * Accessed with <CODE>getFlag()/setFlag()</CODE>. */ public static final byte EEPROM_LOCK_ENABLE_FLAG = 64; /** * EEPROM REGISTER FLAG: When this flag is <CODE>true</CODE>, Block 1 * of the EEPROM (addresses 48-63) is read-only. * Accessed with <CODE>getFlag()</CODE>. */ public static final byte EEPROM_BLOCK_1_LOCK_FLAG = 2; /** * EEPROM REGISTER FLAG: When this flag is <CODE>true</CODE>, Block 0 * of the EEPROM (addresses 32-47) is read-only. * Accessed with <CODE>getFlag()</CODE>. */ public static final byte EEPROM_BLOCK_0_LOCK_FLAG = 1; /** * SPECIAL FEATURE REGISTER FLAG: Mirrors the state of the !PS pin. * Accessed with <CODE>getFlag()</CODE>. */ public static final byte PS_PIN_STATE_FLAG = ( byte ) 128; /** * SPECIAL FEATURE REGISTER FLAG: Mirrors/sets the state of the PIO pin. The * PIO pin can be used as an output; resetting this flag disables the PIO * output driver. * Accessed with <CODE>getFlag()/setFlag()</CODE>. */ public static final byte PIO_PIN_SENSE_AND_CONTROL_FLAG = 64; /** * Holds the value of the sensor external resistance. */ private double Rsens = .05; /** * When this is true, all calculations are assumed to be done in the part. */ private boolean internalResistor; /** * Default constructor */ public OneWireContainer30 () { super(); internalResistor = true; } /** * Creates a container with a provided adapter object * and the address of this 1-Wire device. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this 1-Wire device */ public OneWireContainer30 (DSPortAdapter sourceAdapter, byte[] newAddress) { super(sourceAdapter, newAddress); internalResistor = true; } /** * Creates a container with a provided adapter object * and the address of this 1-Wire device. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this 1-Wire device */ public OneWireContainer30 (DSPortAdapter sourceAdapter, long newAddress) { super(sourceAdapter, newAddress); internalResistor = true; } /** * Creates a container with a provided adapter object * and the address of this 1-Wire device. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this 1-Wire device */ public OneWireContainer30 (DSPortAdapter sourceAdapter, String newAddress) { super(sourceAdapter, newAddress); internalResistor = true; } /** * Returns the Dallas Semiconductor part number of this 1-Wire device * as a string. * * @return representation of the 1-Wire device name * */ public String getName () { return "DS2760"; } /** * Returns the alternate Dallas Semiconductor part number or name. * ie. Smart Battery Monitor * * @return representation of the alternate names for this device */ public String getAlternateNames () { return "1-Cell Li-Ion Battery Monitor"; } /** * Returns a short description of the function of this 1-Wire device type. * * @return representation of the function description */ public String getDescription () { return "The DS2760 is a data acquisition, information storage, and safety" + " protection device tailored for cost-sensitive battery pack applications." + " This low-power device integrates precise temperature, voltage, and" + " current measurement , nonvolatile data storage, and Li-Ion protection" + " into the small footprint of either a TSSOP packet or flip-chip."; } /** * Get an enumeration of memory bank instances that implement one or more * of the following interfaces: * {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, * {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank}, * and {@link com.dalsemi.onewire.container.OTPMemoryBank OTPMemoryBank}. * @return <CODE>Enumeration</CODE> of memory banks */ public Enumeration getMemoryBanks () { Vector bank_vector = new Vector(1); // EEPROM main bank MemoryBankEEPROMblock mn = new MemoryBankEEPROMblock(this); bank_vector.addElement(mn); return bank_vector.elements(); } /** * Sets the DS2760 to use its internal .025 ohm resistor for measurements. * This should only be enabled if there is NO external resistor physically * attached to the device. */ public synchronized void setResistorInternal () { internalResistor = true; } /** * Sets the DS2760 to use an external, user-selectable resistance. This * Resistance should be wired directly to the VSS (negative terminal of * the cell). * * @param Rsens resistance in ohms */ public synchronized void setResistorExternal (double Rsens) { internalResistor = false; this.Rsens = Rsens; } /** * Reads a register byte from the memory of the DS2760. Note that there * is no error checking as the DS2760 performs no CRC on the data. * <p> * Note: This function should only be used when reading the register * memory of the DS2760. The EEPROM blocks (addresses 32-64) should be * accessed with writeBlock/readBlock. * * @param memAddr the address to read (0-255) * * @return data read from memory * * @throws OneWireIOException Error reading data * @throws OneWireException Could not find part */ public byte readByte (int memAddr) throws OneWireIOException, OneWireException
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -