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:
25:0161bf1adc81
Parent:
24:db7494389c03
Child:
28:c81d00ec28a3
--- a/main.cpp	Wed Sep 05 16:05:07 2018 +0000
+++ b/main.cpp	Wed Sep 05 10:15:52 2018 -0700
@@ -3,6 +3,7 @@
 //
 //  Latest review: August 27, 2018 - Walter Trovo
 //
+//  Sep  5, 2018: Charles Young: Created LED7segDisplay class
 //  Sep  5, 2018: Charles Young: Still developing mode selection.  LEDs turn off
 //                when not in mode selection.  Pressing once enters mode selection.
 //                Pressing again enters submode.  Temporarily the rotary switch
@@ -18,27 +19,16 @@
 // this block includes key libraries
 #include <string>       // strings management
 #include "RotarySwitch.hpp"
+#include "LED7segDisplay.hpp"
 
 // Everything associated with the rotary switch and the associated LEDs
 // is hidden in this class.
 RotarySwitch ModeSwitch;
+LED7segDisplay DigitsDisplay;
 
 // definitions of fixed parameters
 
-#define DEC_MODE    0x09FF  // BCD decoding on all digits
-#define SCAN_LIM    0x0B07  // use all 8 digits  
-#define TURN_ON     0x0C01  // no shutdown (operating)
-#define SHUTDOWN    0x0C00  // shutdown
-#define TEST        0x0F00  // no test
-
-#define DT      1      // delay time in us for SPI emulation
-
 #define TGATE   10       // gate time (currently fixed for testing purpose)
-#define MAX_VAL 999999  // Max value managed by the 6-digits display
-
-#define BRIGHTNESS_MIN  0x0A00  // brightness in 16 steps - min to max is 0x0A00 to  0x0A0F
-#define BRIGHTNESS_MAX  0x0A0F  // brightness in 16 steps - min to max is 0x0A00 to  0x0A0F
-uint16_t brightness = BRIGHTNESS_MAX;
 
 // LED on processor board
 DigitalOut led1(LED1);
@@ -52,8 +42,6 @@
 Serial  GPS(D1, D0);             // Serial port for GPS module
 
 // Global variables
-uint8_t     Disp_Digit[8]; // used to manage 8-digits through MAX7219
-uint16_t    Stream;        // used to stream out serial data to MAX7219
 time_t      seconds;       // Real-Time Clock (RTC) timestamp
 unsigned int value = 0;    // displayed value on the 6-digits of the display
 uint8_t     gate = TGATE;          // displayed value on the 2-digits display
@@ -71,11 +59,6 @@
 void Count1_up(void);  // called every time an edge is detected on TRIG1 pin
 void Count2_up(void); // called every time an edge is detected on TRIG2 pin
 void Beep(void);    // used to generate a short beep (buzzer)
-void Display_init(void);    // initialize MAX7219
-void Display_6D_write(uint8_t);    // write to MAX7219 (Main 6-digits display)
-void Display_2D_write(unsigned short);    // write to MAX7219 (Gate 2-digits display)
-void sendDataToDisplay(uint16_t data_to_send);
-void Display_brightness(uint16_t brightness);
 
 //==============================================================================
 //==============================================================================
@@ -94,9 +77,8 @@
     CS1 = 1;    // presets CS of MAX7219
     CS2 = 1;    // preset CS of 74HC595
 
-    Display_6D_write(0x543210);
-    Display_2D_write(TGATE);
-    Display_init(); // initialize MAX7219
+    DigitsDisplay.Display_6D_write(0x543210);
+    DigitsDisplay.Display_2D_write(TGATE);
 
     // RTC is supposed to be loose time at power down (no backup battery)
     // An initialization is performed anyway 
@@ -155,11 +137,10 @@
         
       // show zero gate time   
       gate = 0;                   
-      Display_2D_write(gate);
+      DigitsDisplay.Display_2D_write(gate);
         
       // show selected content on main display
-      value = (int)(Count1/TGATE);
-      Display_6D_write(value);    // refresh the main display              
+      DigitsDisplay.Display_6D_write(Count1);    // refresh the main display              
    }
     
    else
@@ -170,17 +151,14 @@
         
       if(gate==0) // show the counter value at the end of the gate time
       {
-         value = (int)(Count1/TGATE);
-                
-         Display_6D_write(value);    // refresh the main display 
+         DigitsDisplay.Display_6D_write(Count1);    // refresh the main display 
         
          Count1 = 0;     // clear both counters
          Count2 = 0;
          gate = TGATE;// and reload the gate time
-
       }
 
-      Display_2D_write(gate);     // show gate time countdown 
+      DigitsDisplay.Display_2D_write(gate);     // show gate time countdown 
       gate--;
    }
 }
@@ -189,16 +167,14 @@
 {
    // This must be called periodically to monitor switch input
    direction = ModeSwitch.UpdateInput();
-   if (   (direction > 0)
-       && (brightness < BRIGHTNESS_MAX))
+   if (direction > 0)
    {
-      Display_brightness(++brightness);
+      DigitsDisplay.Display_brightness_up();
    }
    else
-      if (   (direction < 0)
-          && (brightness > BRIGHTNESS_MIN))
+      if (direction < 0)
    {
-       Display_brightness(--brightness);
+       DigitsDisplay.Display_brightness_down();
    }
         
    ADC_val = KEYB.read();  // read voltage from keyboard
@@ -250,126 +226,5 @@
     return; 
 }
 
-//---------------------------------------------------------------------------
-// Initialize the MAX7219
-
-void Display_init(void)
-{
-    uint8_t i;
-    uint16_t data_to_send[6] = {SHUTDOWN, TURN_ON, DEC_MODE, brightness, SCAN_LIM, TEST};
-
-    for(i = 0; i < sizeof(data_to_send)/sizeof(uint16_t); i++)
-    {
-       sendDataToDisplay(data_to_send[i]);
-    }
-    
-  return;
-}
-
-void Display_brightness(uint16_t brightness)
-{
-   sendDataToDisplay(brightness);
-}
-
-//---------------------------------------------------------------------------
-// Refresh the 6 digits of the main display
-
-void Display_6D_write(uint8_t value)
-{
- 
-    uint8_t digit;
-    uint16_t data_to_send;
-    char TextString[6];
-    
-    // int to string, then string to digits
-    
-    sprintf(TextString, "%6d", value);   // int to string
-    
-    for(uint8_t i=0; i<6; i++)
-    {   
-        if(TextString[i] == ' ')  // blank empty digits
-            Disp_Digit[i] = 0xFF;
-        else
-            Disp_Digit[i] = TextString[i]-'0';      
-    }
-
-    // write to chip
-
-    SCK = 0;
-    wait_us(DT);    
-    
-    for(digit = 1; digit <7; digit++)
-    {
-        // each stream consists of digit address and data to show
-        data_to_send = 7 - digit;
-        data_to_send<<=8;
-        data_to_send = data_to_send | Disp_Digit[digit-1];
-        sendDataToDisplay(data_to_send);
-   }
-    
-  return;
-}
-
-
-//---------------------------------------------------------------------------
-// Refresh the 2 digits of the gate display
-
-void Display_2D_write(unsigned short value)
-{
- 
-    uint8_t digit;
-    uint16_t data_to_send;
-    char TextString[2];
-
-    // int to string, then string to digits
-    
-    sprintf(TextString, "%2d", value);   // int to string
-
-    if(TextString[0] == ' ')  // blank empty digits
-        Disp_Digit[7] = 0xFF;    
-    else
-        Disp_Digit[7] = TextString[0] - '0';
-    
-    Disp_Digit[6] = TextString[1] - '0';
-
-    // write to chip
-    
-    SCK = 0;
-    wait_us(DT);    
-    
-    for(digit = 7; digit <9; digit++)
-    {
-        // each stream consists of digit address and data to show
-        data_to_send = digit;
-        data_to_send<<=8;
-        data_to_send = data_to_send | Disp_Digit[digit-1];
-        sendDataToDisplay(data_to_send);
-    }
-    
-  return;
-}
-
-void sendDataToDisplay(uint16_t data_to_send)
-{
-        CS1 = 0;
-        for(uint16_t mask = 0x8000; mask!= 0; mask>>= 1)
-        {
-            wait_us(DT);
-            SCK = 0;
-            if(mask & data_to_send)
-                MOSI = 1;
-            else
-                MOSI = 0;
-                
-            wait_us(DT);
-            SCK = 1;
-        }
-        
-        wait_us(DT);    
-        SCK = 0;
-        wait_us(DT);
-        CS1 = 1;
-}
-
 //-------- END OF FILE --------------
 //==============================================================================