Read up to 8 debounced switches from serial port

Dependencies:   mbed

Committer:
jm
Date:
Sat Feb 12 16:46:49 2011 +0000
Revision:
0:f3a5f6fe1c03
jmSwitch Command Line Interface Module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jm 0:f3a5f6fe1c03 1 /*************************************************************************
jm 0:f3a5f6fe1c03 2 * @file jmSwitch.h
jm 0:f3a5f6fe1c03 3 * @brief Command Line Interface Module for reading switches
jm 0:f3a5f6fe1c03 4 * Up to 8 switches can be defined on any digital mbed Pin.
jm 0:f3a5f6fe1c03 5 * Provide debounce and edge detection
jm 0:f3a5f6fe1c03 6 * @version 1.0
jm 0:f3a5f6fe1c03 7 * @date Feb 2, 2011
jm 0:f3a5f6fe1c03 8
jm 0:f3a5f6fe1c03 9 Command Line Interface
jm 0:f3a5f6fe1c03 10 Format: command name (arg info)min..max values [optional argument]
jm 0:f3a5f6fe1c03 11 swRead (Switch id)0..3 Return Message: GPPS0 id pin debounce state
jm 0:f3a5f6fe1c03 12 swInit (Switch id)0..7 (Pin number)0..432 (debounce interval)1..255
jm 0:f3a5f6fe1c03 13 Initialize a Limit Switch Process and return Message: GPPS0 id pin debounce state
jm 0:f3a5f6fe1c03 14 GPPS0 Return 8 Message: GPPS0 id pin debounce state
jm 0:f3a5f6fe1c03 15
jm 0:f3a5f6fe1c03 16 Module Events
jm 0:f3a5f6fe1c03 17 On closing of switch, Return Message: GPPS0 id pin debounce state
jm 0:f3a5f6fe1c03 18 On Opening of switch, Return Message: GPPS0 id pin debounce state
jm 0:f3a5f6fe1c03 19 */
jm 0:f3a5f6fe1c03 20
jm 0:f3a5f6fe1c03 21 #ifndef jmSwitchDef
jm 0:f3a5f6fe1c03 22 #define jmSwitchDef 1
jm 0:f3a5f6fe1c03 23 #include "stdint.h"
jm 0:f3a5f6fe1c03 24 #include "LPC17xx.h"
jm 0:f3a5f6fe1c03 25
jm 0:f3a5f6fe1c03 26 #define switchQty 8 // max switch qty
jm 0:f3a5f6fe1c03 27
jm 0:f3a5f6fe1c03 28 // Module Data Structure
jm 0:f3a5f6fe1c03 29 extern struct StructSwitch{
jm 0:f3a5f6fe1c03 30 uint16_t pin;
jm 0:f3a5f6fe1c03 31 uint8_t debounce;
jm 0:f3a5f6fe1c03 32 uint8_t state;
jm 0:f3a5f6fe1c03 33 uint8_t eggTimer;
jm 0:f3a5f6fe1c03 34 uint32_t bitValue;
jm 0:f3a5f6fe1c03 35 LPC_GPIO_TypeDef *port;
jm 0:f3a5f6fe1c03 36 }sSwitch[switchQty];
jm 0:f3a5f6fe1c03 37 #endif
jm 0:f3a5f6fe1c03 38
jm 0:f3a5f6fe1c03 39 // Module Prototypes
jm 0:f3a5f6fe1c03 40 void SwitchEdgeDetect(void);
jm 0:f3a5f6fe1c03 41 void cli_SwitchInit(void);
jm 0:f3a5f6fe1c03 42 void cli_SwitchRead(void);
jm 0:f3a5f6fe1c03 43 void cli_GPPS0();
jm 0:f3a5f6fe1c03 44 void rGPPS0(unsigned int id);
jm 0:f3a5f6fe1c03 45 void SwitchModuleReset(void);
jm 0:f3a5f6fe1c03 46
jm 0:f3a5f6fe1c03 47 //-------------------------- CLIG PLUGS --------------------
jm 0:f3a5f6fe1c03 48 // CLIG-INCLUDE
jm 0:f3a5f6fe1c03 49 /*
jm 0:f3a5f6fe1c03 50 #include "jmSwitch.h"
jm 0:f3a5f6fe1c03 51
jm 0:f3a5f6fe1c03 52 */
jm 0:f3a5f6fe1c03 53
jm 0:f3a5f6fe1c03 54 // CLIG-INIT
jm 0:f3a5f6fe1c03 55 /*
jm 0:f3a5f6fe1c03 56 SwitchModuleReset();
jm 0:f3a5f6fe1c03 57 */
jm 0:f3a5f6fe1c03 58
jm 0:f3a5f6fe1c03 59 // CLIG-TIMER
jm 0:f3a5f6fe1c03 60 /*
jm 0:f3a5f6fe1c03 61 // Module jmSwitch
jm 0:f3a5f6fe1c03 62 for(i=0;i<switchQty;i++)if(sSwitch[i].eggTimer>0)sSwitch[i].eggTimer--;
jm 0:f3a5f6fe1c03 63 */
jm 0:f3a5f6fe1c03 64
jm 0:f3a5f6fe1c03 65 // CLIG-CMD
jm 0:f3a5f6fe1c03 66 /*
jm 0:f3a5f6fe1c03 67 swRead cli_SwitchRead();
jm 0:f3a5f6fe1c03 68 swInit cli_SwitchInit();
jm 0:f3a5f6fe1c03 69 GPPS0 cli_GPPS0();
jm 0:f3a5f6fe1c03 70 */
jm 0:f3a5f6fe1c03 71
jm 0:f3a5f6fe1c03 72 // CLIG-SM
jm 0:f3a5f6fe1c03 73 /*
jm 0:f3a5f6fe1c03 74 SwitchEdgeDetect();
jm 0:f3a5f6fe1c03 75 */
jm 0:f3a5f6fe1c03 76
jm 0:f3a5f6fe1c03 77 //-------------------------- END CLIG PLUGS --------------------