⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dc550_phonesm_memory.c

📁 一款经典的数字电话设计资料
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************/
/*  CONFIDENTIAL                                                             */
/*  Sigpro Copyright 2003, All rights reserved                               */
/*****************************************************************************/
/*  CLIENT:  Telematrix                                                      */
/*  PROJECT: DC550 Digital Centrex Phone                                     */
/*  FILE:    dc550_phonesm_memory.c                                          */
/*****************************************************************************/
/*  The Memory State becomes activated when someone presses the Memory key   */
/*  while in the Idle State.                                                 */
/*****************************************************************************/

#define __DC550_PHONESM_MEMORY_EXTERN__
#include "dc550_phonesm_memory.h"
#include "dc550_phonesm.h"
#include "dc550_phonesm_idle.h"
#include "dc550_phonesm_infosettings.h"
#include "dc550_phonesm_infonumbers.h"
#include "dc550_phonesm_infolanguage.h"
#include "dc550_display.h"
#include "dc550_leddriver.h"


/******************************************************************************
 *  GLOBAL VARIABLES
 *****************************************************************************/
PHONESM_STATE_E phonesm_memory_exitstate;
DC550InterruptCounter phonesm_memory_periodtimeout;
char phonesm_memory_digits[PHONENUMBER_ARRAY_SIZE];
char phonesm_memory_currentindex;


/******************************************************************************
 *  FUNCTION: void phonesm_memory_init(void) {
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called to initialize all of the Memory State variables.
 *****************************************************************************/
void phonesm_memory_init(void) {
  phonesm_memory_exitstate = PHONESM_STATE_IDLE;
  phonesm_memory_periodtimeout = 0;
  phonesm_memory_digits[0] = 0;
  phonesm_memory_currentindex = 10;
}


/******************************************************************************
 *  FUNCTION: void phonesm_memory_state_enter(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called whenever the telephone enters the Memory State.
 *****************************************************************************/
void phonesm_memory_state_enter(void) {
  // Declare function variables
  char timebuffer[TIMEDATE_ARRAY_SIZE];

  // Refresh the timeout
  phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
  
  // Retrieve current memory dial number
  phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                       phonesm_memory_digits );

  // Clear the display
  display_cleardisplay();
  
  // Write the memory marker and digits on the first line of the display
  display_writelineone( 0,
    phonesm_infolanguage_getmarker_memorydial(phonesm_memory_currentindex) );
  display_writelineone( 4, phonesm_memory_digits );
  
  // Get the time and display it
  phonesm_infosettings_getformattedtime(timebuffer);
  display_writelinetwo( (24 - TIMEDATE_STRING_LENGTH), timebuffer);
  
  // Turn on LCD Backlight
  leddriver_setstate(LED_INDICATOR_BACKLIGHT, LED_STATE_ON);
}


/******************************************************************************
 *  FUNCTION: void phonesm_memory_savenumber(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called when the telephone exits the Memory State but
 *  wishes to save the number.
 *****************************************************************************/
void phonesm_memory_savenumber(void) {
  phonesm_infonumbers_setpredialnumber(phonesm_memory_digits);
  phonesm_memory_digits[0] = 0;
  phonesm_memory_currentindex = 10;
}


/******************************************************************************
 *  FUNCTION: void phonesm_memory_discardnumber(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called when the telephone exits the Memory State and
 *  does not wish to save the number.
 *****************************************************************************/
void phonesm_memory_discardnumber(void) {
  phonesm_memory_digits[0] = 0;
  phonesm_memory_currentindex = 10;
}


/******************************************************************************
 *  FUNCTION: void phonesm_exec_hookswitch(unsigned int updown)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called when the hookswitch goes up or down while the
 *  phone is in Memory State.  It does nothing when the hookswitch goes down,
 *  but it saves the number and exits the state when the hookswitch goes up.
 *****************************************************************************/
BOOL phonesm_memory_exec_hookswitch(BOOL updown) {
  // This checks if the hookswitch went down
  if(updown == HOOKSTATE_DOWN) {
    // Do nothing
    return 0;
  }
  
  // This checks if the hookswitch went up
  else {
    // Save the number, exit the Memory State
    phonesm_memory_savenumber();
    phonesm_deactivate_state(PHONESM_STATE_MEMORY);
    return 1;
  }
}


/******************************************************************************
 *  FUNCTION: BOOL phonesm_memory_exec_keypress(unsigned int key, BOOL updown)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called whenever a key goes up or down while the phone
 *  is in the Memory State.  Most keys exit the Memory State, but some
 *  activate the Contrast and Volume States, and the digit keys and Pause key
 *  are obviously retained as memory digits.
 *****************************************************************************/
BOOL phonesm_memory_exec_keypress(unsigned int key, BOOL updown) {
  char oldindex;
  char locationpopulated = 0;

  // Currently the Memory State will only respond to key down messages
  if(updown == KEYSTATE_DOWN) {
    switch(key) {

      // The Memory key toggles between different memory dial numbers
      case KEYPAD_LOCAL_MEMORY:
      case KEYPAD_SCROLL_UP:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        
        if(phonesm_memory_currentindex >= 10) {
          phonesm_memory_currentindex = 0;
          phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                               phonesm_memory_digits );
          locationpopulated = phonesm_memory_digits[0];
          oldindex = 0;
        }
        else {
          oldindex = phonesm_memory_currentindex;
        }

        if( locationpopulated == 0 ) {
          do {
            phonesm_memory_currentindex++;
            if(phonesm_memory_currentindex >= 10)
              phonesm_memory_currentindex = 0;

            phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                                 phonesm_memory_digits );
            locationpopulated = phonesm_memory_digits[0];
          } while( (locationpopulated == 0) &&
                   (phonesm_memory_currentindex != oldindex) );
        }

        display_writelineone( 0, "                        ");
        display_writelineone( 0,
          phonesm_infolanguage_getmarker_memorydial(
            phonesm_memory_currentindex) );
        display_writelineone( 4, phonesm_memory_digits );
        return 0;

      case KEYPAD_SCROLL_DOWN:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        
        oldindex = phonesm_memory_currentindex;

        do {
          if(phonesm_memory_currentindex == 0)
            phonesm_memory_currentindex = 9;
          else 
            phonesm_memory_currentindex--;

          phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                               phonesm_memory_digits );
          locationpopulated = phonesm_memory_digits[0];
        } while( (locationpopulated == 0) &&
                 (phonesm_memory_currentindex != oldindex) );

        display_writelineone( 0, "                        ");
        display_writelineone( 0,
          phonesm_infolanguage_getmarker_memorydial(
            phonesm_memory_currentindex) );
        display_writelineone( 4, phonesm_memory_digits );
        return 0;
        
      case KEYPAD_DIGIT_0:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        phonesm_infonumbers_getmemorynumber( 0, phonesm_memory_digits );
        if( phonesm_memory_digits[0] ) {
          phonesm_memory_currentindex = 0;
          display_writelineone( 0, "                        ");
          display_writelineone( 0,
            phonesm_infolanguage_getmarker_memorydial(
              phonesm_memory_currentindex) );
          display_writelineone( 4, phonesm_memory_digits );
        }
        else {
          phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                               phonesm_memory_digits );
        }
        return 0;
      case KEYPAD_DIGIT_1:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        phonesm_infonumbers_getmemorynumber( 1, phonesm_memory_digits );
        if( phonesm_memory_digits[0] ) {
          phonesm_memory_currentindex = 1;
          display_writelineone( 0, "                        ");
          display_writelineone( 0,
            phonesm_infolanguage_getmarker_memorydial(
              phonesm_memory_currentindex) );
          display_writelineone( 4, phonesm_memory_digits );
        }
        else {
          phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                               phonesm_memory_digits );
        }
        return 0;
      case KEYPAD_DIGIT_2:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        phonesm_infonumbers_getmemorynumber( 2, phonesm_memory_digits );
        if( phonesm_memory_digits[0] ) {
          phonesm_memory_currentindex = 2;
          display_writelineone( 0, "                        ");
          display_writelineone( 0,
            phonesm_infolanguage_getmarker_memorydial(
              phonesm_memory_currentindex) );
          display_writelineone( 4, phonesm_memory_digits );
        }
        else {
          phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                               phonesm_memory_digits );
        }
        return 0;
      case KEYPAD_DIGIT_3:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        phonesm_infonumbers_getmemorynumber( 3, phonesm_memory_digits );
        if( phonesm_memory_digits[0] ) {
          phonesm_memory_currentindex = 3;
          display_writelineone( 0, "                        ");
          display_writelineone( 0,
            phonesm_infolanguage_getmarker_memorydial(
              phonesm_memory_currentindex) );
          display_writelineone( 4, phonesm_memory_digits );
        }
        else {
          phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                               phonesm_memory_digits );
        }
        return 0;
      case KEYPAD_DIGIT_4:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        phonesm_infonumbers_getmemorynumber( 4, phonesm_memory_digits );
        if( phonesm_memory_digits[0] ) {
          phonesm_memory_currentindex = 4;
          display_writelineone( 0, "                        ");
          display_writelineone( 0,
            phonesm_infolanguage_getmarker_memorydial(
              phonesm_memory_currentindex) );
          display_writelineone( 4, phonesm_memory_digits );
        }
        else {
          phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                               phonesm_memory_digits );
        }
        return 0;
      case KEYPAD_DIGIT_5:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        phonesm_infonumbers_getmemorynumber( 5, phonesm_memory_digits );
        if( phonesm_memory_digits[0] ) {
          phonesm_memory_currentindex = 5;
          display_writelineone( 0, "                        ");
          display_writelineone( 0,
            phonesm_infolanguage_getmarker_memorydial(
              phonesm_memory_currentindex) );
          display_writelineone( 4, phonesm_memory_digits );
        }
        else {
          phonesm_infonumbers_getmemorynumber( phonesm_memory_currentindex,
                                               phonesm_memory_digits );
        }
        return 0;
      case KEYPAD_DIGIT_6:
        phonesm_memory_periodtimeout = PHONESM_MEMORY_TIMEOUT;
        phonesm_infonumbers_getmemorynumber( 6, phonesm_memory_digits );
        if( phonesm_memory_digits[0] ) {
          phonesm_memory_currentindex = 6;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -