Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_compTwinSwitch.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_compTwinSwitch.cpp  -  description
00003                              -------------------
00004     begin                : Sat Jan 4 2003
00005     copyright            : (C) 2003 by Harald Roelle
00006     email                : roelle@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #include "LOW_compTwinSwitch.h"
00020 #include "LOW_netSegment.h"
00021 
00022 
00023 
00024 //=====================================================================================
00025 //
00026 // constructors
00027 //
00028 
00029 LOW_compTwinSwitch::LOW_compTwinSwitch( const LOW_devDS2406 &inPIODevice, actionReceiver &inActionRcv,
00030                                         const bool inDetectShortClicks) :
00031   pioDevice( inPIODevice),
00032   actionRcv( inActionRcv),
00033   detectShortClicks( inDetectShortClicks)
00034 {
00035   if ( !pioDevice.getNetSegment().getHasExternalPower() )
00036     throw compTwinSwitch_error( "Network segment must supply power.", __FILE__, __LINE__);
00037 
00038   if ( ! pioDevice.getHasPioB() )
00039     switchStatesVec = std::vector<bool>( 2, false);
00040   else
00041     switchStatesVec = std::vector<bool>( 1, false);
00042     
00043   LOW_devDS2406::cmd_ChannelAccess::channelInfo_t  dummy;
00044   resetLatches( dummy);
00045 
00046   setAlarmCondition();
00047 }
00048 
00049 
00050 LOW_compTwinSwitch::~LOW_compTwinSwitch()
00051 {
00052 }
00053 
00054 
00055 
00056 //=====================================================================================
00057 //
00058 // public methods
00059 //
00060 
00061 void LOW_compTwinSwitch::handleAlarm()
00062 {
00063   LOW_devDS2406::cmd_ChannelAccess::channelInfo_t  chInfoRead, chInfoReset;
00064 
00065   // two steps needed here, otherwise latch status cannot be read
00066   readStatus( chInfoRead);
00067   resetLatches( chInfoReset);
00068   
00069   // switch A
00070   if ( chInfoRead.activityLatch_pioA )
00071     // using current status after latch reset (and not the one of read status)
00072     // enables us to detect a button release during latch reset
00073     doSwitchAction( 0, chInfoReset.sensedLevel_pioA);
00074 
00075   // switch B if present
00076   if ( pioDevice.getHasPioB() && chInfoRead.activityLatch_pioB )
00077     // using current status after latch reset (and not the one of read status)
00078     // enables us to detect a button release during latch reset
00079     doSwitchAction( 1, chInfoReset.sensedLevel_pioB);
00080 }
00081 
00082 
00083 void LOW_compTwinSwitch::alarmPollLoop()
00084 {
00085   while( ! pioDevice.verifyDevice( true) );
00086 }
00087 
00088 
00089 bool LOW_compTwinSwitch::getDetectShortClicks()
00090 {
00091   return detectShortClicks;
00092 }
00093 
00094 const LOW_devDS2406& LOW_compTwinSwitch::getPioDevice() const
00095 {
00096   return pioDevice;
00097 }
00098 
00099 
00100 
00101 //=====================================================================================
00102 //
00103 // private methods
00104 //
00105 
00106 void LOW_compTwinSwitch::setAlarmCondition()
00107 {
00108   pioDevice.setSearchCondition( LOW_devDS2406::chanBothSelect, LOW_devDS2406::latchSelect,
00109                                 LOW_devDS2406::activeHigh,
00110                                 LOW_devDS2406::pioTransistorOff, LOW_devDS2406::pioTransistorOff);
00111 }
00112 
00113 
00114 void LOW_compTwinSwitch::readStatus( LOW_devDS2406::cmd_ChannelAccess::channelInfo_t &outChannelInfo)
00115 {
00116   LOW_devDS2406::cmd_ChannelAccess readAccess =
00117     LOW_devDS2406::cmd_ChannelAccess( pioDevice,
00118                                       LOW_devDS2406::cmd_ChannelAccess::CRC_disable,
00119                                       LOW_devDS2406::chanBothSelect,
00120                                       LOW_devDS2406::cmd_ChannelAccess::asyncInterleaveMode,
00121                                       LOW_devDS2406::cmd_ChannelAccess::noToggleMode,
00122                                       LOW_devDS2406::cmd_ChannelAccess::readMode,
00123                                       LOW_devDS2406::cmd_ChannelAccess::noResetLatches);
00124   outChannelInfo = readAccess.getChannelInfo();
00125 }
00126 
00127 
00128 void LOW_compTwinSwitch::resetLatches( LOW_devDS2406::cmd_ChannelAccess::channelInfo_t &outChannelInfo)
00129 {
00130   LOW_devDS2406::cmd_ChannelAccess clearLatchAccess  =
00131     LOW_devDS2406::cmd_ChannelAccess( pioDevice,
00132                                       LOW_devDS2406::cmd_ChannelAccess::CRC_disable,
00133                                       LOW_devDS2406::chanBothSelect,
00134                                       LOW_devDS2406::cmd_ChannelAccess::asyncInterleaveMode,
00135                                       LOW_devDS2406::cmd_ChannelAccess::noToggleMode,
00136                                       LOW_devDS2406::cmd_ChannelAccess::readMode,
00137                                       LOW_devDS2406::cmd_ChannelAccess::resetLatches);
00138   outChannelInfo = clearLatchAccess.getChannelInfo();
00139 }
00140 
00141 
00142 /*
00143 old logical state | current level | detect short clicks H called procs | new state
00144 ==================+===============+=====================H==============+==========
00145  0                | 0             | 0                   H on, off      | 0
00146 ------------------+---------------+---------------------H--------------+----------
00147  0                | 0             | 1                   H shortClick   | 0
00148 ------------------+---------------+---------------------H--------------+----------
00149  0                | 1             | 0                   H              |
00150 ------------------+---------------+---------------------H on           | 1
00151  0                | 1             | 1                   H              |
00152 ------------------+---------------+---------------------H--------------+----------
00153  1                | 0             | 0                   H              |
00154 ------------------+---------------+---------------------H off          | 0
00155  1                | 0             | 1                   H              |
00156 ------------------+---------------+---------------------H--------------+----------
00157  1                | 1             | 0                   H              |
00158 ------------------+---------------+---------------------H off, on      | 1
00159  1                | 1             | 1                   H              |
00160 ------------------+---------------+---------------------H--------------+----------
00161 */
00162 void LOW_compTwinSwitch::doSwitchAction( const unsigned int inSwitchNum, const bool inSensedLevel)
00163 {
00164   bool oldLogState = switchStatesVec[inSwitchNum];
00165 
00166   if ( !oldLogState && !inSensedLevel && !detectShortClicks ) {
00167     switchStatesVec[inSwitchNum] = false;
00168     actionRcv.switchAction( this, inSwitchNum, true);
00169     actionRcv.switchAction( this, inSwitchNum, false);
00170   }
00171 
00172   if ( !oldLogState && !inSensedLevel &&  detectShortClicks ) {
00173     switchStatesVec[inSwitchNum] = false;
00174     actionRcv.shortSwitchAction( this, inSwitchNum);
00175   }
00176 
00177   if ( !oldLogState &&  inSensedLevel ) {
00178     switchStatesVec[inSwitchNum] = true;
00179     actionRcv.switchAction( this, inSwitchNum, true);
00180   }
00181 
00182   if (  oldLogState && !inSensedLevel ) {
00183     switchStatesVec[inSwitchNum] = false;
00184     actionRcv.switchAction( this, inSwitchNum, false);
00185   }
00186 
00187   if (  oldLogState &&  inSensedLevel ) {
00188     switchStatesVec[inSwitchNum] = true;
00189     actionRcv.switchAction( this, inSwitchNum, false);
00190     actionRcv.switchAction( this, inSwitchNum, true);
00191   }
00192 }
00193 
00194 
00195 
00196 //=====================================================================================
00197 //
00198 // CLASS: actionReceiver
00199 //
00200 
00201 LOW_compTwinSwitch::actionReceiver::actionReceiver()
00202 {
00203 }

Generated on Tue Feb 3 11:30:24 2004 for OneWireLibrary++ by doxygen 1.3.2