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

📄 dc550_phonesm_active.c

📁 一款经典的数字电话设计资料
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************/
/*  CONFIDENTIAL                                                             */
/*  Sigpro Copyright 2003, All rights reserved                               */
/*****************************************************************************/
/*  CLIENT:  Telematrix                                                      */
/*  PROJECT: DC550 Digital Centrex Phone                                     */
/*  FILE:    dc550_phonesm_active.c                                          */
/*****************************************************************************/
/*  The Active State is activated after the telephone has received an        */
/*  appropriate message from the DMS switch (the Central Office) or after    */
/*  the user takes the telephone off hook.                                   */
/*****************************************************************************/

#define __DC550_PHONESM_ACTIVE_EXTERN__
#include "dc550_phonesm_active.h"
#include "dc550_phonesm.h"
#include "dc550_phonesm_idle.h"
#include "dc550_phonesm_display12.h"
#include "dc550_phonesm_infoaudio.h"
#include "dc550_phonesm_infonumbers.h"
#include "dc550_phonesm_infoonetouch.h"
#include "dc550_phonesm_infosettings.h"
#include "dc550_phonesm_infodisplay12.h"
#include "dc550_modemcontroller.h"
#include "dc550_audio.h"
#include "dc550_leddriver.h"
#include "dc550_display.h"
#include "dc550_usartdriver.h"
#include "dc550_controller.h"


/******************************************************************************
 *  GLOBAL VARIABLES
 *****************************************************************************/
// State variables
PHONESM_STATE_E phonesm_active_exitstate;
BOOL phonesm_active_handsetactivated;
BOOL phonesm_active_buzzeron;
DC550InterruptCounter phonesm_active_pendingonhook;
DC550InterruptCounter phonesm_active_pendingoffhook;
PHONESM_SPEAKINGDEVICE_E phonesm_active_pendingdevice;

// Predial variables
char phonesm_active_predialnumber[PHONENUMBER_ARRAY_SIZE];
unsigned int phonesm_active_predialcurrentkey;
char phonesm_active_predialnextdigit;
DC550InterruptCounter phonesm_active_predialon;
DC550InterruptCounter phonesm_active_predialoff;

// Store Number variables
char phonesm_active_storenumber[PHONENUMBER_ARRAY_SIZE];
char phonesm_active_storenextdigit;

// One Touch Messaging variables
PHONESM_ACTIVE_ONETOUCHSTATE_E phonesm_active_onetouch;
DC550InterruptCounter phonesm_active_onetouch_timeout;

// Display variables
char phonesm_active_buffer_lineone[25];
char phonesm_active_buffer_linetwo[25];
DC550LCDCoordinate phonesm_active_cursorx;
DC550LCDCoordinate phonesm_active_cursory;
PHONESM_ACTIVE_ECHOSTATE_E phonesm_active_digitechoing;
BOOL phonesm_active_echoclearlineone;
BOOL phonesm_active_powerup;
BOOL phonesm_active_displayenabled;
BOOL phonesm_active_displaystatus;

// Call Timer Variables
DC550InterruptCounter phonesm_active_timer_periods;
char phonesm_active_timer_display[12];
PHONESM_ACTIVE_TIMERSTATE_E phonesm_active_timerstate;
DC550InterruptCounter phonesm_active_timerwinkon;
DC550InterruptCounter phonesm_active_timerwinkoff;


/******************************************************************************
 *  FUNCTION: void phonesm_active_init(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called to initialize all of the Active State variables.
 *****************************************************************************/
void phonesm_active_init(void) {
  // Declare local variables
  int i;
  
  // Initialize state variables
  phonesm_active_exitstate = PHONESM_STATE_IDLE;
  phonesm_active_handsetactivated = FALSE;
  phonesm_active_buzzeron = FALSE;
  phonesm_active_pendingonhook = 0;
  phonesm_active_pendingoffhook = 0;
  phonesm_active_pendingdevice = PHONESM_SPEAKINGDEVICE_NONE;
  
  // Initialize predial variables
  phonesm_active_predialnumber[0] = 0;
  phonesm_active_predialcurrentkey = 0xFF;
  phonesm_active_predialnextdigit = 0;
  phonesm_active_predialon = 0;
  phonesm_active_predialoff = 0;
  
  // Initialize Store Number variables
  phonesm_active_storenumber[0] = 0;
  phonesm_active_storenextdigit = 0;
  
  // Initialize One-Touch Messaging variables
  phonesm_active_onetouch = ONETOUCHSTATE_OFF;
  phonesm_active_onetouch_timeout = 0;
  
  // Initialize display variables
  for(i = 0; i < 24; i++) {
    phonesm_active_buffer_lineone[i] = ' ';
    phonesm_active_buffer_linetwo[i] = ' ';
  }
  phonesm_active_buffer_lineone[24] = 0;
  phonesm_active_buffer_linetwo[24] = 0;
  
  phonesm_active_cursorx = 0;
  phonesm_active_cursory = 0;
  phonesm_active_digitechoing = ECHOSTATE_OFF_IP;
  phonesm_active_echoclearlineone = FALSE;
  phonesm_active_powerup = FALSE;
  phonesm_active_displayenabled = FALSE;
  phonesm_active_displaystatus = TRUE;
  
  phonesm_active_timer_periods = 0;
  phonesm_active_timer_display[0] = '[';
  phonesm_active_timer_display[1] = '0';
  phonesm_active_timer_display[2] = '0';
  phonesm_active_timer_display[3] = ':';
  phonesm_active_timer_display[4] = '0';
  phonesm_active_timer_display[5] = '0';
  phonesm_active_timer_display[6] = ':';
  phonesm_active_timer_display[7] = '0';
  phonesm_active_timer_display[8] = '0';
  phonesm_active_timer_display[9] = ']';
  phonesm_active_timer_display[10] = ' ';
  phonesm_active_timer_display[11] = 0;
  phonesm_active_timerwinkon = 0;
  phonesm_active_timerwinkoff = 0;
}


/******************************************************************************
 *  FUNCTION: void phonesm_active_state_enter(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called whenever the telephone enters the Active State.
 *****************************************************************************/
void phonesm_active_state_enter(void) {

  // Update the display
  if(phonesm_active_displayenabled) {
    display_writelineone(0, phonesm_active_buffer_lineone);
    display_writelinetwo(0, phonesm_active_buffer_linetwo);
  }
  else {
    display_cleardisplay();
  }
  
  // Write the Call Timer if appropriate
  if( (phonesm_active_timerstate == TIMERSTATE_ON) &&
      (phonesm_active_timerwinkoff == 0) ) {
    display_writelinetwo(13, phonesm_active_timer_display);
  }
  
  // Update the Alert Indicator LED
  switch (phonesm_infoaudio_speakingdevice) {
    case PHONESM_SPEAKINGDEVICE_ALERTER:
      leddriver_setstate(LED_INDICATOR_VOICEMAIL, LED_STATE_FLASH);
      break;
    case PHONESM_SPEAKINGDEVICE_NONE:
    case PHONESM_SPEAKINGDEVICE_HEADSET:
    case PHONESM_SPEAKINGDEVICE_SPEAKERPHONE:
    case PHONESM_SPEAKINGDEVICE_HANDSET:
      switch(phonesm_infoonetouch_getledstate()) {
        case LED_STATE_OFF:
          leddriver_setstate(LED_INDICATOR_VOICEMAIL, LED_STATE_OFF);
          break;
        case LED_STATE_WINK:
        case LED_STATE_FLASH:
        case LED_STATE_ON:
          leddriver_setstate(LED_INDICATOR_VOICEMAIL, LED_STATE_WINK);
          break;
      }
      break;
  }
  
  // Turn on LCD Backlight
  leddriver_setstate(LED_INDICATOR_BACKLIGHT, LED_STATE_ON);
}


/******************************************************************************
 *  FUNCTION: void phonesm_active_state_exit(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called by one of the functions in this file whenever
 *  this state is deactivated.
 *****************************************************************************/
void phonesm_active_state_exit(void) {

  // Clear the Predial info so that the Active State does not predial the
  // same number the next time
  phonesm_active_predial_clear();
  
  // Clear the Store Number
  phonesm_active_storenumber_clear();

  // Clear the One-Touch Messaging State
  phonesm_active_onetouch = ONETOUCHSTATE_OFF;
  phonesm_active_onetouch_timeout = 0;

  phonesm_active_handsetactivated = FALSE;

  // Turn the Buzzer off if necessary
  if(phonesm_active_buzzeron) {
    phonesm_active_buzzeron = FALSE;
    audio_buzzer(FALSE);
  }
  
  // Clear the Mute Indicator
  if(phonesm_infoaudio_muteon) {
    audio_mute(FALSE);
    phonesm_infoaudio_muteon = FALSE;
    leddriver_setstate(LED_INDICATOR_MUTE, LED_STATE_OFF);
  }

  // Clear Speakerphone and Headset Indicators and turn audio off if necessary
  switch(phonesm_infoaudio_speakingdevice) {
    case PHONESM_SPEAKINGDEVICE_NONE:
      break;
    case PHONESM_SPEAKINGDEVICE_ALERTER:
      phonesm_infoaudio_set_speakingdevice(PHONESM_SPEAKINGDEVICE_NONE);
      audio_ringer(FALSE);
      audio_select(AUDIO_OFF);
      break;
    case PHONESM_SPEAKINGDEVICE_HEADSET:
      modemcontroller_send_modemmessage(MDC_CPE_HOOKSTATE_DOWN);
      phonesm_infoaudio_set_speakingdevice(PHONESM_SPEAKINGDEVICE_NONE);
      leddriver_setstate(LED_INDICATOR_HEADSET, LED_STATE_OFF);
      audio_select(AUDIO_OFF);
      break;
    case PHONESM_SPEAKINGDEVICE_SPEAKERPHONE:
      modemcontroller_send_modemmessage(MDC_CPE_HOOKSTATE_DOWN);
      phonesm_infoaudio_set_speakingdevice(PHONESM_SPEAKINGDEVICE_NONE);
      leddriver_setstate(LED_INDICATOR_SPEAKERPHONE, LED_STATE_OFF);
      audio_select(AUDIO_OFF);
      break;
    case PHONESM_SPEAKINGDEVICE_HANDSET:
      modemcontroller_send_modemmessage(MDC_CPE_HOOKSTATE_DOWN);
      phonesm_infoaudio_set_speakingdevice(PHONESM_SPEAKINGDEVICE_NONE);
      audio_select(AUDIO_OFF);
      break;
  }
  
  // Clear Call Timer
  if(phonesm_active_timerstate != TIMERSTATE_OFF) {
    phonesm_active_timerstate = TIMERSTATE_OFF;
    phonesm_active_timer_periods = 0;
    phonesm_active_timer_display[1] = '0';
    phonesm_active_timer_display[2] = '0';
    phonesm_active_timer_display[4] = '0';
    phonesm_active_timer_display[5] = '0';
    phonesm_active_timer_display[7] = '0';
    phonesm_active_timer_display[8] = '0';
  }
  phonesm_active_timerwinkon = 0;
  phonesm_active_timerwinkoff = 0;
}


/******************************************************************************
 *  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 Active State.  If the Active State activates another state while
 *  executing this function, the function will return 1.  Otherwise, it will
 *  return 0.
 *****************************************************************************/
BOOL phonesm_active_exec_hookswitch(BOOL updown) {
  // This checks if the hookswitch went down
  if(updown == HOOKSTATE_DOWN) {
    switch (phonesm_infoaudio_speakingdevice) {
      case PHONESM_SPEAKINGDEVICE_HANDSET:
        if(phonesm_active_pendingoffhook) {
          phonesm_active_pendingdevice = PHONESM_SPEAKINGDEVICE_HANDSET;
        }
        else {
          phonesm_active_pendingonhook = PHONESM_ACTIVE_ONHOOK_PENDING;
          phonesm_active_pendingdevice = PHONESM_SPEAKINGDEVICE_NONE;
          modemcontroller_send_modemmessage(MDC_CPE_HOOKSTATE_DOWN);
          phonesm_infoaudio_set_speakingdevice(PHONESM_SPEAKINGDEVICE_NONE);
          phonesm_active_handsetactivated = FALSE;
          if(phonesm_infoaudio_muteon) {
            audio_mute(FALSE);
            phonesm_infoaudio_muteon = FALSE;
            leddriver_setstate(LED_INDICATOR_MUTE, LED_STATE_OFF);
          }
          audio_select(AUDIO_OFF);
        }
        break;
      case PHONESM_SPEAKINGDEVICE_HEADSET:
      case PHONESM_SPEAKINGDEVICE_SPEAKERPHONE:
        break;
      case PHONESM_SPEAKINGDEVICE_ALERTER:
      case PHONESM_SPEAKINGDEVICE_NONE:
        // This should only happen when the DMS switch is too slow

⌨️ 快捷键说明

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