#ifndef DISPLAY_DRIVER
#define DISPLAY_DRIVER
//
// display_driver.h
//
//
// The DisplayDriver class is used to update the 14-seg displays used
// by John Mack's Stock Ticker Tape.
// 
// The display chips contain 2 character with 14-segments each. Also there 
// are 2 decimal points and 4 external outputs.  This adds up to 34 bits that
// are sent serially to each chip.  Since we will never us the last two 
// external outputs pins, the last two bits are always zero.
// The update() routine compares the 10 "next" dwords with the "current" dwords.
// If they are different, it sents the new dword+00 to the display chip and
// update the curDisplay[] to match.

class DisplayDriver 
  {
  //
  // Constants
  //
  #define LED_ADDR0_PIN   3
  #define LED_ADDR1_PIN   4
  #define LED_ADDR2_PIN   5
  #define LED_ADDR4_PIN   6
  #define LED_ENABLE_PIN  7
  #define LED_DATA_PIN    8
  #define LED_CLOCK_PIN   9

  #define DIGITS_PER_CHIP       2
  #define CHIPS_PER_LINE        5
  #define DIGITS_PER_LINE       10
  #define NUM_OF_LINES          2
  #define NUM_OF_DISPLAY_CHIPS  10

  // for wrapMode                // print(char) 
  #define VSCROLL             0  // '\20' or '\S'
  #define WRAP_1LINE          1  // '\21' or '\w'
  #define WRAP_2LINES         2  // '\22' or '\W'
  #define HSCOLL_1LINE        3  // '\23' or '\h'
  #define HSCOLL_2LINES       4  // '\24' or '\H'
  #define DEFAULT_SCROLL_SPEED  50 // milliseconds per character

  // for printMode
  #define PRINT_MODE_OR       0  // '\25' or '\O'
  #define PRINT_MODE_XOR      1  // '\26' or '\X'
  #define PRINT_MODE_REPLACE  2  // '\27' or '\R'

  //
  // Member Data
  //

  private:
    long  curDisplay[NUM_OF_DISPLAY_CHIPS];
    long  nextDisplay[NUM_OF_DISPLAY_CHIPS];
    int   cursor;
    int   wrapMode;
    int   printMode;
    char* msg_ptr;
    char* nextMsg_ptr;
    int   scrollSpeed;
    long  waitUntilMillis; // Used to regulate the display speed.

  public:
    //
    // Constructor
    //
    DisplayDriver();

    //
    // Member Functions
    //
    void  setHScrollSpeed( int speed );
    bool  print( char*  msg, bool  preempt );
    int   printQueueLen();
    void  msgPump( long  millis );

  private:
    void  cls();
    void  vScroll();
    void  hScoll( int  line );
    void  printChar( char  c );
    void  update();

    void  dumpDisplay();
  };

#endif