[Embedlets-dev] [ANN] House Monitor LightSensor for TINI using a DS2406
Status: Alpha
Brought to you by:
tkosan
|
From: Kelly S. <be...@ea...> - 2003-07-09 11:54:46
|
All - I know that some of you are involved in home automation applications for TINI/1-Wire, and I thought I would share this... Applications: detect indoor lighting conditions, and the determination can be made by the user to turn these lights on or off, based on the return status of LightSensor. Also, this can be used for a sunrise/sunset sensor. David MacMahon- Yes, you can also use this also for your next release of TiniHttpServer. 8-) Ted Kosan - This might fit in well for your Global Light Blinker... Best regards, Kelly Smith P.S. - Cut'n'paste from here... /** * Title: House Monitor<p> * Description: TINI project to monitor door, window, door-bell * sensors via 1-wire network.<p> * LightSensor using a DS2406 (Sensor 12)<p> * Copyright: Copyright (c) Bob Hinton and Kelly Smith<p> * Company: RH Associates<p> * @author Bob Hinton and Kelly Smith * @version 1.0 * * Created a new class to sense lighting conditions. Returns "light is ON" or "light is OFF" * * LightSensor uses a standalone garden/path lighting from Home Depot - $8.97 for a one * lamp, and includes two "AA" NiCad batteries for charging via a solar cell during the * daytime for each LED "Lamp Post". Brand: Hampton Bay, Model #: 79689. * * Ref: http://www.homedepot.com/prel80/HDUS/EN_US/diy_main/pg_diy.jsp?CNTTYPE=PROD_ META&CNTKEY=Products_2%2fLighting+%26+Fans&BV_SessionID=@@@@1253899723.10577 49258@@@@&BV_EngineID=ccdcadcikkhddkjcgelceffdfgidgjm.0&MID=9876 * * I "dead-bugged" a DS2406 TO-92, across the visible yellow LED (LED cathode to ground and * DS2406) pin-1, with LED anode and DS2406 pin-3 is PIO-A; DS2406 Data pin-2 is 1-Wire). * The solar cell is sufficiently sensitive that it can detect indoor lighting conditions, * and the determination can be made by the user to turn these lights on or off, based on * the return status of LightSensor. Also, this can be used for a sunrise/sunset sensor. */ package housemonitor; import com.dalsemi.onewire.adapter.*; public class LightSensor extends Sensor12 { static final int UNKNOWN_STATE = 0; static final int OPEN_STATE = 1; static final int CLOSED_STATE = 2; private int old_state = UNKNOWN_STATE; private int current_state = UNKNOWN_STATE; // If there is a long distance from the DS2406 to the sensor // then we can get spurious activity events. So include the // facility to ignore any where the state doesn't change private boolean ignore_spurious_alarms = false;; public LightSensor(DSPortAdapter adapter, String address,String description) { super(adapter,address,description); } public LightSensor() { super(); } public String getDescription() { return super.description + " light"; } public void configure_device() throws Exception // Specific configuration for this type of device { EnableActivityAlarm(true); setIgnoreSpuriousAlarms(true); } public String getStateAsString() { try { clearActivityAndRead(); // re-read in case of spurious alarms } catch(Exception e) { return " Exception - " + e.getMessage(); } if(alarm_valid()) return(IsOpen() ? " is ON" : " is OFF"); return null; } public boolean IsOpen() // if current_state is valid - indicating a previous call to // alarm_valid - then return that, else return the value read // from the device { int output; if(current_state != UNKNOWN_STATE) output = (current_state == OPEN_STATE ? CHAN_TRUE : CHAN_FALSE); else output = (getLevel() ? CHAN_TRUE : CHAN_FALSE); setOutputState(output); return output == CHAN_TRUE ? true : false; } public boolean alarm_valid() { if(ignore_spurious_alarms) { current_state = getLevel() ? OPEN_STATE : CLOSED_STATE; if(current_state != old_state) return true; else return false; } return true; } public void clearActivityAndRead() throws com.dalsemi.onewire.OneWireException { super.clearActivityAndRead(); if(ignore_spurious_alarms) { old_state = current_state; current_state = UNKNOWN_STATE; } } public void setIgnoreSpuriousAlarms(boolean value) { ignore_spurious_alarms = value; } public void enableAlarm(boolean enable) throws com.dalsemi.onewire.OneWireException { EnableActivityAlarm(enable); } public boolean readIfThis(long address_long) throws com.dalsemi.onewire.OneWireException { return super.readIfThis(address_long); } } |