001package jmri.jmrix.powerline.insteon2412s; 002 003import jmri.jmrix.powerline.SerialTrafficController; 004import jmri.jmrix.powerline.X10Sequence; 005import org.slf4j.Logger; 006import org.slf4j.LoggerFactory; 007 008/** 009 * Implementation of the Light Object for X10 receivers on Insteon 2412S 010 * interfaces. 011 * <p> 012 * Uses X10 dimming commands to set intensity unless the value is 0.0 or 1.0, in 013 * which case it uses on/off commands only. 014 * <p> 015 * Since the dim/bright step of the hardware is unknown then the Light object is 016 * first created, the first time the intensity (not state) is set to other than 017 * 0.0 or 1.0, the output is run to it's maximum dim or bright step so that we 018 * know the count is right. 019 * <p> 020 * Keeps track of the controller's "dim count", and if not certain forces it to 021 * zero to be sure. 022 * <p> 023 * 024 * 025 * @author Dave Duchamp Copyright (C) 2004 026 * @author Bob Jacobsen Copyright (C) 2006, 2007, 2008, 2009, 2010 027 * @author Ken Cameron Copyright (C) 2009, 2010 Converted to multiple connection 028 * @author kcameron Copyright (C) 2011 029 */ 030public class SpecificX10Light extends jmri.jmrix.powerline.SerialX10Light { 031 032 /** 033 * Create a Light object, with only system name. 034 * <p> 035 * 'systemName' was previously validated in SerialLightManager 036 * 037 * @param systemName text for systemName of light 038 * @param tc tc for connection 039 */ 040 public SpecificX10Light(String systemName, SerialTrafficController tc) { 041 super(systemName, tc); 042 this.tc = tc; 043 // fixed number of steps for X10 Insteon 044 maxDimStep = 22; 045 } 046 047 /** 048 * Create a Light object, with both system and user names. 049 * <p> 050 * 'systemName' was previously validated in SerialLightManager 051 * 052 * @param systemName text for systemName of light 053 * @param tc tc for connection 054 * @param userName text for userName of light 055 */ 056 public SpecificX10Light(String systemName, SerialTrafficController tc, String userName) { 057 super(systemName, tc, userName); 058 this.tc = tc; 059 maxDimStep = 22; 060 } 061 062 SerialTrafficController tc = null; 063 064 // System-dependent instance variables 065 /** 066 * Send a Dim/Bright commands to the X10 hardware to reach a specific 067 * intensity. Acts immediately, and changes no general state. 068 * <p> 069 * This sends "Extended Cmd Dim" commands. 070 */ 071 @Override 072 protected void sendIntensity(double intensity) { 073 if (log.isDebugEnabled()) { 074 log.debug("sendIntensity({}) lastOutputStep: {} maxDimStep: {}", intensity, lastOutputStep, maxDimStep); 075 } 076 077 // if we don't know the dim count, force it to a value. 078// initIntensity(intensity); 079 // find the new correct dim count 080 int newStep = (int) Math.round(intensity * maxDimStep); // maxDimStep is full on, 0 is full off, etc 081 082 // check for errors 083 if ((newStep < 0) || (newStep > maxDimStep)) { 084 log.error("newStep wrong: {} intensity: {}", newStep, intensity); 085 } 086 087 if (newStep == lastOutputStep) { 088 // nothing to do! 089 if (log.isDebugEnabled()) { 090 log.debug("intensity {} within current step, return", intensity); 091 } 092 return; 093 094 } 095 096 // create output sequence of address, then function 097 X10Sequence out = new X10Sequence(); 098 out.addExtData(housecode, devicecode, X10Sequence.EXTCMD_DIM, newStep); 099 // send 100 tc.sendX10Sequence(out, null); 101 lastOutputStep = newStep; 102 103 if (log.isDebugEnabled()) { 104 log.debug("sendIntensity({}) house {} device {} newStep: {}", intensity, X10Sequence.houseValueToText(housecode), devicecode, newStep); 105 } 106 } 107 108 private final static Logger log = LoggerFactory.getLogger(SpecificX10Light.class); 109} 110 111