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

📄 item.cpp

📁 湖北水文黄石试点集中器代码
💻 CPP
字号:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "etr232i.h"

#include "item.h"
#include "lcd_api.h"  //add by wuhuan 2006.6.24
//#include "env.h"
/*/////////////////////////////////////////////////////////////////////////
		*** Item Base Class ***
/////////////////////////////////////////////////////////////////////////*/
Item::Item( )
{
   OutStr = new char[64];
   Prefix[0] = Unit[0] = '\0';
   RIdx = 0;
   HighLight = -1;
}

Item::~Item( )
{
   if( OutStr != NULL ) delete OutStr;
}

void Item::MakeOutStr( char* VUStr )
{
   int  TL, k;
   char TmpStr[50];   //change 32 to 50

   TL = strlen(Prefix) + strlen(VUStr);
   if( TL <= ItemOutStrSize )
      sprintf( OutStr, "%s%s", Prefix, VUStr );
   else
      {
      k = strlen(Prefix) - (TL-ItemOutStrSize);
      if( k >= 0 )
	 {
	 strcpy( TmpStr, Prefix );
	 TmpStr[k] = '\0';
	 sprintf( OutStr, "%s%s", TmpStr, VUStr );
	 }
      else
	 {
	 sprintf( TmpStr, "%s%s", Prefix, VUStr );
	 TmpStr[ItemOutStrSize] = '\0';
	 strcpy( OutStr, TmpStr );
	 }
      }
}

void Item::SetNameUnit( char* PreStr, char* UnitStr )
{
   char TmpStr[40];

   strcpy( TmpStr, PreStr );
   if( strlen(TmpStr) > 16 ) TmpStr[16] = '\0';
   strcpy( Prefix, TmpStr );

   strcpy( TmpStr, UnitStr );
   if( strlen(TmpStr) > 4 ) TmpStr[4] = '\0';
   strcpy( Unit, TmpStr );
}

int  Item::OutStrAvailable( )
{
   if( OutStr != NULL )          return 1;
   else if( strlen(Prefix) > 0 ) return 2;
   else		                 return 0;
}

void Item::DefineItem( char* TextStr )
{
   char TmpStr[40];
   int  TextLen, PrefixLen = 14;

   if( TextStr == NULL ) { Prefix[0] = '\0'; return; }
   TextLen = strlen( TextStr );

   strcpy( TmpStr, TextStr );
   if( TextLen > PrefixLen ) TmpStr[PrefixLen] = '\0';
   strcpy( Prefix, TmpStr );
}

int Item::GetOutStr( char* StrBuf )
{
   strcpy( StrBuf, Prefix );
   strcpy( OutStr, StrBuf );
   return RIdx;
}


/*/////////////////////////////////////////////////////////////////////////
		*** Item Derived Class Item_e ***
/////////////////////////////////////////////////////////////////////////*/
Item_e::Item_e( )
{
   OutStr = new char[ItemOutStrSize+2];
   strcpy( OutStr, "未定义!" );
   Prefix[0] = Unit[0] = '\0';
   RIdx = 0;
   HighLight = -1;

   V = 0;
   NumStr = 0;
   EnumAddr = NULL;
}

Item_e::~Item_e( )
{
   delete OutStr;
}

void Item_e::DefineItem( int EnumIdx, int NumEnum, char** EnumPtr )
{
   V = EnumIdx;
   NumStr = NumEnum;
   EnumAddr = EnumPtr;

   if( V<0 || V>=NumStr ) V = 0;
}

float Item_e::Value( void* pParStruct )
{
   return V;
}

void Item_e::ValueInc( )
{
   V += 1;
   if( V >= NumStr ) V = 0;
}

void Item_e::ValueDec( )
{
   V -= 1;
   if( V < 0 ) V = NumStr - 1;
}

void Item_e::ValueINC( )
{
   ValueInc( );
}

void Item_e::ValueDEC( )
{
   ValueDec( );
}

int Item_e::GetOutStr( char* StrBuf )
{
   char VUStr[16];

   if( strlen(EnumAddr[V]) > ItemOutStrSize )
      {
      for( int i=0; i<ItemOutStrSize; i++ ) VUStr[i] = EnumAddr[V][i];
      VUStr[ItemOutStrSize] = '\0';
      }
   else
      strcpy( VUStr, EnumAddr[V] );

   MakeOutStr( VUStr );
   strcpy( StrBuf, OutStr );
   return RIdx;
}

/*int Item_e::PutInStr( char abyte )
{ 	
	 return RIdx;
}
*/


/////////////////////////////////////////////////////////////
//add by wuhuan 2006.6.23
/*/////////////////////////////////////////////////////////////////////////
		*** Item Derived Class Item_s ***
/////////////////////////////////////////////////////////////////////////*/
Item_s::Item_s( )
{
   OutStr = new char[ItemOutStrSize+2];
   strcpy( OutStr, "未定义!" );
   Prefix[0] = Unit[0] = '\0';
   RIdx = 0;
   HighLight = -1;
   
   MaxInputStrSize = 0;
   NumItem = 0;
   ActItem = 0;
   InCharIdx=0;
   InputDataBuff[0]='\0';
   VUStr[0]='\0';
     
}

Item_s::~Item_s( )
{
   delete OutStr;
}

void Item_s::DefineItem( int Max, char *InitStr )
{
	 MaxInputStrSize = Max;
	 HighLight = strlen(Prefix) + strlen(InitStr) + 1;
	 strcpy(InputDataBuff, InitStr);
}

float Item_s::Value( void* pParStruct )
{
   return 1.0;
}

void Item_s::ValueInc( )
{

}

void Item_s::ValueDec( )
{

}

void Item_s::ValueINC( )
{
}

void Item_s::ValueDEC( )
{
   ValueDec( );
}

int Item_s::GetOutStr( char* StrBuf )
{
   //static char VUStr[16];

   if( strlen(InputDataBuff) > ItemOutStrSize )
   {
      for( int i=0; i<ItemOutStrSize; i++ ) VUStr[i] = InputDataBuff[i];
      VUStr[ItemOutStrSize] = '\0';
   }
   else
      //strcpy( VUStr, InputDataBuff );
      sprintf(VUStr,"%s ",InputDataBuff);

   MakeOutStr( VUStr );
   strcpy( StrBuf, OutStr );
   return RIdx;
}

int Item_s::PutInStr( char abyte, char mulkeyflg )
{  
	 if((mulkeyflg==1)&&(InCharIdx>0)) InCharIdx--;  //reuse the same key, the last byte position back
	
	 InputDataBuff[InCharIdx] = abyte;
	 InputDataBuff[InCharIdx+1] = '\0';

	  if(InCharIdx<MaxInputStrSize)
	  {
	 	     InCharIdx++;
	  }
	  else 
	  { 
	 		   InCharIdx=0;	
	 		   InputDataBuff[0] = '\0';
	 		   VUStr[0] = '\0';
	 		  
	 		   //LCD_Clearup( );
	   }
 		
 	 LCD_Clearup( ); 	//add by wuhuan 2006.7.11
 	  
	 HighLight = strlen(Prefix) + InCharIdx;	
	 
	 return RIdx;
}

void  Item_s::DeleteAByte(  )
{
	 if(InCharIdx>0)
	 {
	 	  InCharIdx--;
	    InputDataBuff[InCharIdx] = '\0';       
   }
   else InputDataBuff[0] = '\0';	 
   		
	 LCD_Clearup( );
	 	 
	 HighLight = strlen(Prefix) + InCharIdx;
	 
}

void Item_s::GetOutInPutStr( char* StrBuf )
{
	 strcpy( StrBuf, InputDataBuff );
}

/*void Item_s::ShowOperInfo( char *StrBuf )
{
   
   int x, y;
   
   LCD_Clearup( );  
   
   x = (128-strlen(StrBuf )*8)/2;
   y = 8;
   
   LCD_WriteString( x, y, StrBuf, 1 );
   
} */

void Item_s::ItemInit(  )
{
	 InCharIdx=0;	
	 InputDataBuff[0] = '\0';
	 VUStr[0] = '\0';
	 	
	  HighLight = strlen(Prefix) + 1;		  
	 //LCD_Clearup( );   
}

⌨️ 快捷键说明

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