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

📄 dc550_phonesm_volume.c

📁 一款经典的数字电话设计资料
💻 C
字号:
/*****************************************************************************/
/*  CONFIDENTIAL                                                             */
/*  Sigpro Copyright 2003, All rights reserved                               */
/*****************************************************************************/
/*  CLIENT:  Telematrix                                                      */
/*  PROJECT: DC550 Digital Centrex Phone                                     */
/*  FILE:    dc550_phonesm_volume.c                                          */
/*****************************************************************************/
/*  The Volume State is only active when the user is adjusting the           */
/*  volume.  It will only ever be active if it is on top of the state        */
/*  stack.                                                                   */
/*****************************************************************************/

#define __DC550_PHONESM_VOLUME_EXTERN__
#include "dc550_phonesm_volume.h"
#include "dc550_phonesm_active.h"
#include "dc550_phonesm_idle.h"
#include "dc550_phonesm_init.h"
#include "dc550_phonesm_memory.h"
#include "dc550_phonesm_predial.h"
#include "dc550_phonesm_program.h"
#include "dc550_phonesm_display12.h"
#include "dc550_phonesm_infoaudio.h"
#include "dc550_phonesm_infolevels.h"
#include "dc550_phonesm_infolanguage.h"
#include "dc550_phonesm.h"
#include "dc550_audio.h"
#include "dc550_display.h"
#include "dc550_leddriver.h"


/******************************************************************************
 *  GLOBAL VARIABLES
 *****************************************************************************/
PHONESM_STATE_E phonesm_volume_exitstate;
DC550InterruptCounter phonesm_volume_periodtimeout;


/******************************************************************************
 *  FUNCTION: void phonesm_volume_init(void) {
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called to initialize all of the Volume State variables.
 *****************************************************************************/
void phonesm_volume_init(void) {

  audio_volume( AUDIO_RINGER, phonesm_infolevels_getalertervolume() );
  audio_volume( AUDIO_HEADSET, phonesm_infolevels_getheadsetvolume() );
  audio_volume( AUDIO_SPEAKER, phonesm_infolevels_getspeakervolume() );
  audio_volume( AUDIO_HANDSET, phonesm_infolevels_gethandsetvolume() );
}


/******************************************************************************
 *  FUNCTION: void phonesm_volume_state_enter(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called whenever the telephone enters the Volume State.
 *****************************************************************************/
void phonesm_volume_state_enter(void) {
  PHONESM_SPEAKINGDEVICE_E device = phonesm_infoaudio_getspeakingdevice();
  if(device == PHONESM_SPEAKINGDEVICE_NONE)
    device = PHONESM_SPEAKINGDEVICE_ALERTER;

  phonesm_volume_periodtimeout = PHONESM_VOLUME_TIMEOUT;
  
  display_writelineone( 0,
                        phonesm_infolanguage_getlineone_volume(device) );
  switch(device) {
    case PHONESM_SPEAKINGDEVICE_NONE:
    case PHONESM_SPEAKINGDEVICE_ALERTER:
      display_writelinetwo( 0,
        phonesm_infolevels_getlevelline(phonesm_infolevels_getalertervolume()));
      break;
    case PHONESM_SPEAKINGDEVICE_HANDSET:
      display_writelinetwo( 0,
        phonesm_infolevels_getlevelline(phonesm_infolevels_gethandsetvolume()));
      break;
    case PHONESM_SPEAKINGDEVICE_HEADSET:
      display_writelinetwo( 0,
        phonesm_infolevels_getlevelline(phonesm_infolevels_getheadsetvolume()));
      break;
    case PHONESM_SPEAKINGDEVICE_SPEAKERPHONE:
      display_writelinetwo( 0,
        phonesm_infolevels_getlevelline(phonesm_infolevels_getspeakervolume()));
      break;
  }
  
  // Turn on LCD Backlight
  leddriver_setstate(LED_INDICATOR_BACKLIGHT, LED_STATE_ON);
}


/******************************************************************************
 *  FUNCTION: void phonesm_volume_state_exit(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called whenever the telephone exits the Volume State.
 *****************************************************************************/
void phonesm_volume_state_exit(void) {
  switch(phonesm_infoaudio_getspeakingdevice()) {
    case PHONESM_SPEAKINGDEVICE_ALERTER:
    case PHONESM_SPEAKINGDEVICE_NONE:
      phonesm_infolevels_commitalertervolume();
      break;
    case PHONESM_SPEAKINGDEVICE_HANDSET:
      phonesm_infolevels_commithandsetvolume();
      break;
    case PHONESM_SPEAKINGDEVICE_HEADSET:
      phonesm_infolevels_commitheadsetvolume();
      break;
    case PHONESM_SPEAKINGDEVICE_SPEAKERPHONE:
      phonesm_infolevels_commitspeakervolume();
      break;
  }
}


/******************************************************************************
 *  FUNCTION: BOOL phonesm_volume_exec_hookswitch(BOOL updown)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called when the hookswitch goes up or down while the
 *  phone is in Volume State.  The Volume State always exits with any
 *  hookswitch activity.
 *****************************************************************************/
BOOL phonesm_volume_exec_hookswitch(BOOL updown) {
  phonesm_volume_state_exit();
  phonesm_deactivate_state(PHONESM_STATE_VOLUME);
  return 1;
}


/******************************************************************************
 *  FUNCTION:
 *  BOOL phonesm_volume_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 Volume State.  This function deactivates the Volume State
 *  and returns 1 whenever the key pressed is not a scroll key.
 *****************************************************************************/
BOOL phonesm_volume_exec_keypress(unsigned int key, BOOL updown) {
  // Declare local variables
  DC550Level currentlevel;
  PHONESM_SPEAKINGDEVICE_E device = phonesm_infoaudio_getspeakingdevice();
  if(device == PHONESM_SPEAKINGDEVICE_NONE)
    device = PHONESM_SPEAKINGDEVICE_ALERTER;

  // Currently the Volume State will only respond to key down messages
  if(updown == KEYSTATE_DOWN) {
    switch(key) {
      // The Scroll Keys change the volume
      case KEYPAD_VOLUME_UP:
        phonesm_volume_periodtimeout = PHONESM_VOLUME_TIMEOUT;
        switch(phonesm_infoaudio_getspeakingdevice()) {
          case PHONESM_SPEAKINGDEVICE_ALERTER:
          case PHONESM_SPEAKINGDEVICE_NONE:
            currentlevel = phonesm_infolevels_getalertervolume();
            if(currentlevel < 15) {
              currentlevel += 1;
              phonesm_infolevels_setalertervolume(currentlevel);
            }
            audio_volume( AUDIO_RINGER, currentlevel );
            display_writelinetwo(0,
              phonesm_infolevels_getlevelline(currentlevel));
            break;
          case PHONESM_SPEAKINGDEVICE_HANDSET:
            currentlevel = phonesm_infolevels_gethandsetvolume();
            if(currentlevel < 15) {
              currentlevel += 1;
              phonesm_infolevels_sethandsetvolume(currentlevel);
            }
            audio_volume( AUDIO_HANDSET, currentlevel );
            display_writelinetwo(0,
              phonesm_infolevels_getlevelline(currentlevel));
            break;
          case PHONESM_SPEAKINGDEVICE_HEADSET:
            currentlevel = phonesm_infolevels_getheadsetvolume();
            if(currentlevel < 15) {
              currentlevel += 1;
              phonesm_infolevels_setheadsetvolume(currentlevel);
            }
            audio_volume( AUDIO_HEADSET, currentlevel );
            display_writelinetwo(0,
              phonesm_infolevels_getlevelline(currentlevel));
            break;
          case PHONESM_SPEAKINGDEVICE_SPEAKERPHONE:
            currentlevel = phonesm_infolevels_getspeakervolume();
            if(currentlevel < 15) {
              currentlevel += 1;
              phonesm_infolevels_setspeakervolume(currentlevel);
            }
            audio_volume( AUDIO_SPEAKER, currentlevel );
            display_writelinetwo(0,
              phonesm_infolevels_getlevelline(currentlevel));
            break;
        }
        return 0;
      case KEYPAD_VOLUME_DOWN:
        phonesm_volume_periodtimeout = PHONESM_VOLUME_TIMEOUT;
        switch(phonesm_infoaudio_getspeakingdevice()) {
          case PHONESM_SPEAKINGDEVICE_ALERTER:
          case PHONESM_SPEAKINGDEVICE_NONE:
            currentlevel = phonesm_infolevels_getalertervolume();
            if(currentlevel > 0) {
              currentlevel -= 1;
              phonesm_infolevels_setalertervolume(currentlevel);
            }
            audio_volume( AUDIO_RINGER, currentlevel );
            display_writelinetwo(0,
              phonesm_infolevels_getlevelline(currentlevel));
            break;
          case PHONESM_SPEAKINGDEVICE_HANDSET:
            currentlevel = phonesm_infolevels_gethandsetvolume();
            if(currentlevel > 0) {
              currentlevel -= 1;
              phonesm_infolevels_sethandsetvolume(currentlevel);
            }
            audio_volume( AUDIO_HANDSET, currentlevel );
            display_writelinetwo(0,
              phonesm_infolevels_getlevelline(currentlevel));
            break;
          case PHONESM_SPEAKINGDEVICE_HEADSET:
            currentlevel = phonesm_infolevels_getheadsetvolume();
            if(currentlevel > 0) {
              currentlevel -= 1;
              phonesm_infolevels_setheadsetvolume(currentlevel);
            }
            audio_volume( AUDIO_HEADSET, currentlevel );
            display_writelinetwo(0,
              phonesm_infolevels_getlevelline(currentlevel));
            break;
          case PHONESM_SPEAKINGDEVICE_SPEAKERPHONE:
            currentlevel = phonesm_infolevels_getspeakervolume();
            if(currentlevel > 0) {
              currentlevel -= 1;
              phonesm_infolevels_setspeakervolume(currentlevel);
            }
            audio_volume( AUDIO_SPEAKER, currentlevel );
            display_writelinetwo(0,
              phonesm_infolevels_getlevelline(currentlevel));
            break;
        }
        return 0;
      case KEYPAD_LOCAL_EXIT:
        phonesm_volume_state_exit();
        phonesm_deactivate_state(PHONESM_STATE_VOLUME);
        return 0;
      default:
        phonesm_volume_state_exit();
        phonesm_deactivate_state(PHONESM_STATE_VOLUME);
        return 1;
    }
  }
  else
    return 0;
}


/******************************************************************************
 *  FUNCTION:
 *  BOOL phonesm_volume_exec_modemcommand(DC550MDCMessage command)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called when the phone receives a modem command while
 *  in the Volume State.  It deactivates the Volume State and returns 1
 *  regardless of the message received.
 *****************************************************************************/
BOOL phonesm_volume_exec_modemcommand(DC550MDCMessage command) {
  // Exit this state
  phonesm_volume_state_exit();
  phonesm_deactivate_state(PHONESM_STATE_VOLUME);
  return 1;
}


/******************************************************************************
 *  FUNCTION:
 *  BOOL phonesm_volume_exec_periodic(BOOL firstline, BOOL secondline)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called periodically whether or not the phone is in the
 *  Idle State.  Since the Idle State is always active, this function will
 *  always be called.  firstline and secondline will both be 1 when the
 *  Idle State is "on top".  firstline would be 0 during Predial, and
 *  secondline would also be 0 when the telephone is active.  This function
 *  returns 1 if the periodic function call needs to be repeated due to a
 *  state change and 0 otherwise.
 *****************************************************************************/
BOOL phonesm_volume_exec_periodic(BOOL firstline, BOOL secondline) {
  if(firstline && secondline) {
    phonesm_volume_periodtimeout--;
    if(!phonesm_volume_periodtimeout) {
      // Exit this state
      phonesm_volume_state_exit();
      phonesm_deactivate_state(PHONESM_STATE_VOLUME);
      return 1;
    }
    
    switch(phonesm_volume_exitstate) {
      case PHONESM_STATE_IDLE:
        phonesm_idle_exec_periodic(0,0);
        break;
      case PHONESM_STATE_INIT:
        phonesm_init_exec_periodic(0,0);
        break;
      case PHONESM_STATE_ACTIVE:
        phonesm_active_exec_periodic(0,0);
        break;
      case PHONESM_STATE_PROGRAM:
        phonesm_program_exec_periodic(0,0);
        break;
      case PHONESM_STATE_DISPLAY12:
        phonesm_display12_exec_periodic(0,0);
        break;
      case PHONESM_STATE_MEMORY:
        phonesm_memory_exec_periodic(0,0);
        break;
      case PHONESM_STATE_PREDIAL:
        phonesm_predial_exec_periodic(0,0);
        break;
      case PHONESM_STATE_CONTRAST:
      case PHONESM_STATE_VOLUME:
        // This should never happen
        // Exit this state
        phonesm_volume_state_exit();
        phonesm_deactivate_state(PHONESM_STATE_VOLUME);
        return 1;
    };
    return 0;
  }
  else {
    // Exit this state
    phonesm_volume_state_exit();
    phonesm_deactivate_state(PHONESM_STATE_VOLUME);
    return 1;
  }
}

⌨️ 快捷键说明

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