Changeset 785 for firmware/trunk/libraries/dipswitch/dipswitch.c
- Timestamp:
- 08/06/08 13:09:34 (5 months ago)
- Files:
-
- 1 modified
-
firmware/trunk/libraries/dipswitch/dipswitch.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
firmware/trunk/libraries/dipswitch/dipswitch.c
r775 r785 46 46 * The DIP Switch subsystem reads values in from the 8 position DIP Switch (0 - 255) on the Application Board. 47 47 Mask off the appropriate bits in the value returned from the DIP switch to determine whether a particular channel is on or off. 48 49 See the <a href="http://www.makingthings.com/documentation/tutorial/application-board-overview/user-interface"> 50 Application Board overview</a> for details. 48 51 * \ingroup Libraries 49 52 * @{ … … 54 57 @param state An integer specifying the state of the DIP Switch - 1 (on) or 0 (off). 55 58 @return Zero on success. 59 60 \b Example 61 \code 62 // enable the DIP switch 63 DipSwitch_SetActive(1); 64 \endcode 56 65 */ 57 66 int DipSwitch_SetActive( int state ) … … 80 89 Returns the active state of the DIP Switch. 81 90 @return The active state of the DIP Switch - 1 (active) or 0 (inactive). 91 92 \b Example 93 \code 94 if( DipSwitch_GetActive() ) 95 { 96 // DIP switch is active 97 } 98 else 99 { 100 // DIP switch is not active 101 } 102 \endcode 82 103 */ 83 104 int DipSwitch_GetActive( ) … … 89 110 Read the current configuration of the on-board DIP switch. 90 111 @return An integer from 0-255 indicating the current configuration of the DIP switch. 112 113 \b Example 114 \code 115 int dip_switch = DipSwitch_GetValue(); 116 // now dip_switch has a bitmask of all 8 channels of the DIP switch 117 \endcode 91 118 */ 92 119 int DipSwitch_GetValue( ) … … 120 147 /** 121 148 Read a single channel's value. 149 This is a convenience function that relies on DipSwitch_GetValue() 150 internally, but extracts the value for a given channel. 122 151 @param channel The channel (0-7) you'd like to read. 123 152 return true if the channel is on, false if it's off. 124 153 @see DipSwitch_GetValue( ) 154 155 \b Example 156 \code 157 if(DipSwitch_GetValueChannel(4) ) 158 { 159 // DIP switch channel 4 is on 160 } 161 else 162 { 163 // DIP switch channel 4 is off 164 } 165 // now dip_switch has a bitmask of all 8 channels of the DIP switch 166 \endcode 125 167 */ 126 168 bool DipSwitch_GetValueChannel( int channel ) … … 134 176 else 135 177 return ((val << channel) & 0x1); 136 }137 138 bool DipSwitch_GetAutoSend( bool init )139 {140 DipSwitch_SetActive( 1 );141 if( init )142 {143 int autosend;144 Eeprom_Read( EEPROM_DIPSWITCH_AUTOSEND, (uchar*)&autosend, 4 );145 DipSwitch->autosend = (autosend == 1 ) ? 1 : 0;146 }147 return DipSwitch->autosend;148 }149 150 void DipSwitch_SetAutoSend( int onoff )151 {152 DipSwitch_SetActive( 1 );153 if( DipSwitch->autosend != onoff )154 {155 DipSwitch->autosend = onoff;156 Eeprom_Write( EEPROM_DIPSWITCH_AUTOSEND, (uchar*)&onoff, 4 );157 }158 178 } 159 179 … … 256 276 #include "osc.h" 257 277 278 bool DipSwitch_GetAutoSend( bool init ) 279 { 280 DipSwitch_SetActive( 1 ); 281 if( init ) 282 { 283 int autosend; 284 Eeprom_Read( EEPROM_DIPSWITCH_AUTOSEND, (uchar*)&autosend, 4 ); 285 DipSwitch->autosend = (autosend == 1 ) ? 1 : 0; 286 } 287 return DipSwitch->autosend; 288 } 289 290 void DipSwitch_SetAutoSend( int onoff ) 291 { 292 DipSwitch_SetActive( 1 ); 293 if( DipSwitch->autosend != onoff ) 294 { 295 DipSwitch->autosend = onoff; 296 Eeprom_Write( EEPROM_DIPSWITCH_AUTOSEND, (uchar*)&onoff, 4 ); 297 } 298 } 299 258 300 static char* DipSwitchOsc_Name = "dipswitch"; 259 301 static char* DipSwitchOsc_PropertyNames[] = { "active", "value", "autosend", 0 }; // must have a trailing 0
