Merck / Mbed OS SmartCap_OS5

Dependencies:   nRF51822

Revision:
2:def2c045c43a
Parent:
1:b08ee63a2822
Child:
4:1bfa16834dd4
diff -r b08ee63a2822 -r def2c045c43a main.h
--- a/main.h	Fri Sep 02 19:02:26 2016 +0000
+++ b/main.h	Tue Dec 20 14:48:43 2016 +0000
@@ -3,22 +3,58 @@
 #define MAIN_H
 
 
-#define UART_DEBUGGING 0 // put a '1' here if you are debugging on the BLE UART, otherwise make it 0. Turns on: shows records being added to log, will not allow a ble connection to timeout
+#define UART_DEBUGGING 1 // put a '1' here if you are debugging on the BLE UART, otherwise make it 0. Turns on: shows records being added to log, will not allow a ble connection to timeout
 
-#define FW_VERSION  000 //  major revisions will be 1xx, 2xx, etc.
+#define FW_VERSION  001 //  major revisions will be 1xx, 2xx, etc.
 
 #define VDD_DELAY   3 // seconds to keep vdd on after PRESS is released.
 
-// Digital I/O lines
-#define PRESS           p3      // Will be shorted to battery terminal when pressed.  Need internal pull-up or pull-down
-#define SOUND_ANALOG    p1      // Analog signal from opto sensor 
-#define VDD_ENABLE      p24     // Analog voltage on when hi
-#define TP              p2      // Test Point
+#define ADC_FREQ        5000   // ADC Sample Frequency in Hz
+#define TICKS_PER_MS    (uint32_t)ADC_FREQ/1000
+
+#define ADC_2o5V    853     // =2.5/3.0*1023
+#define ADC_1o25V   (ADC_2o5V/2)
+#define ADC_MID     (ADC_1o25V)
 
-// ADC defines
-//#define ADC_CHAN_BATTERY    0 /* no I/O pin, done internally */
-//#define ADC_CHAN_SOUND      2 /* p1 or Analog2 */
+//*************** Parameters for recognizing a press  *************************
+// Pulse size is in % of the positive range.
+// for the following pulse sizes, 
+//    0=0% (1.25V) pulse rise
+//    100=100% (2.5V) pulse rise which is the max range.
+#define PULSE_BIG         50
+#define PULSE_MED         30
+#define PULSE_THRESHOLD   10
+
+#define ADC_PULSE_BIG           (ADC_MID + (PULSE_BIG*ADC_MID)/100)
+#define ADC_PULSE_MED           (ADC_MID + (PULSE_MED*ADC_MID)/100)
+#define ADC_PULSE_THRESHOLD     (ADC_MID + (PULSE_THRESHOLD*ADC_MID)/100)
 
 
+// <--T1--> |  <--T2-->   | <-T3-> |  <------T4------>   |  
+//<PRESS>                         <RELEASE>
+//            /\
+//           /  \                        /\
+//----------/    \    /-----------------/  \  /----------------------
+//                \  /                      \/
+//                 \/
+
+// the following times are in ms
+// T_PRESS refers to the pulses produced by pressing
+// T_RELEASE refers to the pulses produced by releasing
+#define T_STARTUP       20    // (T1) time after powerup to ignore the input
+#define T_PRESS_MAX     2500 // (T2_MAX) maximum time to look for PRESS pulses 
+#define T_DELAY         180  // (T3) after a press is recognized, delay this time before looking for release pulses
+#define T_RELEASE_MAX   4500 // (T4_MAX) maximum time to look for release pulses
+#define T_RELEASE_UP    500  // (T7) Max time after the button is released that we look for sound.  This can preempt T4_MAX
+#define T_LEDON         2000 // (T5) time led comes on if a valid press/release was detected
+#define T_SHUTDOWN      250  // (T6) In done state, time to delay after switch is released before powering down
+
+// number of pulses needed to validate a PRESS or RELEASE
+#define NUM_PRESS_BIG   1
+#define NUM_PRESS_MED   3
+#define NUM_RELEASE_BIG 1
+#define NUM_RELEASE_MED 3
+
+//******************************************************************************
 
 #endif // #ifndef MAIN_H
\ No newline at end of file