Example #1
0
void 
outputBuff(FILE *stream) {

  printf(printBuff);   /* !!!! only works for FILE * = stdout */
  clearBuff();

}
Example #2
0
File: home.c Project: Greeeg/uWatch
void home_task(void)
{

	task_open();
	current_menu_item = 1;
	current_tid = 0;
	while(1)
	{
		
		if( current_tid  == 0)
		{
		clearBuff();
		
		
		setxy(2,4);
		xprint("%s\n0x%04X",mainMenu[current_menu_item].name,mainMenu[current_menu_item].task ); 
		
		lcd_xmit();
		
		}
		event_wait( buttonEvent );
		
		char button_state = button_get_pressed();
		if(current_tid == 0)
		{
			if(( button_state & BUTTON_DOWN )&&( current_menu_item > 0 ))
			{
				current_menu_item--; 
				// antmation?
			}
			else if(( button_state & BUTTON_UP )&&( current_menu_item < N_MENU -1 ))
			{
				current_menu_item++;
			}
			else if(( button_state & BUTTON_SELECT )) // no task running
			{
				// call up a new task
			
				task_create( mainMenu[current_menu_item].task, 10, 0, 0, 0 ); // should be a lower priority than this task
			
				// store tid
				current_tid = 1;//task_id_get( mainMenu[current_menu_item].task );
			
			}
		}
		else
		{ 
		if(( button_state & BUTTON_MENU ))
		{
			task_kill( mainMenu[current_menu_item].task );
			current_tid = 0;
		}
		}
		task_wait(10);
			//P2OUT ^= BIT3;
	}
	
	task_close();

}
Example #3
0
int main()
{
	setlocale(LC_ALL,"");
	//ввод данных
	int n;
	do
	{
		clearBuff();
		printf("Введите размер массива n (натуральное число) ");	
	}
	while ((!scanf_s("%d", &n)) | (n<=0));
	//создание массива со случайными значениями
	int *arr = (int*) malloc(n*sizeof(int));
	for (int i = 0; i < n; i++)
	{
		arr[i] = rand()%121; 
		printf("%d ", arr[i]);
	}	
	//перестановка значений в массиве — "колокол"
	arr = kolokol(arr,n);
	//вывод результата
	printf("\n\n");
	for (int i = 0; i < n; i++)
		printf("%d ", arr[i]);
	_getch();
	//освобождаем память
	free(arr);
	return 0;
}
Example #4
0
/*********************************
 *                               *
 *    ge_ProcessQuery            *
 *                               *
 *********************************/
static void
ge_ProcessQuery(PE_QUERY query) {

  switch (query.tag) {
  case STRNG :
    st_PrintEntryInfo(st_NameToKey(query.info.query));
    break;
  case ABOUT :
    clearBuff(); 
    appendBuff(CHARITY_CONT_PROMPT "Charity Interpreter version "CHARITY_VERSION " was written by \n"
			    CHARITY_CONT_PROMPT "     Charles Tuckey, \n"
			    CHARITY_CONT_PROMPT "     Peter Vesely and \n"
			    CHARITY_CONT_PROMPT "     Barry Yee \n"
			    CHARITY_CONT_PROMPT "from May to November, 1995.\n");
    outputBuff(stdout);
    break;
  case SHOWCOMB :
    st_PrintEntryInfo(st_NameToKey(query.info.showcomb));
    if (isFunction(query.info.showcomb)) {
      printMsg(MSG, "COMBINATOR DEFN for %s", query.info.showcomb);
      CodeTableShowComb(query.info.showcomb);
    }
    else if (isDatatype(query.info.showcomb)) {
      st_ShowDatatypeCombinators(st_NameToKey(query.info.showcomb));
    }
    else 
      ;   /* do nothing */
    break;
  case DUMPTABLE:
    st_DumpTable();
    break;
  case REPLACE:
    if (gb_ReplaceFunctions)
      printMsg(MSG, "Functions replaced silently.");
    else
      printMsg(MSG, "User prompted to replace functions.");
    printMsg(MSG, "User prompted to replace datatypes.");
    break;
  case INCLUDEDIRS:
    printMsg(MSG,"Search path is %L.",(LIST *)g_strList_IncludeDirs);
    break;
  case SHOWMEM:
    MemDisplayState();
    break;
  case QUERY:
    ge_ShowHelp(QUERY);
    break;
  default: 
    printMsg(FATAL_MSG, "ge_ProcessQuery - Invalid tag (%d)", query.tag);
  }
}
Example #5
0
/**************************
 *                        *
 * appendBuff             *
 *                        *
 **************************/
void 
appendBuff(char *str) {

  int i=0;

  if (str) {
    while (str[i]) {
      if (printBuffPtr == (MaxPrintbuff - 1))  {
	printBuff[++printBuffPtr] = 0;
	outputBuff(stdout);
	clearBuff();
      }
      printBuff[printBuffPtr++] = str[i++];
    }   /*  elihw  */
    printBuff[printBuffPtr] = 0;
  }   /*  fi  */
}
Example #6
0
/**************************
 *                        *
 *    printMsg            *
 *                        *
 **************************/
void 
printMsg(MSG_TYPE msgType, char *msg, ...) {

  va_list  ap;
  char        *p,
              *strVal,
               convStr[MAX_MSG_LENGTH],
               text[MAX_MSG_LENGTH];
  int          i=0,
               intVal;
  CT_EXPR     *coreTermLogicExpr;
  ST_TYPE_SIG *typeSigVal;
  ST_TYPE     *st_type;
  LIST        *list;
  CT_VAR_BASE *ctVarBase;

  clearBuff();
  switch (msgType) {
  case MSG :  
  case PROMPT_MSG : 
    break;
  case FATAL_MSG :
    appendBuff("*** FATAL ERROR: ");     break;
  case ERROR_MSG :
    appendBuff("*** ERROR: ");           break;
  case DEBUG_MSG :
    appendBuff("-->DEBUG: ");           break;
  case DELAYEDERROR_MSG :
    appendBuff("*** ERROR: ");       delayedErrorCount++;    break;
  case WARN_MSG :
    appendBuff("WARNING: ");         break;
  default :
    printMsg(FATAL_MSG, "printMesg - Invalid value for MSG_TYPE");
  }

  va_start(ap, msg);

  for (p=msg; *p; p++) {
    if (*p != '%') 
      text[i++] = *p;
    else {
      text[i] = 0;      i=0;
      appendBuff(text);
      switch (*++p) {
      case '%' :
	appendBuff("%");
	break;
      case 'd' :
	intVal = va_arg(ap, int);
	sprintf(convStr,"%d",intVal);
	appendBuff(convStr);
	break;
      case 'r' :
	coreTermLogicExpr = va_arg(ap, CT_EXPR*);
	_showCT_expr(coreTermLogicExpr, 0);
	break;
      case 's' :
	strVal = va_arg(ap, char*);
	appendBuff(strVal);
	break;
      case 't' :
	typeSigVal = va_arg(ap, ST_TYPE_SIG*);
	st_ShowSig(typeSigVal);
	break;
      case 'L' :  /* lists */
	list = va_arg(ap, LIST*);
	showList(list, BFALSE);
	break;
      case 'T' :
	st_type = va_arg(ap, ST_TYPE *);
	st_ShowType(st_type);
	break;
      case 'S' :	/* running out of choices */
	typeSigVal = va_arg(ap, ST_TYPE_SIG*);
	st_ShowTypeSig(typeSigVal);
	break;	
      case 'U' :	/* this is to strip out context variables */
	typeSigVal = va_arg(ap, ST_TYPE_SIG*);
	st_ShowTypeSigLessContext(typeSigVal);
	break;
      case 'V' :
        ctVarBase = va_arg(ap, CT_VAR_BASE*);
        ctShowVarBase(ctVarBase);
        break;
      default :
	printMsg(FATAL_MSG, "Invalid format specifier: %s", p);
      }   /*  hctiws  */
    }   /*  esle  */
  }   /*  rof  */

  text[i] = 0;
  appendBuff(text);     



  switch (msgType) {
  case MSG :
  case WARN_MSG :
  case DEBUG_MSG :
  case DELAYEDERROR_MSG :
    appendBuff("\n");
    outputBuff(stdout);
    break;
  case PROMPT_MSG :
    outputBuff(stdout);
    break;
  case FATAL_MSG :
    appendBuff("\n");
    outputBuff(stdout);
    exit(-1);
    break;
  case ERROR_MSG :
    appendBuff("\n");
    outputBuff(stdout);
    longjmp(topLevelEnv, 1);
    break;
  default :
    appendBuff("\n");
    outputBuff(stdout);
    printMsg(FATAL_MSG, "printMesg - Invalid value for MSG_TYPE");
  }
  

}   /*  end printMsg  */
Example #7
0
int main(void) {

    char passWord[passwords][wordLen]; //[nump][lenp]; 
    char temp[wordLen]; //string to hold characters as they are typed in
    int pwItt = 0; //index of the password being typed in by user 
    int pwStoreIndex = 0; //index for string# in passWord[][] array
    //index is used to add pws to passWord[][]

    int numCharsPrinted = 0; // counter to keep things tidy on the display 
    int modeStateEnable = 0; // enables the second state machine 
    int i = 0, j = 0;
    int match = 0;
    int count = 0;
    ANSELE = 0;
    SYSTEMConfigPerformance(40000000);
    initLCD();
    clearLCD();
    writeLCD(0b00001111, 0, 50);
    initTimer1();
    initKeypad();
    enableInterrupts();
    clearBuff(wordLen, temp);
    //initialize temp to NULL
    for (i = 0; i < wordLen; i++) {
        temp [i] = NULL;
    }
    //initialize passcode array to NULL
    for (i = 0; i < passwords; i++) {
        for (j = 0; j < wordLen; j++) {
            passWord[i][j] = NULL;
        }
    }

#ifdef TEST2
    int flag = 0;

    //Precode 2 passwords into password array and test if working

    for (i = 0; i < 2; i++) {
        for (j = 0; j < wordLen-3; j++) {
            if (flag == 0) {
                passWord[i][j] = '0'+j;
            } else {
                passWord[i][j] = '0'+j + 1;
            }
        }
        flag++;
        passWord[i][j] = '\0';
    }

#endif
    
    // initialize the state machine output 
    printStringLCD("Enter");

#ifdef run  
    while (1) {

        //<><><><>  button de bounce stuff  <><><><><><><><><><><><><><><><><><><><><><>        
        switch (state) {
            case printKey:
                modeStateEnable = 1;
                temp[pwItt] = keyScanned;
                pwItt++;
                state = waitForRelease;
                break;

            case scanKey:
                keyScanned = scanKeypad();
                state = printKey;
                break;

            case dbPress:
                delayUs(DBDelayTime);
                state = scanKey;
                break;

            case dbRelease:
                delayUs(DBDelayTime);
                state = waitForPress;
                break;

            case waitForPress:
                //enableInterrupts();
                break;

            case waitForRelease:
                // enableInterrupts(); 
                break;
        }
        //<><><><> END button de bounce stuff  <><><><><><><><><><><><><><><><><><><><><><>  

        //!!! TODO !!! every exit branch of the state machine WILL:
        //        enable/disable interrupts
        //        set the next state (even if it does not change)
        //        set modeStateEnable to 1 or 0

        //    THIS will help with debugging  

        //<><><><>  Mode setting state machine <><><><><><><><><><><><><><><><><><><><><><>       
        if (modeStateEnable == 1) { // need to ensure this is correct...
            disableInterrupts(); //messing with printing?
            modeStateEnable = 0; //wait for key input
            // the newKeyPressed variable gets changed to 1 everytime a key press is detected    
            switch (modeState) {
                case firstStar: //interrupts are ENABLED DELETEME
                    if (temp[1] == '*') {
                        modeState = set; // the state that allows you to add pws 
                        modeStateEnable = 0; //wait for new key to be pressed
                        clearLCD();
                        printStringLCD("Set Mode");
                        moveCursorLCD(2, 1);
                        enableInterrupts();
                    } else {
                        modeState = dispBad;
                        modeStateEnable = 1; //goto state
                        disableInterrupts();
                    }
                    break;

                case dispGood: //interrupts are DISABLED DELETEME
                    printOutput("Good");
                    clearLCD();
                    printStringLCD("Enter"); //prompt enter state
                    clearBuff(wordLen, temp); // clear the temp string 
                    pwItt = 0; // reset the pw itterator 
                    modeState = dispEnter; //switch state
                    modeStateEnable = 0; //wait for new key to be pressed
                    enableInterrupts();
                    break;

                case dispBad: //interrupts are DISABLED DELETEME
                    printOutput("Bad");
                    clearLCD();
                    printStringLCD("Enter"); // prompt enter state
                    modeState = dispEnter; // switch state
                    clearBuff(wordLen, temp); // clear the temp string 
                    pwItt = 0; // reset the pw itterator 
                    modeStateEnable = 0; // wait for new key to be pressed
                    enableInterrupts();
                    break;

                case dispEnter: //interrupts are DISABLED DELETEME
                    clearLCD();
                    printStringLCD("Enter");
                    moveCursorLCD(2, 1);
                    printStringLCD(temp); // print the characters as they are entered 
                    if (pwItt == 4) {


                        if (checkValid(temp, passWord) == 0) {
                            //if( match == 0){ 
                            modeState = dispBad; // 0 means invalid pw
                            modeStateEnable = 1; //goto state
                            disableInterrupts();
                        } else {
                            modeState = dispGood; //1 means valid pw
                            modeStateEnable = 1; //goto state
                            disableInterrupts();
                            printCharLCD('&');
                        }
                    } else if (temp[0] == '*') {
                        modeState = firstStar;
                        modeStateEnable = 0; //wait for new key to be pressed 
                        enableInterrupts();
                    } else if (temp[0] == '#') {
                        modeState = dispBad;
                        modeStateEnable = 1; //continue
                        disableInterrupts();
                    } else {
                        modeState = dispEnter;
                        modeStateEnable = 0; //wait for new key to be pressed 
                        enableInterrupts();
                    }

                    break;
                case dispValid://-
                    printOutput("Valid   ");
                    clearLCD();
                    printStringLCD("Enter");

                    if (addNewPw(temp, passWord) == 0) { // if password is not in list 
                        //if(match == 0){           // if password is not in list 
                        strcpy(passWord[pwStoreIndex], temp); // add it
                        pwStoreIndex++; // increment itterator 
                    }
                    modeState = dispEnter;
                    clearBuff(wordLen, temp); // clear the temp string 
                    pwItt = 0; // reset the pw itterator
                    modeStateEnable = 0; //wait for new key to be pressed 
                    enableInterrupts();
                    break;

                case dispInvalid://-
                    printOutput("Invalid ");
                    clearLCD();
                    printStringLCD("Enter");
                    modeState = dispEnter;
                    clearBuff(wordLen, temp); // clear the temp string 
                    pwItt = 0; // reset the pw itterator 
                    modeStateEnable = 0; //wait for new key to be pressed 
                    enableInterrupts();
                    break;

                case set:

                    printCharLCD(keyScanned); // might work better to press key pressed 
                    if (keyScanned == '*' || keyScanned == '#') { // if an invalid key was entered 
                        modeState = dispInvalid; // if new pw is not valid 
                        modeStateEnable = 1; //next state needs to be executed
                        disableInterrupts();
                    } else if (pwItt == 6) { // pw == "**xxxx"...
                        temp[0] = temp[2];
                        temp[1] = temp[3]; // remove leading "**" 
                        temp[2] = temp[4];
                        temp[3] = temp[5];
                        temp[4] = NULL;
                        temp[5] = NULL;

                        modeState = dispValid;
                        modeStateEnable = 1; //next state needs to be executed
                        disableInterrupts();
                    } else {
                        modeStateEnable = 0; //next state needs to be executed
                        enableInterrupts();
                    }

                    break;
            }
        }
        //<><><><> END Mode setting state machine <><><><><><><><><><><><><><><><><><><><><><>   

    }

    return 0;
}