Charles Young's development fork. Going forward I only want to push mature code to main repository.

Dependencies:   mbed

Fork of GEO_COUNTER_L432KC by Geo Electronics "Geo Counter"

Revision:
22:2616a57327d8
Parent:
21:5640ebc362a0
--- a/main.cpp	Tue Sep 04 17:40:29 2018 -0700
+++ b/main.cpp	Wed Sep 05 01:03:30 2018 +0000
@@ -3,6 +3,7 @@
 //
 //  Latest review: August 27, 2018 - Walter Trovo
 //
+//  Sep  4, 2018: Charles Young: Created RotarySwitch class to manage mode selection
 //  Feb 14, 2018: initial release aimed to test the counters, the serial port
 //                the PWM output and the MAX7219 operation.
 //  Feb 15, 2018: Removed MAX7219 libray (replaced with custom routine). 
@@ -11,16 +12,17 @@
 
 
 // this block includes key libraries
-#include "mbed.h"       // global Mbed library (always needed)
 #include <string>       // strings management
+#include "RotarySwitch.hpp"
 
-#include <RotarySwitch.hpp>
+// Everything associated with the rotary switch and the associated LEDs
+// is hidden in this class.
 RotarySwitch ModeSwitch;
 
 // definitions of fixed parameters
 
 #define DEC_MODE    0x09FF  // BCD decoding on all digits
-#define BRIGHTNESS  0x0A0F  // max brightness
+#define BRIGHTNESS  0x0A00  // brightness in 16 steps - min to max is 0x0A00 to  0x0A0F
 #define SCAN_LIM    0x0B07  // use all 8 digits  
 #define TURN_ON     0x0C01  // no shutdown (operating)
 #define SHUTDOWN    0x0C00  // shutdown
@@ -31,22 +33,6 @@
 #define TGATE   10       // gate time (currently fixed for testing purpose)
 #define MAX_VAL 999999  // Max value managed by the 6-digits display
 
-// definitions of the input/outputs (pins)
-DigitalOut  AUX   (D2);    // AUX control for GPS module
-InterruptIn TRIG1 (D3);    // Counter 1 trigger
-InterruptIn TRIG2 (D6);    // Counter 2 trigger
-PwmOut      PWM   (D10);   // PWM output
-DigitalOut  BUZZ  (D13);   // Buzzer
-
-AnalogIn    AIN0  (A0);    // ADC input 0 (High Voltage)
-AnalogIn    AIN1  (A1);    // ADC input 1 (aux)
-DigitalOut  CS2   (A2);    // 74HC595 RCLK (pin 12)
-DigitalOut  CS1   (A3);    // MAX7219 CS (pin 12)
-DigitalOut  SCK   (A4);    // 74HC595 SRCLK (pin 11) & MAX7219 SCK (pin 13)
-AnalogIn    KEYB  (A5);    // Keyboard input (SW2 & SW3) 
-DigitalOut  MOSI  (A6);    // 74HC595 SER (pin 14) & MAX7219 DIN (pin 1)
-DigitalIn   UN    (A7);    // Unused (in V1 PCB A5 and A7 must be connected)
-
 // LED on processor board
 DigitalOut led1(LED1);
 
@@ -105,7 +91,7 @@
     // RTC is supposed to be loose time at power down (no backup battery)
     // An initialization is performed anyway 
     set_time(0); // Set time
- 
+    
     PWM.period_ms(3);    // set the PWM period
     PWM.write(0.8);      // set the PWM duty-cycle
     
@@ -142,11 +128,14 @@
    seconds = time(NULL);   // get current time 
    strftime(Text, 50, "%H:%M:%S", localtime(&seconds));
    PC.printf(" RTC: %s, CNT1: %7d CNT2: %7d",Text, Count1, Count2);
-   // PC.printf(" wheel %d %d", WheelCurrent, QEPB.read());
+   //PC.printf(" wheel %d %d", WheelCurrent, QEPB.read());
 }
 
 void UpdateOutput()   
 {
+    // This must be called periodically to update the LEDs
+    ModeSwitch.UpdateOutput();
+      
    if(Stopped)
    {    
       // disable interrupts on TRIG1 and TRIG2
@@ -187,7 +176,10 @@
 }
 
 void UpdateInput()   
-{               
+{
+   // This must be called periodically to monitor switch input
+   ModeSwitch.UpdateInput();
+        
    ADC_val = KEYB.read();  // read voltage from keyboard
    if (   (ADC_val<0.1)    // START/STOP pushbutton pressed
        && (!StartStopPressed))
@@ -203,7 +195,6 @@
       Count1 = 0; // clear counters     
       Count2 = 0;              
    }
-    
    logToPC();
    return;
 }
@@ -217,7 +208,6 @@
     return; 
 }
 
-
 //---------------------------------------------------------------------------
 // Increment CNT1 every time a rising edge is detected on TRIG2 (interrupt)
 
@@ -239,7 +229,6 @@
     return; 
 }
 
-
 //---------------------------------------------------------------------------
 // Initialize the MAX7219
 
@@ -249,7 +238,7 @@
     uint16_t mask;
     uint16_t data_to_send[6] = {SHUTDOWN, TURN_ON, DEC_MODE, BRIGHTNESS, SCAN_LIM, TEST};
              //{SHUTDOWN, TURN_ON, DEC_MODE, BRIGHTNESS, SCAN_LIM, TEST};
-    for(i = 0; i <6; i++)
+    for(i = 0; i < sizeof(data_to_send)/sizeof(uint16_t); i++)
     {
         CS1 = 0;
       
@@ -396,4 +385,3 @@
 //==============================================================================
 
 
-