void applicationTask()
{
    uint8_t currentLedState;
    uint8_t buttonSelect;
    uint8_t sliderValue;
    uint16_t sliderLvl;
    uint8_t sliderLvlTxt[15];
    uint8_t sliderValueTxt[15];
    
    buttonSelect = capsense_readData( _CAPSENSE_CS_READ_STATUS0 );
    sliderValue = capsense_readDataBytes( _CAPSENSE_CS_READ_RAW );
    capsense_writeData( _CAPSENSE_OUTPUT_PORT0, currentLedState );
    Delay_100ms();

    if ( buttonSelect == 8 )
    {
        currentLedState ^= 0x01;
        Delay_100ms();
    }
    if ( buttonSelect == 16 )
    {
        currentLedState ^= 0x02;
        Delay_100ms();
    }
    if ( buttonSelect == 24 )
    {
        currentLedState = ~currentLedState;
        Delay_100ms();
    }

    sliderLvl = capsense_getSliderLvl();

    if ( sliderValue != 0 )
    {
        mikrobus_logWrite("Slider lvl. ", _LOG_TEXT);
        LongToStr( sliderLvl, sliderLvlTxt );
        mikrobus_logWrite( sliderLvlTxt, _LOG_LINE );

        mikrobus_logWrite("Slider value", _LOG_TEXT);
        LongToStr( sliderValue, sliderValueTxt );
        mikrobus_logWrite( sliderValueTxt, _LOG_LINE );
        mikrobus_logWrite( "", _LOG_LINE );

        Delay_100ms();
    }
}
/*
** ===================================================================
**     Method      :  Term1_SendNum (component Term)
**     Description :
**         Send number to terminal.
**     Parameters  :
**         NAME            - DESCRIPTION
**         number          - Long number
**     Returns     : Nothing
** ===================================================================
*/
void Term1_SendNum(int32_t number)
{
  char_t str[15];                      /* Temporary variable */
  uint8_t i=0U;                        /* Temporary variable */

  LongToStr(str, number);              /* Conversion number to the string */
  while (str[i] != '\0') {
    while (Inhr1_SendChar((Inhr1_TComData)str[i]) == ERR_TXFULL){} /* Send char */
    i++;                               /* Increase the variable */
  }
}
Beispiel #3
0
void main() {


   unsigned short kp;
   int nscale=0;
   char txt[3];

        //initializing scale
   char scale[3][3];
   scale[0][0]='H';scale[0][1]='z';scale[0][2]=' ';
   scale[1][0]='K';scale[1][1]='H';scale[1][2]='z';
   scale[2][0]='M';scale[2][1]='H';scale[2][2]='z';
   TRISA= 0;
   TRISB=0;


  Lcd_Init();                              // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off
  Lcd_Out(1, 1, "Freq:");                  // Write message text on LCD
  Lcd_Out(1, 14, "Hz");
  Lcd_Out(2,1,"Signal Generator");
  Keypad_Init();                           // Initialize Keypad
  while(1)
  {
          int freq_array[3]={0,0,0};
          unsigned long freq;

          kp=0;
          kp=Keypad_Key_Click();

          if(kp!=0 && kp!=1 && kp!=2)         //when any number is pressed
          {
                freq_array[0]=freq_array[1];
                freq_array[1]=freq_array[2];
                freq_array[2]=keyidentifier(kp);
                freq=100*freq_array[2]+10*freq_array[1]+freq_array[0];
                LongToStr(freq,txt);
                Lcd_Out(1,6,txt);
          }

          if(kp==2)         //when scale key pressed
          {
                if(nscale==2){
                        nscale=0;
                }
                else
                {
                        nscale=nscale+1;
                }
                Lcd_Out(1,14,scale[nscale]);
          }

          if(kp==1)         //when start is pressed
          {
                  if(nscale==2)
                  {
                          freq=freq*1000000;
                  }
                  else if(nscale==1)
                  {
                          freq=freq*1000;
                  }
                  else
                  {
                          freq=freq;
                  }

                  set_keyword(freq);
                  send_data_ad9850();
          }

  }

}
// THINK LOW Memory condition!  This is called internally early to get at least some information and suggestion to User.
void _prv_ExceptionMessage( const unsigned int	context,
							const unsigned int  threadIdx,		// use MAIN_THREAD_INDEX or actual threadIdx
							const unsigned int	exType, 
							const string		ex_what,
							const CCodeCounter * pCounter )		// Only need this for Parser dumps
{
	bool	isLowMemory = false;
	bool	mustExit = false;

	string	tempMsg;

	// Check for the REALLY Exciting Exceptions
	if ( exType == EXCEPTION_BAD_ALLOC )
		isLowMemory = true;

	if ( exType == EXCEPTION_STD_EXCEPTION )
	{
		// STD library Exception
		if ( ex_what.compare( "bad allocation" ) == 0 )
			isLowMemory = true;

	}

// Could be this was called from an Exception handler already.
// So catch any Exceptions here quietly.  These are not the original problem's location.
try
{
	if ( false == isLowMemory )
		return;

	printf( "\n   LOW on RAM exception " );
	if ( EXCEPTION_HANDLER_PARSER == context )
	{
		printf( "while parsing:\n%s\n", 
			pCounter->parse_file_name.c_str() );
	}
	else 
	if ( EXCEPTION_HANDLER_THREAD == context )
	{
		printf( "from a Thread.\n" );
	}
	else
	{
		printf( "from UCC application level.\n" );
	}

	// 


	// Output using predefined strings to help prevent possible recursive LOW Memory exceptions.
	// Also use C style code rather than C++ objects to reduce Memory use here!
	if ( isDiff && duplicate_threshold >= 0.0 )
	{
		printf( "\n\nUCC is LOW on Memory running Difference with Duplication checking.\nYou may try Differencing alone and do separate Duplicate checking for just 1 Baseline at a time.\n" );
	}
	else if ( duplicate_threshold >= 0.0 )
	{
		printf( "\n\nUCC is LOW on Memory and running Duplicate checking.\nYou can try a smaller list of files to process.\n" );
	}
	else if ( workThreadsCount >= MIN_UCC_THREAD_COUNT )
	{
		printf( "\n\nUCC is LOW on Memory and running with Threads.\nYou can try using fewer or NO Threads.\nOr you can keep Threads but have a smaller list of files to process.\n" );
	}
	else
		printf( "\n\nUCC is LOW on Memory.\nYou can try a smaller list of files to process.\n" );

	// Show the total number of files, Largest file, total sizes of all files.
	// Exactly where we are with processing those may be tricky to get here.
	if ( isDiff )
	{
		printf( "Baseline A has  %ld  files\nBaseline B has  %ld  files\n   Total files  %ld\n", 
				(long)numFilesInA, (long)numFilesInB, (long)numFilesInA + (long)numFilesInB );
		printf( "Baseline A largest file is  %lld  Bytes\nBaseline B largest file is  %lld  Bytes\n", 
				(long long)largestFileSizeA, (long long)largestFileSizeB );
	//	printf( "If all files were loaded into RAM (as previous UCC versions did):\n" );
	#if defined(__MINGW32__)
		printf( "Baseline A total sizes all files  %ld  Bytes\nBaseline B total sizes all files  %ld  Bytes.\n               Total for both is  %ld\n", 
	#else
		printf( "Baseline A total sizes all files  %lld  Bytes\nBaseline B total sizes all files  %lld  Bytes.\n               Total for both is  %lld\n", 
	#endif
			(long long)totalFileSizesA, (long long)totalFileSizesB, (long long)totalFileSizesA + (long long)totalFileSizesB );
	}
	else
	{
		ShowFileSetStats( true );
	}


	int				errorRet;
	bool			validate = true;
	unsigned int	heap_count = 0;
	unsigned long	start_block_count = 0L;
	unsigned long long	start_total_sizes = 0L;

	HeapInUse( errorRet, heap_count, start_block_count, start_total_sizes, validate );

	if ( start_block_count > 1 )
	{
		// Got some valid? Heap stats.
		string	heapStr = "\nHeap Memory in Use:\n";
		string	heapCountStr;
		IntToStr( (int)heap_count, heapCountStr );
		string	blkCountStr;
		LongToStr( (long)start_block_count, blkCountStr );
		string	totalMemStr;
		LongLongToStr( (long long)start_total_sizes, totalMemStr );
		heapStr += "There are " + heapCountStr + " Heaps.\n";
		heapStr += "There are " + blkCountStr + " blocks for a total of " + totalMemStr + " Bytes of Memory.\n";

		cout << heapStr;
		userIF->AddError( heapStr, true );
	}

	// Try calling a Stack Dump here.  May not be able to finish.
	string dump;
	_prv_StackDump( dump, context, threadIdx, exType, ex_what, pCounter );
	userIF->AddError( dump, true );
}
/*!
* 1. Function Description: 
*    Sets a string with a possibly LONG formatted Stack Dump multiline message
*
* 2. Parameters:
*    dumpStr:	IN/OUT	reference to string to set
*    context:	IN		where in UCC code is the Stack Dump wanted
*    threadIdx:	IN		which thread wanted the Stack Dump
*    exType:	IN		what kind of Exception
*    ex_what:	IN		some text provided by code that threw the Exception
*    pCounter:	IN		pointer to base class of Parser that had the Exception
*    useNative:	IN		use Native platform support for Stack Dump
*
* 3. Creation Time and Owner: 
*    Version 2015.12
*/
void FormatStackDump( string & stackStr, const unsigned int context, 
					const unsigned int threadIdx, const unsigned int exType, 
					const string ex_what, const CCodeCounter * pCounter,
					const bool useNative )
{
	bool	isLowMemory = false;

	// Check for the REALLY Exciting Exceptions
	if ( exType == EXCEPTION_BAD_ALLOC )
		isLowMemory = true;

	stackStr = "!!! UCC Stack Dump ...\n";

	time_t	timeNow;
	time( &timeNow );

	// double	total_seconds = difftime( timeNow, timeStart ) + 0.5;
	string	runningTime;
	ShowTiming( runningTime, timeStart, timeNow, true, false, false );

	stackStr += "Command line:\n" + cmdLine + "\n";
	stackStr += runningTime + "\n";

	if ( isNativeStackDumpAvailable && useNative )
	{
		// Call Native support here

		// for now fall through
	}

	string	threadIdxStr;
	IntToStr( (int)threadIdx, threadIdxStr );


	string	phyLineNumStr;
	string	logLineNumStr;

	switch( context )
	{
		case EXCEPTION_HANDLER_APP:

			break;
		case EXCEPTION_HANDLER_THREAD:
			// TODO:  Add some details for Thread context Stack Dumps


			break;
		case EXCEPTION_HANDLER_PARSER:
			stackStr += pCounter->language_name;
			stackStr += "  parser is running from ";
			if ( MAIN_THREAD_INDEX == threadIdx )
				stackStr += "the Main thread.\n";
			else
			{
				stackStr += "Thread " + threadIdxStr + "\n";
			}
			stackStr += "File being parsed:\n";
			stackStr += pCounter->parse_file_name + "\n";
			
			LongToStr( (long)pCounter->currentPhyLine, phyLineNumStr );
			stackStr += "Physical line " + phyLineNumStr + " being parsed:\n";
			stackStr += pCounter->parse_physical_line + "\n";
			stackStr += pCounter->parse_physical_line_comments + "\n";
			
			LongToStr( (long)pCounter->currentLSrcLine, logLineNumStr );
			stackStr += "Logical (source) line " + logLineNumStr + " being parsed:\n";
			stackStr += pCounter->parse_logical_line + "\n";
			stackStr += "UCC  " + pCounter->language_name + "  parser code (approximate) Stack Dump:\n";
			stackStr += "CCodeCounter::CountSLOC  (base class method)";
			
			FormatStackCalls( stackStr, pCounter );

			break;
		default:
			stackStr += "Stack Dump interface error.  Invalid context";
			break;
	}

	// Get a fast? check of the Heap  Only works for Windows now.
	int				errorRet;
	bool			call_again = true;
	bool			validate = true;
	unsigned int	heap_count = 0;
	unsigned long	start_block_count = 0;
	unsigned long long	start_total_sizes = 0L;

	HeapInUse( errorRet, heap_count, start_block_count, start_total_sizes, validate );
	if ( ( errorRet == 1 ) || ( errorRet < 0 ) )
		call_again = false;

	if ( start_block_count > 1 )
	{
		// Got some valid? Heap stats.
		string	heapStr = "\nHeap Memory in Use:\n";
		string	heapCountStr;
		IntToStr( (int)heap_count, heapCountStr );
		string	blkCountStr;
		LongToStr( (long)start_block_count, blkCountStr );
		string	totalMemStr;
		LongLongToStr( (long long)start_total_sizes, totalMemStr );
		heapStr += "There are " + heapCountStr + " Heaps.\n";
		heapStr += "There are " + blkCountStr + " blocks for a total of " + totalMemStr + " Bytes of Memory.\n";

		stackStr += heapStr;
	}

	return;
}
Beispiel #6
0
BOOL CADORecordset::GetFieldValue(int nIndex, CString& strValue, CString strDateFormat)
{
	CString str;
	_variant_t vtFld;
	_variant_t vtIndex;

	vtIndex.vt = VT_I2;
	vtIndex.iVal = nIndex;
	
	try
	{
		vtFld = m_pRecordset->Fields->GetItem(vtIndex)->Value;
		switch(vtFld.vt) 
		{
		case VT_R4:
			str = DblToStr(vtFld.fltVal);
			break;
		case VT_R8:
			str = DblToStr(vtFld.dblVal);
			break;
		case VT_BSTR:
			str = vtFld.bstrVal;
			break;
		case VT_I2:
		case VT_UI1:
			str = IntToStr(vtFld.iVal);
			break;
		case VT_INT:
			str = IntToStr(vtFld.intVal);
			break;
		case VT_I4:
			str = LongToStr(vtFld.lVal);
			break;
		case VT_UI4:
			str = ULongToStr(vtFld.ulVal);
			break;
		case VT_DECIMAL:
			{
			//Corrected by José Carlos Martínez Galán
			double val = vtFld.decVal.Lo32;
			val *= (vtFld.decVal.sign == 128)? -1 : 1;
			val /= pow(10, vtFld.decVal.scale); 
			str = DblToStr(val);
			}
			break;
		case VT_DATE:
			{
				COleDateTime dt(vtFld);
				
				if(strDateFormat.IsEmpty())
					strDateFormat = _T("%Y-%m-%d %H:%M:%S");
				str = dt.Format(strDateFormat);
			}
			break;
		case VT_CY:		//Added by John Andy Johnson!!!
			{
				vtFld.ChangeType(VT_R8);
 
				CString str;
				str.Format(_T("%f"), vtFld.dblVal);
 
				_TCHAR pszFormattedNumber[64];
 
				//	LOCALE_USER_DEFAULT
				if(GetCurrencyFormat(
						LOCALE_USER_DEFAULT,	// locale for which string is to be formatted 
						0,						// bit flag that controls the function's operation
						str,					// pointer to input number string
						NULL,					// pointer to a formatting information structure
												//	NULL = machine default locale settings
						pszFormattedNumber,		// pointer to output buffer
						63))					// size of output buffer
				{
					str = pszFormattedNumber;
				}
			}
			break;
		case VT_BOOL:
			str = vtFld.boolVal == VARIANT_TRUE? 'T':'F';
			break;
		case VT_EMPTY:
		case VT_NULL:
			str.Empty();
			break;
		default:
			str.Empty();
			return FALSE;
		}
		strValue = str;
		return TRUE;
	}
	catch(_com_error &e)
	{
		dump_com_error(e);
		return FALSE;
	}
}
Beispiel #7
0
BOOL CADOParameter::GetValue(CString& strValue, CString strDateFormat)
{
	_variant_t vtVal;
	CString strVal;

	try
	{
		vtVal = m_pParameter->Value;
		switch(vtVal.vt) 
		{
		case VT_R4:
			strVal = DblToStr(vtVal.fltVal);
			break;
		case VT_R8:
			strVal = DblToStr(vtVal.dblVal);
			break;
		case VT_BSTR:
			strVal = vtVal.bstrVal;
			break;
		case VT_I2:
		case VT_UI1:
			strVal = IntToStr(vtVal.iVal);
			break;
		case VT_INT:
			strVal = IntToStr(vtVal.intVal);
			break;
		case VT_I4:
			strVal = LongToStr(vtVal.lVal);
			break;
		case VT_DECIMAL:
			{
			//Corrected by José Carlos Martínez Galán
			double val = vtVal.decVal.Lo32;
			val *= (vtVal.decVal.sign == 128)? -1 : 1;
			val /= pow(10, vtVal.decVal.scale); 
			strVal = DblToStr(val);
			}
			break;
		case VT_DATE:
			{
				COleDateTime dt(vtVal);

				if(strDateFormat.IsEmpty())
					strDateFormat = _T("%Y-%m-%d %H:%M:%S");
				strVal = dt.Format(strDateFormat);
			}
			break;
		case VT_EMPTY:
		case VT_NULL:
			strVal.Empty();
			break;
		default:
			strVal.Empty();
			return FALSE;
		}
		strValue = strVal;
		return TRUE;
	}
	catch(_com_error& e)
	{
		dump_com_error(e);
		return FALSE;
	}
}
Beispiel #8
0
BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, wstring& strValue, wstring strDateFormat)
{
	wstring str;
	_variant_t vtFld;

	try
	{
		vtFld = m_pRecordset->Fields->GetItem(lpFieldName)->Value;
		switch(vtFld.vt) 
		{
		case VT_R4:
			str = DblToStr(vtFld.fltVal);
			break;
		case VT_R8:
			str = DblToStr(vtFld.dblVal);
			break;
		case VT_BSTR:
			str = vtFld.bstrVal;
			break;
		case VT_I2:
		case VT_UI1:
			str = IntToStr(vtFld.iVal);
			break;
		case VT_INT:
			str = IntToStr(vtFld.intVal);
			break;
		case VT_I4:
			str = LongToStr(vtFld.lVal);
			break;
		case VT_UI4:
			str = ULongToStr(vtFld.ulVal);
			break;
		case VT_DECIMAL:
			{
			double val = vtFld.decVal.Lo32;
			val *= (vtFld.decVal.sign == 128)? -1 : 1;
			val /= pow((float)10, vtFld.decVal.scale); 
			str = DblToStr(val);
			}
			break;
		case VT_DATE:
			{
#if 0 /*lanshh **/
				COleDateTime dt(vtFld);

				if(strDateFormat.IsEmpty())
					strDateFormat = _T("%Y-%m-%d %H:%M:%S");
				str = dt.Format(strDateFormat);
#endif
			}
			break;
#if 0
		case VT_CY:		
			{
				vtFld.ChangeType(VT_R8);
 
				wstring str;
				str.Format(_T("%f"), vtFld.dblVal);
 
				_TCHAR pszFormattedNumber[64];
 
				//	LOCALE_USER_DEFAULT
				if(GetCurrencyFormat(
						LOCALE_USER_DEFAULT,	// locale for which string is to be formatted 
						0,						// bit flag that controls the function's operation
						str,					// pointer to input number string
						NULL,					// pointer to a formatting information structure
												//	NULL = machine default locale settings
						pszFormattedNumber,		// pointer to output buffer
						63))					// size of output buffer
				{
					str = pszFormattedNumber;
				}
			}
			break;
#endif
		case VT_EMPTY:
		case VT_NULL:
            str.clear();
			break;
		case VT_BOOL:
			str = vtFld.boolVal == VARIANT_TRUE? _T('T'):_T('F');
			break;
		default:
            str.clear();
			return FALSE;
		}
		strValue = str;
		return TRUE;
	}
	catch(_com_error &e)
	{
		dump_com_error(e);
		return FALSE;
	}
}
Beispiel #9
0
BOOL CADOParameter::GetValue(wstring& strValue, wstring strDateFormat)
{
	_variant_t vtVal;
	wstring strVal = _T("");

	try
	{
		vtVal = m_pParameter->Value;
		switch(vtVal.vt) 
		{
		case VT_R4:
			strVal = DblToStr(vtVal.fltVal);
			break;
		case VT_R8:
			strVal = DblToStr(vtVal.dblVal);
			break;
		case VT_BSTR:
			strVal = vtVal.bstrVal;
			break;
		case VT_I2:
		case VT_UI1:
			strVal = IntToStr(vtVal.iVal);
			break;
		case VT_INT:
			strVal = IntToStr(vtVal.intVal);
			break;
		case VT_I4:
			strVal = LongToStr(vtVal.lVal);
			break;
		case VT_DECIMAL:
			{
			double val = vtVal.decVal.Lo32;
			val *= (vtVal.decVal.sign == 128)? -1 : 1;
			val /= pow((float)10, vtVal.decVal.scale); 
			strVal = DblToStr(val);
			}
			break;
		case VT_DATE:
			{
#if USEAFX
				COleDateTime dt(vtVal);

                if(strDateFormat.empty())
					strDateFormat = _T("%Y-%m-%d %H:%M:%S");
                strVal = dt.Format(strDateFormat.c_str());
#endif
			}
			break;
		case VT_EMPTY:
		case VT_NULL:
			strVal.empty();
			break;
		default:
            strVal.empty();
			return FALSE;
		}
		strValue = strVal;
		return TRUE;
	}
	catch(_com_error& e)
	{
		dump_com_error(e);
		return FALSE;
	}
}
//=============================>>> l_to_a   <<<============================
  void IntToStr(int intg, char* str)
  {  // convert int intg to char string in str

    LongToStr((long)intg, str);
  }
Beispiel #11
0
BOOL GetFieldValue(_CommandPtr pCmd, const char* lpFieldName, char* strValue, int size, bool/* autoTrim*/)
{
	//CString str = _T("");
	//char str[50] = "";
	_variant_t vtFld;
	_bstr_t b;

	try
	{
		vtFld = pCmd->Parameters->GetItem(lpFieldName)->Value;
		switch(vtFld.vt) 
		{
		case VT_R4:
			DblToStr(vtFld.fltVal, strValue, 50);
			break;
		case VT_R8:
			DblToStr(vtFld.dblVal, strValue, 50);
			break;
		case VT_BSTR:
			b = vtFld.bstrVal;
			strcpy(strValue, b);
			//memcpy(strValue, (char*)vtFld.bstrVal, sizeof(vtFld.bstrVal));

			break;
		case VT_I2:
		case VT_UI1:
			IntToStr(vtFld.iVal, strValue, size);
			break;
		case VT_INT:
			IntToStr(vtFld.intVal, strValue, size);
			break;
		case VT_I4:
			LongToStr(vtFld.lVal, strValue, size);
			break;
		case VT_UI4:
			ULongToStr(vtFld.ulVal, strValue, size);
			break;
		case VT_DECIMAL:
			{
				//Corrected by Jos?Carlos Martínez Galán
				double val = vtFld.decVal.Lo32;
				val *= (vtFld.decVal.sign == 128)? -1 : 1;
				val /= pow(10, vtFld.decVal.scale); 
				DblToStr(val, strValue, size);
			}
			break;
		case VT_DATE:
			//{
			//	COleDateTime dt(vtFld);

			//	if( 0 == strlen(strDateFormat) )
			//		strDateFormat = "%Y-%m-%d %H:%M:%S";
			//	sprintf(str, strDateFormat, );
			//	strcpy(str, dt.Format(strDateFormat));
			//}
			break;
		case VT_EMPTY:
		case VT_NULL:
			//str.Empty();
			break;
		case VT_BOOL:
			strValue[0] = vtFld.boolVal == VARIANT_TRUE? 'T':'F';
			break;
		default:
			return FALSE;
		}

		//strcpy(strValue, str);
		return TRUE;
	}
	catch(_com_error &e)
	{
		PrintComError(e);
		return FALSE;
	}
}
Beispiel #12
0
void TIniFile::WriteLong(const wxString &Section, const wxString &Ident,
  long Value)
{
	WriteString(Section, Ident, LongToStr(Value));
}
Beispiel #13
0
long TIniFile::ReadLong(const wxString &Section, const wxString &Ident,
	long Default)
{
	return StrToLong(ReadString(Section, Ident, LongToStr(Default)));
}