Exemplo n.º 1
0
void PrintMebane(void)  //prints MEBANE-LABS ((4x20 loop for scroll)
{	
	PrintChar(0x05);
	//PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x4d);
	PrintChar(0x45);
	PrintChar(0x42);
	PrintChar(0x41);
	PrintChar(0x4e);
	PrintChar(0x45);
	
	
	PrintChar(0x06);
	PrintChar(0x06);
	
	PrintChar(0x06);
	PrintChar(0x4c);
	PrintChar(0x41);
	PrintChar(0x42);
	PrintChar(0x53);
	
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	
	PrintChar(0x37);
	PrintChar(0x2d);
	PrintChar(0x32);
	PrintChar(0x39);
	PrintChar(0x2d);
	
	PrintChar(0x32);
	PrintChar(0x30);
	PrintChar(0x31);
	PrintChar(0x31);
	
	
	_delay_ms(5000);



}
Exemplo n.º 2
0
static byte AskPassword (Password &password, int& pim)
{
	size_t pos = 0;
	byte scanCode;
	byte asciiCode;
	byte hidePassword = 1;

	pim = 0;

	Print ("Enter password");
	Print (PreventNormalSystemBoot ? " for hidden system:\r\n" : ": ");

	while (true)
	{
		asciiCode = GetKeyboardChar (&scanCode);

		switch (scanCode)
		{
		case TC_BIOS_KEY_ENTER:
			password.Length = pos;
			Print ("\r");
			if (!PreventNormalSystemBoot)
				Print ("Enter password: "******"PIM: ");

		while (true)
		{
			asciiCode = GetKeyboardChar (&scanCode);

			switch (scanCode)
			{
			case TC_BIOS_KEY_ENTER:
				Print ("\rPIM: ");
				pos =0;
				while (pos < MAX_PIM)
				{
					PrintChar ('*');
					pos++;
				}

				ClearBiosKeystrokeBuffer();
				PrintEndl();

				return TC_BIOS_KEY_ENTER;

			case TC_BIOS_KEY_BACKSPACE:
				if (pos > 0)
				{
					if (pos < MAX_PIM)
						PrintBackspace();
					else
						PrintCharAtCursor (' ');

					--pos;
					pim /= 10;
				}
				continue;

			case TC_BIOS_KEY_F5:
				hidePassword ^= 0x01;
				continue;

			default:
				if (scanCode == TC_BIOS_KEY_ESC || IsMenuKey (scanCode))
				{
					burn (password.Text, sizeof (password.Text));
					ClearBiosKeystrokeBuffer();

					PrintEndl();
					return scanCode;
				}
			}

			if (!IsDigit (asciiCode) || pos == MAX_PIM)
			{
				Beep();
				continue;
			}

			pim = 10*pim + (asciiCode - '0');
			pos++;

			if (hidePassword) asciiCode = '*';
			if (pos < MAX_PIM)
				PrintChar (asciiCode);
			else
				PrintCharAtCursor (asciiCode);
		}
	}
}
Exemplo n.º 3
0
    void NVMWrite( WORD dest, BYTE *src, BYTE count )
    {
        BYTE    bytesOnPage;
        BYTE    bytesOnPageCounter;
    	#if !defined(__C30__)
        	BYTE    oldGIEH;
    	#endif
        BYTE    *srcCounter;
        BYTE    status;
        WORD    writeStart;

        if (!count)
        {
            return;
        }

        #if !defined(__C30__)
            oldGIEH = 0;
            if ( INTCONbits.GIEH )
            {
                oldGIEH = 1;
            }
            INTCONbits.GIEH = 0;
        #endif


        // Make sure the chip is unlocked.
        SPISelectEEPROM();                  // Enable chip select
        SPIPut( SPIWRSR );                  // Send WRSR - Write Status Register opcode
        SPIPut( 0x00 );                     // Write the status register
        SPIUnselectEEPROM();                // Disable Chip Select

        #ifdef ENABLE_DEBUG
            UART2Put('w');
            PrintChar( (BYTE)(((WORD)dest>>8)&0xFF) );
            PrintChar( (BYTE)((WORD)dest&0xFF) );
            UART2Put('-');
            PrintChar( count );
        #endif

        writeStart = dest;
        while (count)
        {
            bytesOnPage = EEPROM_PAGE_SIZE - (writeStart & (EEPROM_PAGE_SIZE-1));
            if (bytesOnPage > count)
            {
                bytesOnPage = count;
            }

            #ifdef PRINT_MULTIPLE_WRITE_ATTEMPTS
                flag = 0;
            #endif
            CLRWDT();

            #if defined(VERIFY_WRITE)
                while (ComparePage( writeStart, src, bytesOnPage ))
            #elif defined(CHECK_BEFORE_WRITE)
                if (ComparePage( writeStart, src, bytesOnPage ))
            #endif
            {
                #ifdef PRINT_MULTIPLE_WRITE_ATTEMPTS
                    flag = 1;
                #endif
                SPISelectEEPROM();                          // Enable chip select
                SPIPut( SPIWREN );                          // Transmit the write enable instruction
                SPIUnselectEEPROM();                        // Disable Chip Select to enable Write Enable Latch

                SPISelectEEPROM();                          // Enable chip select
                SPIPut( SPIWRITE );                         // Transmit write instruction
                SPIPut( (BYTE)((writeStart>>8) & 0xFF) );   // Transmit address high byte
                SPIPut( (BYTE)((writeStart) & 0xFF) );      // Trabsmit address low byte

                // Loop until the required number of bytes have been written or
                // until the maximum number of bytes per write cycle have been written
                bytesOnPageCounter = bytesOnPage;
                srcCounter = src;
                do
                {
                    SPIPut (*srcCounter++);                    // Write the source byte
                    bytesOnPageCounter--;
                }
                while (bytesOnPageCounter);

                // Disable chip select to start write cycle.  We'll let it finish in the background if we can.
                SPIUnselectEEPROM();

                // Wait for the write to complete.  We have to wait here, because we can't
                // do a read of the memory while the write is in progress.
                do
                {
                    SPISelectEEPROM();                  // Enable chip select
                    SPIPut( SPIRDSR );                  // Send RDSR - Read Status Register opcode
                    status = SPIGet();;                 // Read the status register
                    SPIUnselectEEPROM();                // Disable Chip Select
                }
                while (status & WIP_MASK);
            }

            count -= bytesOnPage;
            writeStart += bytesOnPage;
            src = &src[bytesOnPage];
        }

        #if !defined(__C30__)
            if (oldGIEH)        // If interrupts were enabled before this function
            {
                INTCONbits.GIEH = 1;       // re-enable them
            }
        #endif

        #ifdef ENABLE_DEBUG
            UART2Put('.');
            UART2PutROMString((ROM char * const)"\r\n");
        #endif
    }
Exemplo n.º 4
0
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//
// PrintString - Print out a serial string
//
// Inputs:      Text string to print
//
// Outputs:     None.
//
void PrintString(const char *String) {

    while( *String )
        PrintChar(*String++);
    }
Exemplo n.º 5
0
/**
  Get string or password input from user.

  @param  MenuOption        Pointer to the current input menu.
  @param  Prompt            The prompt string shown on popup window.
  @param  StringPtr         Old user input and destination for use input string.

  @retval EFI_SUCCESS       If string input is read successfully
  @retval EFI_DEVICE_ERROR  If operation fails

**/
EFI_STATUS
ReadString (
  IN     UI_MENU_OPTION              *MenuOption,
  IN     CHAR16                      *Prompt,
  IN OUT CHAR16                      *StringPtr
  )
{
  EFI_STATUS              Status;
  EFI_INPUT_KEY           Key;
  CHAR16                  NullCharacter;
  UINTN                   ScreenSize;
  CHAR16                  Space[2];
  CHAR16                  KeyPad[2];
  CHAR16                  *TempString;
  CHAR16                  *BufferedString;
  UINTN                   Index;
  UINTN                   Index2;
  UINTN                   Count;
  UINTN                   Start;
  UINTN                   Top;
  UINTN                   DimensionsWidth;
  UINTN                   DimensionsHeight;
  UINTN                   CurrentCursor;
  BOOLEAN                 CursorVisible;
  UINTN                   Minimum;
  UINTN                   Maximum;
  FORM_BROWSER_STATEMENT  *Question;
  BOOLEAN                 IsPassword;

  DimensionsWidth  = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;
  DimensionsHeight = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;

  NullCharacter    = CHAR_NULL;
  ScreenSize       = GetStringWidth (Prompt) / sizeof (CHAR16);
  Space[0]         = L' ';
  Space[1]         = CHAR_NULL;

  Question         = MenuOption->ThisTag;
  Minimum          = (UINTN) Question->Minimum;
  Maximum          = (UINTN) Question->Maximum;

  if (Question->Operand == EFI_IFR_PASSWORD_OP) {
    IsPassword = TRUE;
  } else {
    IsPassword = FALSE;
  }

  TempString = AllocateZeroPool ((Maximum + 1)* sizeof (CHAR16));
  ASSERT (TempString);

  if (ScreenSize < (Maximum + 1)) {
    ScreenSize = Maximum + 1;
  }

  if ((ScreenSize + 2) > DimensionsWidth) {
    ScreenSize = DimensionsWidth - 2;
  }

  BufferedString = AllocateZeroPool (ScreenSize * 2);
  ASSERT (BufferedString);

  Start = (DimensionsWidth - ScreenSize - 2) / 2 + gScreenDimensions.LeftColumn + 1;
  Top   = ((DimensionsHeight - 6) / 2) + gScreenDimensions.TopRow - 1;

  //
  // Display prompt for string
  //
  CreateMultiStringPopUp (ScreenSize, 4, &NullCharacter, Prompt, Space, &NullCharacter);

  gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));

  CursorVisible = gST->ConOut->Mode->CursorVisible;
  gST->ConOut->EnableCursor (gST->ConOut, TRUE);

  CurrentCursor = GetStringWidth (StringPtr) / 2 - 1;
  if (CurrentCursor != 0) {
    //
    // Show the string which has beed saved before.
    //
    SetUnicodeMem (BufferedString, ScreenSize - 1, L' ');
    PrintStringAt (Start + 1, Top + 3, BufferedString);

    if ((GetStringWidth (StringPtr) / 2) > (DimensionsWidth - 2)) {
      Index = (GetStringWidth (StringPtr) / 2) - DimensionsWidth + 2;
    } else {
      Index = 0;
    }

    if (IsPassword) {
      gST->ConOut->SetCursorPosition (gST->ConOut, Start + 1, Top + 3);
    }

    for (Count = 0; Index + 1 < GetStringWidth (StringPtr) / 2; Index++, Count++) {
      BufferedString[Count] = StringPtr[Index];

      if (IsPassword) {
        PrintChar (L'*');
      }
    }

    if (!IsPassword) {
      PrintStringAt (Start + 1, Top + 3, BufferedString);
    }
    
    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
    gST->ConOut->SetCursorPosition (gST->ConOut, Start + GetStringWidth (StringPtr) / 2, Top + 3);
  }
  
  do {
    Status = WaitForKeyStroke (&Key);
    ASSERT_EFI_ERROR (Status);

    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));
    switch (Key.UnicodeChar) {
    case CHAR_NULL:
      switch (Key.ScanCode) {
      case SCAN_LEFT:
        if (CurrentCursor > 0) {
          CurrentCursor--;
        }
        break;

      case SCAN_RIGHT:
        if (CurrentCursor < (GetStringWidth (StringPtr) / 2 - 1)) {
          CurrentCursor++;
        }
        break;

      case SCAN_ESC:
        FreePool (TempString);
        FreePool (BufferedString);
        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
        gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);
        return EFI_DEVICE_ERROR;

      default:
        break;
      }

      break;

    case CHAR_CARRIAGE_RETURN:
      if (GetStringWidth (StringPtr) >= ((Minimum + 1) * sizeof (CHAR16))) {

        FreePool (TempString);
        FreePool (BufferedString);
        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
        gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);
        return EFI_SUCCESS;
      } else {
        //
        // Simply create a popup to tell the user that they had typed in too few characters.
        // To save code space, we can then treat this as an error and return back to the menu.
        //
        do {
          CreateDialog (4, TRUE, 0, NULL, &Key, &NullCharacter, gMiniString, gPressEnter, &NullCharacter);
        } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);

        FreePool (TempString);
        FreePool (BufferedString);
        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
        gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);
        return EFI_DEVICE_ERROR;
      }

      break;

    case CHAR_BACKSPACE:
      if (StringPtr[0] != CHAR_NULL && CurrentCursor != 0) {
        for (Index = 0; Index < CurrentCursor - 1; Index++) {
          TempString[Index] = StringPtr[Index];
        }
        Count = GetStringWidth (StringPtr) / 2 - 1;
        if (Count >= CurrentCursor) {
          for (Index = CurrentCursor - 1, Index2 = CurrentCursor; Index2 < Count; Index++, Index2++) {
            TempString[Index] = StringPtr[Index2];
          }
          TempString[Index] = CHAR_NULL;
        }
        //
        // Effectively truncate string by 1 character
        //
        StrCpy (StringPtr, TempString);
        CurrentCursor --;
      }

    default:
      //
      // If it is the beginning of the string, don't worry about checking maximum limits
      //
      if ((StringPtr[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
        StrnCpy (StringPtr, &Key.UnicodeChar, 1);
        CurrentCursor++;
      } else if ((GetStringWidth (StringPtr) < ((Maximum + 1) * sizeof (CHAR16))) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
        KeyPad[0] = Key.UnicodeChar;
        KeyPad[1] = CHAR_NULL;
        Count = GetStringWidth (StringPtr) / 2 - 1;
        if (CurrentCursor < Count) {
          for (Index = 0; Index < CurrentCursor; Index++) {
            TempString[Index] = StringPtr[Index];
          }
		  TempString[Index] = CHAR_NULL;
          StrCat (TempString, KeyPad);
          StrCat (TempString, StringPtr + CurrentCursor);
          StrCpy (StringPtr, TempString);
        } else {
          StrCat (StringPtr, KeyPad);
        }
        CurrentCursor++;
      }

      //
      // If the width of the input string is now larger than the screen, we nee to
      // adjust the index to start printing portions of the string
      //
      SetUnicodeMem (BufferedString, ScreenSize - 1, L' ');
      PrintStringAt (Start + 1, Top + 3, BufferedString);

      if ((GetStringWidth (StringPtr) / 2) > (DimensionsWidth - 2)) {
        Index = (GetStringWidth (StringPtr) / 2) - DimensionsWidth + 2;
      } else {
        Index = 0;
      }

      if (IsPassword) {
        gST->ConOut->SetCursorPosition (gST->ConOut, Start + 1, Top + 3);
      }

      for (Count = 0; Index + 1 < GetStringWidth (StringPtr) / 2; Index++, Count++) {
        BufferedString[Count] = StringPtr[Index];

        if (IsPassword) {
          PrintChar (L'*');
        }
      }

      if (!IsPassword) {
        PrintStringAt (Start + 1, Top + 3, BufferedString);
      }
      break;
    }

    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
    gST->ConOut->SetCursorPosition (gST->ConOut, Start + CurrentCursor + 1, Top + 3);
  } while (TRUE);

}
Exemplo n.º 6
0
/**
  Get selection for OneOf and OrderedList (Left/Right will be ignored).

  @param  Selection         Pointer to current selection.
  @param  MenuOption        Pointer to the current input menu.

  @retval EFI_SUCCESS       If Option input is processed successfully
  @retval EFI_DEVICE_ERROR  If operation fails

**/
EFI_STATUS
GetSelectionInputPopUp (
  IN  UI_MENU_SELECTION           *Selection,
  IN  UI_MENU_OPTION              *MenuOption
  )
{
  EFI_STATUS              Status;
  EFI_INPUT_KEY           Key;
  UINTN                   Index;
  CHAR16                  *StringPtr;
  CHAR16                  *TempStringPtr;
  UINTN                   Index2;
  UINTN                   TopOptionIndex;
  UINTN                   HighlightOptionIndex;
  UINTN                   Start;
  UINTN                   End;
  UINTN                   Top;
  UINTN                   Bottom;
  UINTN                   PopUpMenuLines;
  UINTN                   MenuLinesInView;
  UINTN                   PopUpWidth;
  CHAR16                  Character;
  INT32                   SavedAttribute;
  BOOLEAN                 ShowDownArrow;
  BOOLEAN                 ShowUpArrow;
  UINTN                   DimensionsWidth;
  LIST_ENTRY              *Link;
  BOOLEAN                 OrderedList;
  UINT8                   *ValueArray;
  UINT8                   ValueType;
  EFI_HII_VALUE           HiiValue;
  EFI_HII_VALUE           *HiiValueArray;
  UINTN                   OptionCount;
  QUESTION_OPTION         *OneOfOption;
  QUESTION_OPTION         *CurrentOption;
  FORM_BROWSER_STATEMENT  *Question;
  INTN                    Result;

  DimensionsWidth   = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;

  ValueArray        = NULL;
  ValueType         = 0;
  CurrentOption     = NULL;
  ShowDownArrow     = FALSE;
  ShowUpArrow       = FALSE;

  StringPtr = AllocateZeroPool ((gOptionBlockWidth + 1) * 2);
  ASSERT (StringPtr);

  Question = MenuOption->ThisTag;
  if (Question->Operand == EFI_IFR_ORDERED_LIST_OP) {
    ValueArray = Question->BufferValue;
    ValueType = Question->ValueType;
    OrderedList = TRUE;
  } else {
    OrderedList = FALSE;
  }

  //
  // Calculate Option count
  //
  if (OrderedList) {
    for (Index = 0; Index < Question->MaxContainers; Index++) {
      if (GetArrayData (ValueArray, ValueType, Index) == 0) {
        break;
      }
    }

    OptionCount = Index;
  } else {
    OptionCount = 0;
    Link = GetFirstNode (&Question->OptionListHead);
    while (!IsNull (&Question->OptionListHead, Link)) {
      OneOfOption = QUESTION_OPTION_FROM_LINK (Link);

      OptionCount++;

      Link = GetNextNode (&Question->OptionListHead, Link);
    }
  }

  //
  // Prepare HiiValue array
  //
  HiiValueArray = AllocateZeroPool (OptionCount * sizeof (EFI_HII_VALUE));
  ASSERT (HiiValueArray != NULL);
  Link = GetFirstNode (&Question->OptionListHead);
  for (Index = 0; Index < OptionCount; Index++) {
    if (OrderedList) {
      HiiValueArray[Index].Type = ValueType;
      HiiValueArray[Index].Value.u64 = GetArrayData (ValueArray, ValueType, Index);
    } else {
      OneOfOption = QUESTION_OPTION_FROM_LINK (Link);
      CopyMem (&HiiValueArray[Index], &OneOfOption->Value, sizeof (EFI_HII_VALUE));
      Link = GetNextNode (&Question->OptionListHead, Link);
    }
  }

  //
  // Move Suppressed Option to list tail
  //
  PopUpMenuLines = 0;
  for (Index = 0; Index < OptionCount; Index++) {
    OneOfOption = ValueToOption (Question, &HiiValueArray[OptionCount - Index - 1]);
    if (OneOfOption == NULL) {
      return EFI_NOT_FOUND;
    }

    RemoveEntryList (&OneOfOption->Link);

    if ((OneOfOption->SuppressExpression != NULL) &&
        EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) {
      //
      // This option is suppressed, insert to tail
      //
      InsertTailList (&Question->OptionListHead, &OneOfOption->Link);
    } else {
      //
      // Insert to head
      //
      InsertHeadList (&Question->OptionListHead, &OneOfOption->Link);

      PopUpMenuLines++;
    }
  }

  //
  // Get the number of one of options present and its size
  //
  PopUpWidth = 0;
  HighlightOptionIndex = 0;
  Link = GetFirstNode (&Question->OptionListHead);
  for (Index = 0; Index < PopUpMenuLines; Index++) {
    OneOfOption = QUESTION_OPTION_FROM_LINK (Link);

    StringPtr = GetToken (OneOfOption->Text, MenuOption->Handle);
    if (StrLen (StringPtr) > PopUpWidth) {
      PopUpWidth = StrLen (StringPtr);
    }
    FreePool (StringPtr);

    if (!OrderedList && (CompareHiiValue (&Question->HiiValue, &OneOfOption->Value, &Result, NULL) == EFI_SUCCESS) && (Result == 0)) {
      //
      // Find current selected Option for OneOf
      //
      HighlightOptionIndex = Index;
    }

    Link = GetNextNode (&Question->OptionListHead, Link);
  }

  //
  // Perform popup menu initialization.
  //
  PopUpWidth = PopUpWidth + POPUP_PAD_SPACE_COUNT;

  SavedAttribute = gST->ConOut->Mode->Attribute;
  gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);

  if ((PopUpWidth + POPUP_FRAME_WIDTH) > DimensionsWidth) {
    PopUpWidth = DimensionsWidth - POPUP_FRAME_WIDTH;
  }

  Start  = (DimensionsWidth - PopUpWidth - POPUP_FRAME_WIDTH) / 2 + gScreenDimensions.LeftColumn;
  End    = Start + PopUpWidth + POPUP_FRAME_WIDTH;
  Top    = gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT;
  Bottom = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight - 1;

  MenuLinesInView = Bottom - Top - 1;
  if (MenuLinesInView >= PopUpMenuLines) {
    Top     = Top + (MenuLinesInView - PopUpMenuLines) / 2;
    Bottom  = Top + PopUpMenuLines + 1;
  } else {
    ShowDownArrow = TRUE;
  }

  if (HighlightOptionIndex > (MenuLinesInView - 1)) {
    TopOptionIndex = HighlightOptionIndex - MenuLinesInView + 1;
  } else {
    TopOptionIndex = 0;
  }

  do {
    //
    // Clear that portion of the screen
    //
    ClearLines (Start, End, Top, Bottom, POPUP_TEXT | POPUP_BACKGROUND);

    //
    // Draw "One of" pop-up menu
    //
    Character = BOXDRAW_DOWN_RIGHT;
    PrintCharAt (Start, Top, Character);
    for (Index = Start; Index + 2 < End; Index++) {
      if ((ShowUpArrow) && ((Index + 1) == (Start + End) / 2)) {
        Character = GEOMETRICSHAPE_UP_TRIANGLE;
      } else {
        Character = BOXDRAW_HORIZONTAL;
      }

      PrintChar (Character);
    }

    Character = BOXDRAW_DOWN_LEFT;
    PrintChar (Character);
    Character = BOXDRAW_VERTICAL;
    for (Index = Top + 1; Index < Bottom; Index++) {
      PrintCharAt (Start, Index, Character);
      PrintCharAt (End - 1, Index, Character);
    }

    //
    // Move to top Option
    //
    Link = GetFirstNode (&Question->OptionListHead);
    for (Index = 0; Index < TopOptionIndex; Index++) {
      Link = GetNextNode (&Question->OptionListHead, Link);
    }

    //
    // Display the One of options
    //
    Index2 = Top + 1;
    for (Index = TopOptionIndex; (Index < PopUpMenuLines) && (Index2 < Bottom); Index++) {
      OneOfOption = QUESTION_OPTION_FROM_LINK (Link);
      Link = GetNextNode (&Question->OptionListHead, Link);

      StringPtr = GetToken (OneOfOption->Text, MenuOption->Handle);
      ASSERT (StringPtr != NULL);
      //
      // If the string occupies multiple lines, truncate it to fit in one line,
      // and append a "..." for indication.
      //
      if (StrLen (StringPtr) > (PopUpWidth - 1)) {
        TempStringPtr = AllocateZeroPool (sizeof (CHAR16) * (PopUpWidth - 1));
        ASSERT ( TempStringPtr != NULL );
        CopyMem (TempStringPtr, StringPtr, (sizeof (CHAR16) * (PopUpWidth - 5)));
        FreePool (StringPtr);
        StringPtr = TempStringPtr;
        StrCat (StringPtr, L"...");
      }

      if (Index == HighlightOptionIndex) {
          //
          // Highlight the selected one
          //
          CurrentOption = OneOfOption;

          gST->ConOut->SetAttribute (gST->ConOut, PICKLIST_HIGHLIGHT_TEXT | PICKLIST_HIGHLIGHT_BACKGROUND);
          PrintStringAt (Start + 2, Index2, StringPtr);
          gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);
        } else {
          gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);
          PrintStringAt (Start + 2, Index2, StringPtr);
        }

      Index2++;
      FreePool (StringPtr);
    }

    Character = BOXDRAW_UP_RIGHT;
    PrintCharAt (Start, Bottom, Character);
    for (Index = Start; Index + 2 < End; Index++) {
      if ((ShowDownArrow) && ((Index + 1) == (Start + End) / 2)) {
        Character = GEOMETRICSHAPE_DOWN_TRIANGLE;
      } else {
        Character = BOXDRAW_HORIZONTAL;
      }

      PrintChar (Character);
    }

    Character = BOXDRAW_UP_LEFT;
    PrintChar (Character);

    //
    // Get User selection
    //
    Key.UnicodeChar = CHAR_NULL;
    if ((gDirection == SCAN_UP) || (gDirection == SCAN_DOWN)) {
      Key.ScanCode  = gDirection;
      gDirection    = 0;
      goto TheKey;
    }

    Status = WaitForKeyStroke (&Key);

TheKey:
    switch (Key.UnicodeChar) {
    case '+':
      if (OrderedList) {
        if ((TopOptionIndex > 0) && (TopOptionIndex == HighlightOptionIndex)) {
          //
          // Highlight reaches the top of the popup window, scroll one menu item.
          //
          TopOptionIndex--;
          ShowDownArrow = TRUE;
        }

        if (TopOptionIndex == 0) {
          ShowUpArrow = FALSE;
        }

        if (HighlightOptionIndex > 0) {
          HighlightOptionIndex--;

          ASSERT (CurrentOption != NULL);
          SwapListEntries (CurrentOption->Link.BackLink, &CurrentOption->Link);
        }
      }
      break;

    case '-':
      //
      // If an ordered list op-code, we will allow for a popup of +/- keys
      // to create an ordered list of items
      //
      if (OrderedList) {
        if (((TopOptionIndex + MenuLinesInView) < PopUpMenuLines) &&
            (HighlightOptionIndex == (TopOptionIndex + MenuLinesInView - 1))) {
          //
          // Highlight reaches the bottom of the popup window, scroll one menu item.
          //
          TopOptionIndex++;
          ShowUpArrow = TRUE;
        }

        if ((TopOptionIndex + MenuLinesInView) == PopUpMenuLines) {
          ShowDownArrow = FALSE;
        }

        if (HighlightOptionIndex < (PopUpMenuLines - 1)) {
          HighlightOptionIndex++;

          ASSERT (CurrentOption != NULL);
          SwapListEntries (&CurrentOption->Link, CurrentOption->Link.ForwardLink);
        }
      }
      break;

    case CHAR_NULL:
      switch (Key.ScanCode) {
      case SCAN_UP:
      case SCAN_DOWN:
        if (Key.ScanCode == SCAN_UP) {
          if ((TopOptionIndex > 0) && (TopOptionIndex == HighlightOptionIndex)) {
            //
            // Highlight reaches the top of the popup window, scroll one menu item.
            //
            TopOptionIndex--;
            ShowDownArrow = TRUE;
          }

          if (TopOptionIndex == 0) {
            ShowUpArrow = FALSE;
          }

          if (HighlightOptionIndex > 0) {
            HighlightOptionIndex--;
          }
        } else {
          if (((TopOptionIndex + MenuLinesInView) < PopUpMenuLines) &&
              (HighlightOptionIndex == (TopOptionIndex + MenuLinesInView - 1))) {
            //
            // Highlight reaches the bottom of the popup window, scroll one menu item.
            //
            TopOptionIndex++;
            ShowUpArrow = TRUE;
          }

          if ((TopOptionIndex + MenuLinesInView) == PopUpMenuLines) {
            ShowDownArrow = FALSE;
          }

          if (HighlightOptionIndex < (PopUpMenuLines - 1)) {
            HighlightOptionIndex++;
          }
        }
        break;

      case SCAN_ESC:
        gST->ConOut->SetAttribute (gST->ConOut, SavedAttribute);

        //
        // Restore link list order for orderedlist
        //
        if (OrderedList) {
          HiiValue.Type = ValueType;
          HiiValue.Value.u64 = 0;
          for (Index = 0; Index < Question->MaxContainers; Index++) {
            HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);
            if (HiiValue.Value.u64 == 0) {
              break;
            }

            OneOfOption = ValueToOption (Question, &HiiValue);
            if (OneOfOption == NULL) {
              return EFI_NOT_FOUND;
            }

            RemoveEntryList (&OneOfOption->Link);
            InsertTailList (&Question->OptionListHead, &OneOfOption->Link);
          }
        }

        FreePool (HiiValueArray);
        return EFI_DEVICE_ERROR;

      default:
        break;
      }

      break;

    case CHAR_CARRIAGE_RETURN:
      //
      // return the current selection
      //
      if (OrderedList) {
        Index = 0;
        Link = GetFirstNode (&Question->OptionListHead);
        while (!IsNull (&Question->OptionListHead, Link)) {
          OneOfOption = QUESTION_OPTION_FROM_LINK (Link);

          SetArrayData (ValueArray, ValueType, Index, OneOfOption->Value.Value.u64);

          Index++;
          if (Index > Question->MaxContainers) {
            break;
          }

          Link = GetNextNode (&Question->OptionListHead, Link);
        }
      } else {
        ASSERT (CurrentOption != NULL);
        CopyMem (&Question->HiiValue, &CurrentOption->Value, sizeof (EFI_HII_VALUE));
      }

      gST->ConOut->SetAttribute (gST->ConOut, SavedAttribute);
      FreePool (HiiValueArray);

      Status = ValidateQuestion (Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);
      if (EFI_ERROR (Status)) {
        //
        // Input value is not valid, restore Question Value
        //
        GetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);
      } else {
        SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);
        UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);
      }

      return Status;

    default:
      break;
    }
  } while (TRUE);

}
Exemplo n.º 7
0
void main(void)
{
     #define BAUDRG 77

    BYTE SecNum = 0;

   BOOL Tx_Success = FALSE;
   BYTE Tx_Trials = 0, scanresult = 0;
    /*******************************************************************/
    // Initialize the system
    /*******************************************************************/

    ANCON0 = 0XFF;     /*desactiva entradas analogicas*/
    ANCON1 = 0XFF;     /*desactiva entradas analogicas*/



    PPSUnLock();

    PPSOutput(PPS_RP10, PPS_TX2CK2);    // TX2 RP17/RC6     icsp
    PPSInput(PPS_RX2DT2, PPS_RP9);     // RX2 RP18/RC7

    PPSOutput(PPS_RP23, PPS_SDO2);    // SDO2 RP23/RD6
    PPSInput(PPS_SDI2, PPS_RP24);     // SDI2 RP24/RD7
    PPSOutput(PPS_RP22, PPS_SCK2);    // SCK2 RP22/RD5

    PPSLock();

     System_PeripheralPinSelect( ExternalInterrupt3, 19);  /*external interrupt 3 B3*/

     BoardInit();
     ConsoleInit();

     Gpios_PinDirection(GPIOS_PORTC, 7, GPIOS_INPUT);  /*pin C0 como salida para SDI*/
     Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/
     
     //Gpios_PinDirection(GPIOS_PORTD, 4, GPIOS_OUTPUT);  /*pin D4 como salida */

     Open1USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG);
     baud1USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF);


     Open2USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG);
     baud2USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF);


     OpenTimer1( TIMER_INT_OFF &T1_16BIT_RW &T1_SOURCE_FOSC_4 & T1_PS_1_8 &T1_OSC1EN_OFF &T1_SYNC_EXT_OFF, TIMER_GATE_OFF  & TIMER_GATE_INT_OFF);



     Gpios_PinDirection(GPIOS_PORTD, 7, GPIOS_INPUT);  /*pin C0 como salida para SDI*/
     Gpios_PinDirection(GPIOS_PORTD, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/
     Gpios_PinDirection(GPIOS_PORTD, 5, GPIOS_OUTPUT); /*pin C2 como salida para SCK*/

     Spi_Init(SPI_PORT1, SPI_64DIV); /*Inicializamos SPI2*/
     Spi_Init(SPI_PORT2, SPI_64DIV); /*Inicializamos SPI2*/

     //Adc_Init(ADC_10BITS);

     LED_1 = 1;
     LED_2 = 0;
     //RLY_1 = 0;
     RLY_2 = 0;

     ON_RADIO = 1;
     ON_MAC = 1;
     ON_TEMP = 1;
     
     StartWirelessConnection();
     
     
     
     //myDevicesRequiredStatus[0] = 0x55;
     
     
     EEPROMRead(&myDevicesRequiredStatus, 0, 1);
     
     if(myDevicesRequiredStatus[0] == 0x55)
     {
         RLY_1 = 1;
         EEPROMCHG = 1;
         ConsolePutROMString((ROM char *)"RELAY ON ");
     }
     
     if(myDevicesRequiredStatus[0] == 0xAA)
     {
         RLY_1 = 0;
         EEPROMCHG = 0;
         ConsolePutROMString((ROM char *)"RELAY OFF ");
     }
     
     
     
     
     

     for(j=0;j<10;j++)
     {
         DelayMs(50);

         LED_1 ^= 1;
         LED_2 ^= 1;
     }
     
     

     LED_1 = 0;
     LED_2 = 0;
     //RLY_1 = 0;
     RLY_2 = 0;
     
    
     
     TickScaler = 4;
     EndDevStateMachine =0;



/*
                                

                                while(!Tx_Success)
                                {
                                    if(myChannel < 8)
                                        scanresult = MiApp_SearchConnection(10, (0x00000001 << myChannel));
                                    else if(myChannel < 16)
                    				    scanresult = MiApp_SearchConnection(10, (0x00000100 << (myChannel-8)));
                                    else if(myChannel < 24)
                    				    scanresult = MiApp_SearchConnection(10, (0x00010000 << (myChannel-16)));
                                    else
                    				    scanresult = MiApp_SearchConnection(10, (0x01000000 << (myChannel-24)));
                                    if(scanresult == 0)
                                    {
                                        Tx_Trials++;
                                        if(Tx_Trials > 2) break;

                                    }
                                    else Tx_Success = TRUE;

                                }
                                if(Tx_Success)
                                {
                                    ConsolePutROMString((ROM char *)"RADIO OK ");
                                }
                                else
                                {
                                    ConsolePutROMString((ROM char *)"RADIO FAIL ");
                                }

*/


     //.VBGOE = 0;
     //ANCON1bits.VBGEN = 1;		// Enable Band gap reference voltage
     //DelayMs(10);
     //VBGResult = Adc_u16Read(15);
     //ANCON1bits.VBGEN = 0;	    // Disable Bandgap

      //Adc_Init(ADC_10BITS);
     
     
     ANCON0 = 0xFF;
     ANCON1 = 0x9F;
     ANCON1bits.VBGEN = 1;		// Enable Band gap reference voltage
     
     
     ADCON0bits.VCFG = 0;    // vreff VDD-VSS
     ADCON0bits.CHS = 0x0F;  // VBG channel select
     
     ADCON1 = 0xBE;
     ADCON0bits.ADON = 1;
     
     //for(j=0;j<16;j++)
     //{
        //myDevicesOutputStatus[j] = j;
     //}
    
     
     //EEPROMWRITE(myDevicesOutputStatus,0,16);
     
     
     //for(j=0;j<16;j++)
     //{
        //myDevicesOutputStatus[j] = 0;
     //}
     
     //DelayMs(500);
     
     EEPROMRead(&myDevicesOutputStatus, 0, 16);
     ConsolePutROMString((ROM char *)"EEPROM READ: ");
     //PrintChar(TemperatureCalibrationValue);
     
     
     for(j=0;j<1;j++)
     {
         PrintChar(myDevicesOutputStatus[j]);
     }
	

     SwTimer3 = 0;
     SwTimer4 = 0;
     
     TRISB&=0xEF;   //JL: Configuro el pin B4 como salida si modificar el estado de los demas pines
     
     while(1)
     {
     /*
         WirelessTxRx();
         WirelesStatus();
         Bypass();
         */
         
         
         //No se utilizaron
         //Menu();
         //Timer1Tick();
         //WirelessTxRxPANCOORD();
         //TaskScheduler();
         
         //JLEstas funciones deben habilitarse para trabajar como repetidora
         
         Timer1Tick();
         Repeater();
        
     }

}
//*****************************************************************************
//
// This is the callback from the USB HID keyboard handler.
//
// \param psKbInstance is ignored by this function.
// \param ui32Event is one of the valid events for a keyboard device.
// \param ui32MsgParam is defined by the event that occurs.
// \param pvMsgData is a pointer to data that is defined by the event that
// occurs.
//
// This function will be called to inform the application when a keyboard has
// been plugged in or removed and any time a key is pressed or released.
//
// \return None.
//
//*****************************************************************************
void
KeyboardCallback(tUSBHKeyboard *psKbInstance, uint32_t ui32Event,
                 uint32_t ui32MsgParam, void *pvMsgData)
{
    char cChar;

    switch(ui32Event)
    {
        //
        // New Key press detected.
        //
        case USBH_EVENT_HID_KB_PRESS:
        {
            //
            // If this was a Caps Lock key then update the Caps Lock state.
            //
            if(ui32MsgParam == HID_KEYB_USAGE_CAPSLOCK)
            {
                //
                // The main loop needs to update the keyboard's Caps Lock
                // state.
                //
                g_eUSBState = STATE_KEYBOARD_UPDATE;

                //
                // Toggle the current Caps Lock state.
                //
                g_ui32Modifiers ^= HID_KEYB_CAPS_LOCK;

                //
                // Update the screen based on the Caps Lock status.
                //
                UpdateStatus();
            }
            else if(ui32MsgParam == HID_KEYB_USAGE_SCROLLOCK)
            {
                //
                // The main loop needs to update the keyboard's Scroll Lock
                // state.
                //
                g_eUSBState = STATE_KEYBOARD_UPDATE;

                //
                // Toggle the current Scroll Lock state.
                //
                g_ui32Modifiers ^= HID_KEYB_SCROLL_LOCK;
            }
            else if(ui32MsgParam == HID_KEYB_USAGE_NUMLOCK)
            {
                //
                // The main loop needs to update the keyboard's Scroll Lock
                // state.
                //
                g_eUSBState = STATE_KEYBOARD_UPDATE;

                //
                // Toggle the current Num Lock state.
                //
                g_ui32Modifiers ^= HID_KEYB_NUM_LOCK;
            }
            else
            {
                //
                // Was this the backspace key?
                //
                if((uint8_t)ui32MsgParam == HID_KEYB_USAGE_BACKSPACE)
                {
                    //
                    // Yes - set the ASCII code for a backspace key.  This is
                    // not returned by USBHKeyboardUsageToChar since this only
                    // returns printable characters.
                    //
                    cChar = ASCII_BACKSPACE;
                }
                else
                {
                    //
                    // This is not backspace so try to map the usage code to a
                    // printable ASCII character.
                    //
                    cChar = (char)
                        USBHKeyboardUsageToChar(g_psKeyboardInstance,
                                                &g_sUSKeyboardMap,
                                                (uint8_t)ui32MsgParam);
                }

                //
                // A zero value indicates there was no textual mapping of this
                // usage code.
                //
                if(cChar != 0)
                {
                    PrintChar(cChar);
                }
            }
            break;
        }
        case USBH_EVENT_HID_KB_MOD:
        {
            //
            // This application ignores the state of the shift or control
            // and other special keys.
            //
            break;
        }
        case USBH_EVENT_HID_KB_REL:
        {
            //
            // This applications ignores the release of keys as well.
            //
            break;
        }
    }
}
Exemplo n.º 9
0
//*****************************************************************************
//
// This is the callback from the USB HID keyboard handler.
//
// \param pvCBData is ignored by this function.
// \param ulEvent is one of the valid events for a keyboard device.
// \param ulMsgParam is defined by the event that occurs.
// \param pvMsgData is a pointer to data that is defined by the event that
// occurs.
//
// This function will be called to inform the application when a keyboard has
// been plugged in or removed and anytime a key is pressed or released.
//
// \return This function will return 0.
//
//*****************************************************************************
unsigned long
KeyboardCallback(void *pvCBData, unsigned long ulEvent,
                 unsigned long ulMsgParam, void *pvMsgData)
{
    unsigned char ucChar;

    switch(ulEvent)
    {
        //
        // New keyboard detected.
        //
        case USB_EVENT_CONNECTED:
        {
            //
            // Indicate that the keyboard has been detected.
            //
            UARTprintf("Keyboard Connected\n");

            //
            // Proceed to the STATE_KEYBOARD_INIT state so that the main loop
            // can finish initialized the mouse since USBHKeyboardInit() cannot
            // be called from within a callback.
            //
            g_eUSBState = STATE_KEYBOARD_INIT;

            break;
        }

        //
        // Keyboard has been unplugged.
        //
        case USB_EVENT_DISCONNECTED:
        {
            //
            // Indicate that the keyboard has been disconnected.
            //
            UARTprintf("Keyboard Disconnected\n");

            //
            // Change the state so that the main loop knows that the keyboard
            // is no longer present.
            //
            g_eUSBState = STATE_NO_DEVICE;

            //
            // Reset the modifiers state.
            //
            g_ulModifiers = 0;

            //
            // Update the screen.
            //
            UpdateStatus();

            break;
        }

        //
        // New Key press detected.
        //
        case USBH_EVENT_HID_KB_PRESS:
        {
            //
            // If this was a Caps Lock key then update the Caps Lock state.
            //
            if(ulMsgParam == HID_KEYB_USAGE_CAPSLOCK)
            {
                //
                // The main loop needs to update the keyboard's Caps Lock
                // state.
                //
                g_eUSBState = STATE_KEYBOARD_UPDATE;

                //
                // Toggle the current Caps Lock state.
                //
                g_ulModifiers ^= HID_KEYB_CAPS_LOCK;

                //
                // Update the screen based on the Caps Lock status.
                //
                UpdateStatus();
            }
            else
            {
                //
                // Print the current key out the UART.
                //
                ucChar = (unsigned char)
                    USBHKeyboardUsageToChar(g_ulKeyboardInstance,
                                            &g_sUSKeyboardMap,
                                            (unsigned char)ulMsgParam);
                //
                // A zero value indicates there was no textual mapping of this
                // usage code.
                //
                if(ucChar != 0)
                {
                    PrintChar(ucChar);
                }
            }
            break;
        }
        case USBH_EVENT_HID_KB_MOD:
        {
            //
            // This application ignores the state of the shift or control
            // and other special keys.
            //
            break;
        }
        case USBH_EVENT_HID_KB_REL:
        {
            //
            // This applications ignores the release of keys as well.
            //
            break;
        }
    }
    return(0);
}
Exemplo n.º 10
0
void Repeater(void)
 {
     if( MiApp_MessageAvailable())
     {
            Printf("\r\n  ");
            if( rxMessage.flags.bits.secEn )
            {
                ConsolePutROMString((ROM char *)"Secured ");
            }

            if( rxMessage.flags.bits.broadcast )
            {
             ConsolePutROMString((ROM char *)"Broadcast Packet with RSSI ");
            }
            else
            {
             ConsolePutROMString((ROM char *)"Unicast Packet with RSSI ");
            }
            PrintChar(rxMessage.PacketRSSI);


           if( rxMessage.flags.bits.srcPrsnt )
            {
                ConsolePutROMString((ROM char *)" from ");
                if( rxMessage.flags.bits.altSrcAddr )
                {
                    PrintChar(rxMessage.SourceAddress[1]);
                    PrintChar(rxMessage.SourceAddress[0]);
                }
                else
                {
                    for(i = 0; i < MY_ADDRESS_LENGTH; i++)
                    {
                      PrintChar(rxMessage.SourceAddress[MY_ADDRESS_LENGTH-1-i]);

                    }
                }
            }

            ConsolePutROMString((ROM char *)": ");


            for(i = 0; i < rxMessage.PayloadSize; i++)
            {
              PrintChar(rxMessage.Payload[i]);
            }
         
       ClrWdt();  
       SwTimer3 = 0;  
         
       LED_2 ^= 1;
       MiApp_DiscardMessage();
       
     }
     
     
     if(SwTimer3 >= 500)           // if lost connection ... JL:Anteriormente 100, se cambio para
     {                              //lugares donde los mensajes llegan con mucho retardo entre uno y otro (area de pozo))
         Reset();
     }
 }
Exemplo n.º 11
0
t_sshort GrphDisp_Init(t_uchar Col, /* total column size of display                */
                   t_uchar Row, /* total row size of display                   */
                   t_uchar MaxWindow/* approx. windows that can be open        */
                             /* (assuming window is 1/4 of the total        */
                             /* display. Nevertheless windows can be opened */
                             /* as long as there is room on the stack.      */
)
{

  ColMajor = Col;
  RowMajor = Row;
  BaseBit = 0;               /* used in pixel macro                         */
  TmpBit = 0;                /* used in pixel macro                         */
  StackIndex = 0;            /* stack is empty 1/4 of the maximum window *  */
                             /* the amount of windows this is the total     */
                             /* amount of space how you use it is up to you */

  #if defined(FEDORA_VERSION)
    /* Init Curses */
    initcurses();
  #endif /* MAEL Version */
  
  StackSize = (ColMajor*RowMajor*2)*MaxWindow;

  Vdisplay = (char *)Mem_Alloc(ColMajor*RowMajor*2+256);
  if ((t_uchar *)Vdisplay == 0)
  {
    /* Memory error */
    printf ("Error Grphdisp: memoria insuficiente\n");
    printf ("Press any key to halt:");
    #if defined(FEDORA_VERSION)
    mael_getch();
    #else
    getch ();
    #endif
    exit (1);
    return (NOSDOS_FAILURE);
  }                          /* StackData = (t_uchar                           */
                             /* *)Memory_Alloc(StackSize,MA_ALLOC);         */
  StackData = (t_uchar *)Mem_Alloc(StackSize);
  if (StackData == 0)
  {
    /* Memory error */
    printf ("Error Grphdisp: memoria insuficiente\n");
    printf ("Press any key to halt:");
    #if defined(FEDORA_VERSION)
    mael_getch();
    #else
    getch ();
    #endif
    exit (1);
    return (NOSDOS_FAILURE);
  }
  memset(StackData, 0, StackSize);
  memset(Vdisplay, 0, ColMajor*RowMajor*2);

  /* Clears entire screen */
  clrscr ();

#if !defined(FEDORA_VERSION)
{

  t_uchar IdxLine, IdxCol;

  /* Makes frame */
  gotoxy (DISP_INICOL-1, DISP_INILINE-1);
  
  /*cprintf ("%c", FRAME_LEFTH); */
  PrintChar ((char) FRAME_LEFTH);
  
  for (IdxCol = 0; IdxCol < ColMajor; IdxCol++)
    /*cprintf ("%c", FRAME_HOR); */
    PrintChar ((char) FRAME_HOR);
  /*cprintf ("%c", FRAME_RIGHTH); */
  PrintChar ((char) FRAME_RIGHTH);
  for (IdxLine = 0; IdxLine < RowMajor; IdxLine++)
  {
    gotoxy (DISP_INICOL-1, DISP_INILINE+IdxLine);
    /*cprintf ("%c", FRAME_VER); */
    PrintChar ((char) FRAME_VER);
    gotoxy (DISP_INICOL+ColMajor, DISP_INILINE+IdxLine);
    /*cprintf ("%c", FRAME_VER); */
    PrintChar ((char) FRAME_VER);
  } /* endfor */
  gotoxy (DISP_INICOL-1, DISP_INILINE+IdxLine);
  /*cprintf ("%c", FRAME_LEFTL); */
  PrintChar ((char) FRAME_LEFTL);
  for (IdxCol = 0; IdxCol < ColMajor; IdxCol++)
    /*cprintf ("%c", FRAME_HOR); */
    PrintChar ((char) FRAME_HOR);
  /*cprintf ("%c", FRAME_RIGHTL); */
  PrintChar ((char) FRAME_RIGHTL);
}
#endif /* MAEL Version */

  GrphDisp_DispBuffer((t_uchar *) Vdisplay, 0, 0, (t_uchar) (ColMajor-1), (t_uchar) (RowMajor-1));
  return (NOSDOS_OK);
}
Exemplo n.º 12
0
void Centerspace()   //spaces to center
{
    PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
}  
Exemplo n.º 13
0
void Count(void)	// prints 0.0000-omega
{
	PrintChar(0x05);
	
	
	 //4.      
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x34);
	PrintChar(0x2e);
	PrintChar(0x39);
	PrintChar(0x39);
	PrintChar(0x39);
	PrintChar(0x36);
	PrintChar(0x06);
	PrintChar(0x01);
	
	_delay_ms(500);
	
	PrintChar(0x05);
	
	
	 //.0002
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x06);
	PrintChar(0x34);
	PrintChar(0x2e);
	PrintChar(0x39);
	PrintChar(0x39);
	PrintChar(0x39);
	PrintChar(0x37);
	PrintChar(0x06);
	PrintChar(0x01);
	
	_delay_ms(50);
	
	//PrintChar(0x05); //.0001
	//PrintChar(0x34);
	//PrintChar(0x2e);
	//PrintChar(0x39);
	//PrintChar(0x39);
	//PrintChar(0x39);
	//PrintChar(0x35);
	//PrintChar(0x2d);
	//PrintChar(0x01);

	//_delay_ms(50);
}
Exemplo n.º 14
0
void Print (const char *str)
{
	char c;
	while (c = *str++)
		PrintChar (c);
}
Exemplo n.º 15
0
 void WirelessTxRx(void)
 {
     Timer1Tick();

     switch(EndDevStateMachine)
     {
         case 0:                      // recibe estado para relevadores y latencia de comunicacion
         {
             if( MiApp_MessageAvailable())
             {
                if((rxMessage.Payload[1] == 0x00)&&((rxMessage.Payload[3] == OutputStat)))
                {
                    BypassCounter = 0;
                    if(rxMessage.Payload[4] <= 16)
                    {
                        //BaseTimeToTx = rxMessage.Payload[4];
                        TickScaler = rxMessage.Payload[4];
                    }


                    j = (myNodeNumber-1)/8;
                    j += 5;

                    i = rxMessage.Payload[j];

                    j =  (myNodeNumber-1)%8;

                    if(QUERY_8BIT(i,j))
                    {

                        RLY_STATUS = 1;
                    }
                    else
                    {

                        RLY_STATUS = 0;
                    }


                    ConsolePutROMString((ROM char *)"\r\n Req Stat:");

                    for(i=0;i<rxMessage.PayloadSize;i++)
                    {
                        PrintChar(rxMessage.Payload[i]);
                    }
                    

                    SwTimer0 = 0;
                    WriteTimer1(56161);           
                    Tick = 0;
                    
                    LED_2 ^= 1;
                    EndDevStateMachine = 1;
                    SwTimer3 = 0;     // clear MIWIPRO STATUS TIMER


                }
                else
                {
                    if((rxMessage.Payload[1] == 0x00)&&((rxMessage.Payload[3] == ListenDevices)))
                    {
                        ConsolePutROMString((ROM char *)"\r\n Listen Devices:");

                        for(i=0;i<rxMessage.PayloadSize;i++)
                        {
                         PrintChar(rxMessage.Payload[i]);
                        }
                        
                        j = (myNodeNumber-1)/8;
                        j += 4;

                        i = rxMessage.Payload[j];

                        j =  (myNodeNumber-1)%8;
                        
                        
                        if(QUERY_8BIT(i,j))
                        {
                         ConsolePutROMString((ROM char *)"\r\n Link stablished correctly");
                         RestartCounter = 0;
                        }
                        else
                        {
                         ConsolePutROMString((ROM char *)"\r\n NO Link stablished!!");
                         ++RestartCounter;
                        }
                        
                        
                        
                    }
                    else
                    {
                        if((rxMessage.Payload[1] == 0x00)&&((rxMessage.Payload[3] == CalibrationProcedure)))
                        {
                            
                            ConsolePutROMString((ROM char *)"\r\n Temperature sensor calibration:");
                            
                            //TemperatureCalibrationValue = rxMessage.Payload[5];
                            
                            
                            if((rxMessage.Payload[5] == MyTemp)||(rxMessage.Payload[5] == 0))
                            {
                                TemperatureCalibrationValue = 0;
                            }
                            else
                            {
                                if(rxMessage.Payload[5] > MyTemp)              // la temp de referencia es mayor a la leida
                                {
                                    //TemperatureCalibrationValue = (rxMessage.Payload[5] - MyTemp) & 0x0F;
                                    
                                }
                                else                                           // la temperatura leida es mayor a la temp de referencia
                                {
                                    //TemperatureCalibrationValue = (MyTemp - rxMessage.Payload[5]) & 0x0F;
                                    //SET_8BIT(TemperatureCalibrationValue,7);
                                }
                            }
                            
                            //EEPROMWRITE(TemperatureCalibrationValue,0,1);
                        }
                    }
                    
                }
                

                 MiApp_DiscardMessage();
             }
         }
         break;

//-----------------------------------------------------------------------------//

         case 1:                // envia estado y temperatura
         {
             if(SwTimer0 >= (_U08)myNodeNumber)
             {

              MyTemp = TemperatureRead();
                                                       
              MiApp_FlushTx();
              MiApp_WriteData(' ');
              MiApp_WriteData(myNodeNumber);
              MiApp_WriteData(MyTrackingNumber);
              MiApp_WriteData(OutputStat);
              MiApp_WriteData(RLY_STATUS);
              MiApp_WriteData(MyTemp);

              MiApp_BroadcastPacket(FALSE);
              

             /*              
              if(RLY_STATUS == 1)
              {
                  RLY_1 = 1;
              }
              else
              {
                  RLY_1 = 0;
              }
              */
              
              
              //SDW_RLY_STATUS
              
              if(RLY_STATUS == 1)
              {
                  if(SDW_RLY_STATUS == 1)
                  {
                      RLY_1 = 1;
                      
                      if(EEPROMCHG == 0)
                      {
                        i = 0x55;
                        EEPROMWRITE(&i,0,1); 
                        EEPROMWRITE(&i,0,1); 
                        EEPROMWRITE(&i,0,1); 
                        EEPROMWRITE(&i,0,1); 
                        EEPROMWRITE(&i,0,1); 
                          
                          
                       //for(j=0;j<16;j++)
                       //{
                        //myDevicesOutputStatus[j] = 0x55;
                       //}
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                        
                        ConsolePutROMString((ROM char *)"\r\n Relay status updated in eeprom 55");
                      }
                      
                      EEPROMCHG = 1;
                  }
                  else
                  {
                      SDW_RLY_STATUS = 1;
                  }
              }
              else
              {
                  if(SDW_RLY_STATUS == 0)
                  {
                      RLY_1 = 0;
                      
                      if(EEPROMCHG == 1)
                      {
                       i = 0xAA;
                       EEPROMWRITE(&i,0,1); 
                       EEPROMWRITE(&i,0,1); 
                       EEPROMWRITE(&i,0,1); 
                       EEPROMWRITE(&i,0,1); 
                       EEPROMWRITE(&i,0,1); 
                          
                       //for(j=0;j<16;j++)
                       //{
                        //myDevicesOutputStatus[j] = 0xAA;
                       //}
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);   
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                       //EEPROMWRITE(&myDevicesOutputStatus,0,16);
                          
                          
                       ConsolePutROMString((ROM char *)"\r\n Relay status updated in eeprom AA");
                      }
                      
                      EEPROMCHG = 0;
                      
                  }
                  else
                  {
                      SDW_RLY_STATUS = 0;
                  }
              }
              
              
              
              
              
              
              IRControl();
              

              EndDevStateMachine = 2;
             }
         }
         break;

//-----------------------------------------------------------------------------//

         case 2:
         {
             LED_1 ^= 1;
             EndDevStateMachine = 0;
         }
         break;

//-----------------------------------------------------------------------------//

         default:
         {
             EndDevStateMachine = 0;
         }
         break;


     }
 }
Exemplo n.º 16
0
EFI_STATUS
GetNumericInput (
  IN  UI_MENU_SELECTION           *Selection,
  IN  UI_MENU_OPTION              *MenuOption
  )
/*++

Routine Description:
  This routine reads a numeric value from the user input.

Arguments:
  Selection        -  Pointer to current selection.
  MenuOption       -  Pointer to the current input menu.

Returns:
  EFI_SUCCESS       - If numerical input is read successfully
  EFI_DEVICE_ERROR  - If operation fails

--*/
{
  EFI_STATUS              Status;
  UINTN                   Column;
  UINTN                   Row;
  CHAR16                  InputText[23];
  CHAR16                  FormattedNumber[22];
  UINT64                  PreviousNumber[20];
  UINTN                   Count;
  UINTN                   Loop;
  BOOLEAN                 ManualInput;
  BOOLEAN                 HexInput;
  BOOLEAN                 DateOrTime;
  UINTN                   InputWidth;
  UINT64                  EditValue;
  UINT64                  Step;
  UINT64                  Minimum;
  UINT64                  Maximum;
  UINTN                   EraseLen;
  UINT8                   Digital;
  EFI_INPUT_KEY           Key;
  EFI_HII_VALUE           *QuestionValue;
  FORM_BROWSER_FORM       *Form;
  FORM_BROWSER_FORMSET    *FormSet;
  FORM_BROWSER_STATEMENT  *Question;

  Column            = MenuOption->OptCol;
  Row               = MenuOption->Row;
  PreviousNumber[0] = 0;
  Count             = 0;
  InputWidth        = 0;
  Digital           = 0;

  FormSet       = Selection->FormSet;
  Form          = Selection->Form;
  Question      = MenuOption->ThisTag;
  QuestionValue = &Question->HiiValue;
  Step          = Question->Step;
  Minimum       = Question->Minimum;
  Maximum       = Question->Maximum;

  if ((Question->Operand == EFI_IFR_DATE_OP) || (Question->Operand == EFI_IFR_TIME_OP)) {
    DateOrTime = TRUE;
  } else {
    DateOrTime = FALSE;
  }

  //
  // Prepare Value to be edit
  //
  EraseLen = 0;
  EditValue = 0;
  if (Question->Operand == EFI_IFR_DATE_OP) {
    Step = 1;
    Minimum = 1;

    switch (MenuOption->Sequence) {
    case 0:
      Maximum = 12;
      EraseLen = 4;
      EditValue = QuestionValue->Value.date.Month;
      break;

    case 1:
      Maximum = 31;
      EraseLen = 3;
      EditValue = QuestionValue->Value.date.Day;
      break;

    case 2:
      Maximum = 0xffff;
      EraseLen = 5;
      EditValue = QuestionValue->Value.date.Year;
      break;

    default:
      break;
    }
  } else if (Question->Operand == EFI_IFR_TIME_OP) {
    Step = 1;
    Minimum = 0;

    switch (MenuOption->Sequence) {
    case 0:
      Maximum = 23;
      EraseLen = 4;
      EditValue = QuestionValue->Value.time.Hour;
      break;

    case 1:
      Maximum = 59;
      EraseLen = 3;
      EditValue = QuestionValue->Value.time.Minute;
      break;

    case 2:
      Maximum = 59;
      EraseLen = 3;
      EditValue = QuestionValue->Value.time.Second;
      break;

    default:
      break;
    }
  } else {
    //
    // Numeric
    //
    EraseLen = gOptionBlockWidth;
    EditValue = QuestionValue->Value.u64;
    if (Maximum == 0) {
      Maximum = (UINT64) -1;
    }
  }

  if (Step == 0) {
    ManualInput = TRUE;
  } else {
    ManualInput = FALSE;
  }

  if ((Question->Operand == EFI_IFR_NUMERIC_OP) &&
      ((Question->Flags & EFI_IFR_DISPLAY) == EFI_IFR_DISPLAY_UINT_HEX)) {
    HexInput = TRUE;
  } else {
    HexInput = FALSE;
  }

  if (ManualInput) {
    if (HexInput) {
      InputWidth = Question->StorageWidth * 2;
    } else {
      switch (Question->StorageWidth) {
      case 1:
        InputWidth = 3;
        break;

      case 2:
        InputWidth = 5;
        break;

      case 4:
        InputWidth = 10;
        break;

      case 8:
        InputWidth = 20;
        break;

      default:
        InputWidth = 0;
        break;
      }
    }

    InputText[0] = LEFT_NUMERIC_DELIMITER;
    SetUnicodeMem (InputText + 1, InputWidth, L' ');
    InputText[InputWidth + 1] = RIGHT_NUMERIC_DELIMITER;
    InputText[InputWidth + 2] = L'\0';

    PrintAt (Column, Row, InputText);
    Column++;
  }

  //
  // First time we enter this handler, we need to check to see if
  // we were passed an increment or decrement directive
  //
  do {
    Key.UnicodeChar = CHAR_NULL;
    if (gDirection != 0) {
      Key.ScanCode  = gDirection;
      gDirection    = 0;
      goto TheKey2;
    }

    Status = WaitForKeyStroke (&Key);

TheKey2:
    switch (Key.UnicodeChar) {

    case '+':
    case '-':
      if (Key.UnicodeChar == '+') {
        Key.ScanCode = SCAN_RIGHT;
      } else {
        Key.ScanCode = SCAN_LEFT;
      }
      Key.UnicodeChar = CHAR_NULL;
      goto TheKey2;

    case CHAR_NULL:
      switch (Key.ScanCode) {
      case SCAN_LEFT:
      case SCAN_RIGHT:
        if (DateOrTime) {
          //
          // By setting this value, we will return back to the caller.
          // We need to do this since an auto-refresh will destroy the adjustment
          // based on what the real-time-clock is showing.  So we always commit
          // upon changing the value.
          //
          gDirection = SCAN_DOWN;
        }

        if (!ManualInput) {
          if (Key.ScanCode == SCAN_LEFT) {
            if (EditValue > Step) {
              EditValue = EditValue - Step;
            } else {
              EditValue = Minimum;
            }
          } else if (Key.ScanCode == SCAN_RIGHT) {
            EditValue = EditValue + Step;
            if (EditValue > Maximum) {
              EditValue = Maximum;
            }
          }

          EfiZeroMem (FormattedNumber, 21 * sizeof (CHAR16));
          if (Question->Operand == EFI_IFR_DATE_OP) {
            if (MenuOption->Sequence == 2) {
              //
              // Year
              //
              SPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%04d", (UINTN) EditValue);
            } else {
              //
              // Month/Day
              //
              SPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%02d", (UINTN) EditValue);
            }

            if (MenuOption->Sequence == 0) {
              FormattedNumber[EraseLen - 2] = DATE_SEPARATOR;
            } else if (MenuOption->Sequence == 1) {
              FormattedNumber[EraseLen - 1] = DATE_SEPARATOR;
            }
          } else if (Question->Operand == EFI_IFR_TIME_OP) {
            SPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%02d", (UINTN) EditValue);

            if (MenuOption->Sequence == 0) {
              FormattedNumber[EraseLen - 2] = TIME_SEPARATOR;
            } else if (MenuOption->Sequence == 1) {
              FormattedNumber[EraseLen - 1] = TIME_SEPARATOR;
            }
          } else {
            QuestionValue->Value.u64 = EditValue;
            PrintFormattedNumber (Question, FormattedNumber, 21 * sizeof (CHAR16));
          }

          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);
          for (Loop = 0; Loop < EraseLen; Loop++) {
            PrintAt (MenuOption->OptCol + Loop, MenuOption->Row, L" ");
          }
          gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT);

          if (MenuOption->Sequence == 0) {
            PrintCharAt (MenuOption->OptCol, Row, LEFT_NUMERIC_DELIMITER);
            Column = MenuOption->OptCol + 1;
          }

          PrintStringAt (Column, Row, FormattedNumber);

          if (!DateOrTime || MenuOption->Sequence == 2) {
            PrintChar (RIGHT_NUMERIC_DELIMITER);
          }

  		  goto EnterCarriageReturn;
        }
        break;

      case SCAN_UP:
      case SCAN_DOWN:
        goto EnterCarriageReturn;

      case SCAN_ESC:
        return EFI_DEVICE_ERROR;

      default:
        break;
      }

      break;

EnterCarriageReturn:

    case CHAR_CARRIAGE_RETURN:
      //
      // Store Edit value back to Question
      //
      if (Question->Operand == EFI_IFR_DATE_OP) {
        switch (MenuOption->Sequence) {
        case 0:
          QuestionValue->Value.date.Month = (UINT8) EditValue;
          break;

        case 1:
          QuestionValue->Value.date.Day = (UINT8) EditValue;
          break;

        case 2:
          QuestionValue->Value.date.Year = (UINT16) EditValue;
          break;

        default:
          break;
        }
      } else if (Question->Operand == EFI_IFR_TIME_OP) {
        switch (MenuOption->Sequence) {
        case 0:
          QuestionValue->Value.time.Hour = (UINT8) EditValue;
          break;

        case 1:
          QuestionValue->Value.time.Minute = (UINT8) EditValue;
          break;

        case 2:
          QuestionValue->Value.time.Second = (UINT8) EditValue;
          break;

        default:
          break;
        }
      } else {
        //
        // Numeric
        //
        QuestionValue->Value.u64 = EditValue;
      }

      //
      // Check to see if the Value is something reasonable against consistency limitations.
      // If not, let's kick the error specified.
      //
      Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);
      if (EFI_ERROR (Status)) {
        //
        // Input value is not valid, restore Question Value
        //
        GetQuestionValue (FormSet, Form, Question, TRUE);
      } else {
        SetQuestionValue (FormSet, Form, Question, TRUE);
        if (!DateOrTime || (Question->Storage != NULL)) {
          //
          // NV flag is unnecessary for RTC type of Date/Time
          //
          UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);
        }
      }

      return Status;
      break;

    case CHAR_BACKSPACE:
      if (ManualInput) {
        if (Count == 0) {
          break;
        }
        //
        // Remove a character
        //
        EditValue = PreviousNumber[Count - 1];
        UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, FALSE);
        Count--;
        Column--;
        PrintAt (Column, Row, L" ");
      }
      break;

    default:
      if (ManualInput) {
        if (HexInput) {
          if (!IsHexDigit (&Digital, Key.UnicodeChar)) {
            UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, TRUE);
            break;
          }
        } else {
          if (Key.UnicodeChar > L'9' || Key.UnicodeChar < L'0') {
            UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, TRUE);
            break;
          }
        }

        //
        // If Count exceed input width, there is no way more is valid
        //
        if (Count >= InputWidth) {
          break;
        }
        //
        // Someone typed something valid!
        //
        if (Count != 0) {
          if (HexInput) {
            EditValue = LShiftU64 (EditValue, 4) + Digital;
          } else {
            //
            // EditValue = EditValue * 10 + (Key.UnicodeChar - L'0');
            //
            EditValue = LShiftU64 (EditValue, 3) + LShiftU64 (EditValue, 1) + (Key.UnicodeChar - L'0');
          }
        } else {
          if (HexInput) {
            EditValue = Digital;
          } else {
            EditValue = Key.UnicodeChar - L'0';
          }
        }

        if (EditValue > Maximum) {
          UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, TRUE);
          EditValue = PreviousNumber[Count];
          break;
        } else {
          UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, FALSE);
        }

        Count++;
        PreviousNumber[Count] = EditValue;

        PrintCharAt (Column, Row, Key.UnicodeChar);
        Column++;
      }
      break;
    }
  } while (TRUE);

  return EFI_SUCCESS;
}
Exemplo n.º 17
0
unsigned char * NEAR SRAMalloc(NEAR unsigned char nBytes)
{
	#if defined(__C30__)
		return (unsigned char *)malloc((size_t)nBytes);
	#else
	
    	SALLOC * NEAR       pHeap;
		#ifdef MAKE_INTERRUPT_SAFE
		    BYTE                saveGIEH;
		#endif
	    NEAR SALLOC         segHeader;
    	NEAR unsigned char  segLen;
	    SALLOC * NEAR       temp;


    	#ifdef MAKE_INTERRUPT_SAFE
        	saveGIEH = 0;
	        if (INTCONbits.GIEH)
    	        saveGIEH = 1;
        	INTCONbits.GIEH = 0;
	    #endif


    	#ifdef ENABLE_DEBUG
        	ConsolePutROMString( (ROM char * const)"Alloc " );
	        PrintChar(nBytes);
			printf("\r\n");
    	#endif

	    // Do not allow allocation above the max minus one bytes.  Also, do
    	// not allow a zero length packet.  Could cause problems.
	    if ((nBytes > (_MAX_SEGMENT_SIZE - 1))  ||
    	    (nBytes == 0))
    	{
        	#ifdef MAKE_INTERRUPT_SAFE
            	INTCONbits.GIEH = saveGIEH;
	        #endif
    	    return (0);
	    }

    	// Init the pointer to the heap
	    pHeap = (SALLOC *)_uDynamicHeap;

    	while (1)
	    {
    	    #ifdef ENABLE_DEBUG
        	    ConsolePutROMString( (ROM char * const)" check " );
            	PrintChar( (BYTE)((WORD)pHeap>>8) );
	            PrintChar( (BYTE)((WORD)pHeap&0xff) );
    	    #endif

        	// Get the header of the segment
	        segHeader = *pHeap;

    	    // Extract the segment length from the segment
        	segLen = segHeader.bits.count - 1;

	        // A null segment indicates the end of the table
    	    if (segHeader.byte == 0)
        	{
            	#ifdef ENABLE_DEBUG
                	ConsolePutROMString( (ROM char * const)" TableEnd\r\n" );
	            #endif
    	        #ifdef MAKE_INTERRUPT_SAFE
        	        INTCONbits.GIEH = saveGIEH;
            	#endif
	            return (0);
    	    }

        	// If this segment is not allocated then attempt to allocate it
	        if (!(segHeader.bits.alloc))
    	    {
        	    // If the free segment is too small then attempt to merge
            	if (nBytes > segLen)
	            {
    	            #ifdef ENABLE_DEBUG
        	            ConsolePutROMString( (ROM char * const)" merge" );
            	    #endif
                	// If the merge fails them move on to the next segment
	                if (!(_SRAMmerge(pHeap)))
    	            {
        	            pHeap +=(WORD)(segHeader.bits.count);
            	    }
                	// Fall through so we can check the newly created segment.
	            }
    	        else

        	    // If the segment length matches the request then allocate the
            	// header and return the pointer
	            if (nBytes == segLen)
    	        {
        	        // Allocate the segment
            	    (*pHeap).bits.alloc = 1;

                	// Return the pointer to the caller
	                #ifdef MAKE_INTERRUPT_SAFE
    	                INTCONbits.GIEH = saveGIEH;
        	        #endif
            	    #ifdef ENABLE_DEBUG
                	    ConsolePutROMString( (ROM char * const)" Found\r\n" );
	                #endif
    	            return ((unsigned char *)(pHeap + 1));
        	    }

            	// Else create a new segment
	            else
    	        {
        	        // Reset the header to point to a new segment
            	    (*pHeap).byte = nBytes + 0x81;

                	// Remember the pointer to the first segment
	                temp = pHeap + 1;

    	            // Point to the new segment
        	        pHeap += (WORD)(nBytes + 1);

            	    // Insert the header for the new segment
                	(*pHeap).byte = segLen - nBytes;

	                // Return the pointer to the user
    	            #ifdef MAKE_INTERRUPT_SAFE
        	            INTCONbits.GIEH = saveGIEH;
            	    #endif
                	#ifdef ENABLE_DEBUG
                    	ConsolePutROMString( (ROM char * const)" Found\r\n" );
	                #endif
    	            return ((unsigned char *) temp);
        	    }
	        }

    	    // else set the pointer to the next segment header in the heap
        	else
	        {
    	        pHeap += (WORD)segHeader.bits.count;
        	}
	    }

    	#ifdef MAKE_INTERRUPT_SAFE
        	INTCONbits.GIEH = saveGIEH;
	    #endif
    	#ifdef ENABLE_DEBUG
        	ConsolePutROMString( (ROM char * const)" ???\r\n" );
	    #endif
    	return (0);
	#endif    
}
Exemplo n.º 18
0
int
main()
{
    array = (int*)ShmAllocate(sizeof(int)*(SIZE+3));  // queue[SIZE], head, tail, count
    int x, i, j, seminit = 1, y;
    int pid[NUM_DEQUEUER+NUM_ENQUEUER];

    for (i=0; i<SIZE; i++) array[i] = -1;
    array[SIZE] = 0;
    array[SIZE+1] = 0;
    array[SIZE+2] = 0;

    semid = SemGet(SEM_KEY1);
    SemCtl(semid, SYNCH_SET, &seminit);

    stdoutsemid = SemGet(SEM_KEY2);
    SemCtl(stdoutsemid, SYNCH_SET, &seminit);

    notFullid = CondGet(COND_KEY1);
    notEmptyid = CondGet(COND_KEY2);

    int temp;
    temp = -11;
    SemCtl(semid,SYNCH_GET,&temp);
    PrintInt(temp);
    for (i=0; i<NUM_DEQUEUER; i++) {
       x = Fork();
       if (x == 0) {
          for (j=0; j<NUM_DEQUEUE_OP; j++) {
             x = Dequeue (i, &y);
             SemOp(stdoutsemid, -1);
             PrintString("Dequeuer ");
             PrintInt(i);
             PrintString(": Got ");
             PrintInt(x);
             PrintString(" from slot ");
             PrintInt(y);
             PrintChar('\n');
             SemOp(stdoutsemid, 1);
          }
          Exit(DEQUEUE_EXIT_CODE);
       }
       pid[i] = x;
    }
    
    for (i=0; i<NUM_ENQUEUER; i++) {
       x = Fork();
       if (x == 0) {
          x = i*NUM_ENQUEUE_OP;
          for (j=0; j<NUM_ENQUEUE_OP; j++) {
             y = Enqueue (x+j, i);
             SemOp(stdoutsemid, -1);
             PrintString("Enqueuer ");
             PrintInt(i);
             PrintString(": Inserted ");
             PrintInt(x+j);
             PrintString(" in slot ");
             PrintInt(y);
             PrintChar('\n');
             SemOp(stdoutsemid, 1);
          }
          Exit(ENQUEUE_EXIT_CODE);
       }
       pid[i+NUM_DEQUEUER] = x;
    }

    for (i=0; i<NUM_DEQUEUER+NUM_ENQUEUER; i++) {
       x = Join(pid[i]);
       SemOp(stdoutsemid, -1);
       PrintString("Parent joined with ");
       PrintInt(pid[i]);
       PrintString(" having exit code ");
       PrintInt(x);
       PrintChar('\n');
       SemOp(stdoutsemid, 1);
    }
    SemCtl(semid, SYNCH_REMOVE, 0);
    SemCtl(stdoutsemid, SYNCH_REMOVE, 0);
    CondRemove(notFullid);
    CondRemove(notEmptyid);

    return 0;
}
Exemplo n.º 19
0
int Window::mvaddchar(int x, int y, gunichar uc)
{
  wmove(p->win, y, x);
  return PrintChar(uc);
}
Exemplo n.º 20
0
/**
  This routine reads a numeric value from the user input.

  @param  Selection         Pointer to current selection.
  @param  MenuOption        Pointer to the current input menu.

  @retval EFI_SUCCESS       If numerical input is read successfully
  @retval EFI_DEVICE_ERROR  If operation fails

**/
EFI_STATUS
GetNumericInput (
  IN  UI_MENU_SELECTION           *Selection,
  IN  UI_MENU_OPTION              *MenuOption
  )
{
  EFI_STATUS              Status;
  UINTN                   Column;
  UINTN                   Row;
  CHAR16                  InputText[MAX_NUMERIC_INPUT_WIDTH];
  CHAR16                  FormattedNumber[MAX_NUMERIC_INPUT_WIDTH - 1];
  UINT64                  PreviousNumber[MAX_NUMERIC_INPUT_WIDTH - 3];
  UINTN                   Count;
  UINTN                   Loop;
  BOOLEAN                 ManualInput;
  BOOLEAN                 HexInput;
  BOOLEAN                 DateOrTime;
  UINTN                   InputWidth;
  UINT64                  EditValue;
  UINT64                  Step;
  UINT64                  Minimum;
  UINT64                  Maximum;
  UINTN                   EraseLen;
  UINT8                   Digital;
  EFI_INPUT_KEY           Key;
  EFI_HII_VALUE           *QuestionValue;
  FORM_BROWSER_FORM       *Form;
  FORM_BROWSER_FORMSET    *FormSet;
  FORM_BROWSER_STATEMENT  *Question;

  Column            = MenuOption->OptCol;
  Row               = MenuOption->Row;
  PreviousNumber[0] = 0;
  Count             = 0;
  InputWidth        = 0;
  Digital           = 0;

  FormSet       = Selection->FormSet;
  Form          = Selection->Form;
  Question      = MenuOption->ThisTag;
  QuestionValue = &Question->HiiValue;
  Step          = Question->Step;
  Minimum       = Question->Minimum;
  Maximum       = Question->Maximum;

  //
  // Only two case, user can enter to this function: Enter and +/- case.
  // In Enter case, gDirection = 0; in +/- case, gDirection = SCAN_LEFT/SCAN_WRIGHT
  //
  ManualInput        = (BOOLEAN)(gDirection == 0 ? TRUE : FALSE);

  if ((Question->Operand == EFI_IFR_DATE_OP) || (Question->Operand == EFI_IFR_TIME_OP)) {
    DateOrTime = TRUE;
  } else {
    DateOrTime = FALSE;
  }

  //
  // Prepare Value to be edit
  //
  EraseLen = 0;
  EditValue = 0;
  if (Question->Operand == EFI_IFR_DATE_OP) {
    Step = 1;
    Minimum = 1;

    switch (MenuOption->Sequence) {
    case 0:
      Maximum = 12;
      EraseLen = 4;
      EditValue = QuestionValue->Value.date.Month;
      break;

    case 1:
      switch (QuestionValue->Value.date.Month) {
      case 2:
        if ((QuestionValue->Value.date.Year % 4) == 0  && 
            ((QuestionValue->Value.date.Year % 100) != 0 || 
            (QuestionValue->Value.date.Year % 400) == 0)) {
          Maximum = 29;
        } else {
          Maximum = 28;
        }
        break;
      case 4:
      case 6:
      case 9:
      case 11:
        Maximum = 30;
        break;
      default:
        Maximum = 31;
        break;
      } 

      EraseLen = 3;
      EditValue = QuestionValue->Value.date.Day;
      break;

    case 2:
      Maximum = 0xffff;
      EraseLen = 5;
      EditValue = QuestionValue->Value.date.Year;
      break;

    default:
      break;
    }
  } else if (Question->Operand == EFI_IFR_TIME_OP) {
    Step = 1;
    Minimum = 0;

    switch (MenuOption->Sequence) {
    case 0:
      Maximum = 23;
      EraseLen = 4;
      EditValue = QuestionValue->Value.time.Hour;
      break;

    case 1:
      Maximum = 59;
      EraseLen = 3;
      EditValue = QuestionValue->Value.time.Minute;
      break;

    case 2:
      Maximum = 59;
      EraseLen = 3;
      EditValue = QuestionValue->Value.time.Second;
      break;

    default:
      break;
    }
  } else {
    //
    // Numeric
    //
    EraseLen = gOptionBlockWidth;
    EditValue = QuestionValue->Value.u64;
    if (Maximum == 0) {
      Maximum = (UINT64) -1;
    }
  }

  if ((Question->Operand == EFI_IFR_NUMERIC_OP) &&
      ((Question->Flags & EFI_IFR_DISPLAY) == EFI_IFR_DISPLAY_UINT_HEX)) {
    HexInput = TRUE;
  } else {
    HexInput = FALSE;
  }

  //
  // Enter from "Enter" input, clear the old word showing.
  //
  if (ManualInput) {
    if (Question->Operand == EFI_IFR_NUMERIC_OP) {
      if (HexInput) {
        InputWidth = Question->StorageWidth * 2;
      } else {
        switch (Question->StorageWidth) {
        case 1:
          InputWidth = 3;
          break;

        case 2:
          InputWidth = 5;
          break;

        case 4:
          InputWidth = 10;
          break;

        case 8:
          InputWidth = 20;
          break;

        default:
          InputWidth = 0;
          break;
        }
      }

      InputText[0] = LEFT_NUMERIC_DELIMITER;
      SetUnicodeMem (InputText + 1, InputWidth, L' ');
      ASSERT (InputWidth + 2 < MAX_NUMERIC_INPUT_WIDTH);
      InputText[InputWidth + 1] = RIGHT_NUMERIC_DELIMITER;
      InputText[InputWidth + 2] = L'\0';

      PrintAt (Column, Row, InputText);
      Column++;
    }

    if (Question->Operand == EFI_IFR_DATE_OP) {
      if (MenuOption->Sequence == 2) {
        InputWidth = 4;
      } else {
        InputWidth = 2;
      }

      if (MenuOption->Sequence == 0) {
        InputText[0] = LEFT_NUMERIC_DELIMITER;
        SetUnicodeMem (InputText + 1, InputWidth, L' ');
      } else {
        SetUnicodeMem (InputText, InputWidth, L' ');
      }

      if (MenuOption->Sequence == 2) {
        InputText[InputWidth + 1] = RIGHT_NUMERIC_DELIMITER;
      } else {
        InputText[InputWidth + 1] = DATE_SEPARATOR;
      }
      InputText[InputWidth + 2] = L'\0';

      PrintAt (Column, Row, InputText);
      if (MenuOption->Sequence == 0) {
        Column++;
      }
    }

    if (Question->Operand == EFI_IFR_TIME_OP) {
      InputWidth = 2;

      if (MenuOption->Sequence == 0) {
        InputText[0] = LEFT_NUMERIC_DELIMITER;
        SetUnicodeMem (InputText + 1, InputWidth, L' ');
      } else {
        SetUnicodeMem (InputText, InputWidth, L' ');
      }

      if (MenuOption->Sequence == 2) {
        InputText[InputWidth + 1] = RIGHT_NUMERIC_DELIMITER;
      } else {
        InputText[InputWidth + 1] = TIME_SEPARATOR;
      }
      InputText[InputWidth + 2] = L'\0';

      PrintAt (Column, Row, InputText);
      if (MenuOption->Sequence == 0) {
        Column++;
      }
    }
  }

  //
  // First time we enter this handler, we need to check to see if
  // we were passed an increment or decrement directive
  //
  do {
    Key.UnicodeChar = CHAR_NULL;
    if (gDirection != 0) {
      Key.ScanCode  = gDirection;
      gDirection    = 0;
      goto TheKey2;
    }

    Status = WaitForKeyStroke (&Key);

TheKey2:
    switch (Key.UnicodeChar) {

    case '+':
    case '-':
      if (Key.UnicodeChar == '+') {
        Key.ScanCode = SCAN_RIGHT;
      } else {
        Key.ScanCode = SCAN_LEFT;
      }
      Key.UnicodeChar = CHAR_NULL;
      goto TheKey2;

    case CHAR_NULL:
      switch (Key.ScanCode) {
      case SCAN_LEFT:
      case SCAN_RIGHT:
        if (DateOrTime && !ManualInput) {
          //
          // By setting this value, we will return back to the caller.
          // We need to do this since an auto-refresh will destroy the adjustment
          // based on what the real-time-clock is showing.  So we always commit
          // upon changing the value.
          //
          gDirection = SCAN_DOWN;
        }

        if ((Step != 0) && !ManualInput) {
          if (Key.ScanCode == SCAN_LEFT) {
            if (EditValue >= Minimum + Step) {
              EditValue = EditValue - Step;
            } else if (EditValue > Minimum){
              EditValue = Minimum;
            } else {
              EditValue = Maximum;
            }
          } else if (Key.ScanCode == SCAN_RIGHT) {
            if (EditValue + Step <= Maximum) {
              EditValue = EditValue + Step;
            } else if (EditValue < Maximum) {
              EditValue = Maximum;
            } else {
              EditValue = Minimum;
            }
          }

          ZeroMem (FormattedNumber, 21 * sizeof (CHAR16));
          if (Question->Operand == EFI_IFR_DATE_OP) {
            if (MenuOption->Sequence == 2) {
              //
              // Year
              //
              UnicodeSPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%04d", (UINT16) EditValue);
            } else {
              //
              // Month/Day
              //
              UnicodeSPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%02d", (UINT8) EditValue);
            }

            if (MenuOption->Sequence == 0) {
              ASSERT (EraseLen >= 2);
              FormattedNumber[EraseLen - 2] = DATE_SEPARATOR;
            } else if (MenuOption->Sequence == 1) {
              ASSERT (EraseLen >= 1);
              FormattedNumber[EraseLen - 1] = DATE_SEPARATOR;
            }
          } else if (Question->Operand == EFI_IFR_TIME_OP) {
            UnicodeSPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%02d", (UINT8) EditValue);

            if (MenuOption->Sequence == 0) {
              ASSERT (EraseLen >= 2);
              FormattedNumber[EraseLen - 2] = TIME_SEPARATOR;
            } else if (MenuOption->Sequence == 1) {
              ASSERT (EraseLen >= 1);
              FormattedNumber[EraseLen - 1] = TIME_SEPARATOR;
            }
          } else {
            QuestionValue->Value.u64 = EditValue;
            PrintFormattedNumber (Question, FormattedNumber, 21 * sizeof (CHAR16));
          }

          gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND);
          for (Loop = 0; Loop < EraseLen; Loop++) {
            PrintAt (MenuOption->OptCol + Loop, MenuOption->Row, L" ");
          }
          gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextHighlightColor) | PcdGet8 (PcdBrowserFieldBackgroundHighlightColor));

          if (MenuOption->Sequence == 0) {
            PrintCharAt (MenuOption->OptCol, Row, LEFT_NUMERIC_DELIMITER);
            Column = MenuOption->OptCol + 1;
          }

          PrintStringAt (Column, Row, FormattedNumber);

          if (!DateOrTime || MenuOption->Sequence == 2) {
            PrintChar (RIGHT_NUMERIC_DELIMITER);
          }
        }

        goto EnterCarriageReturn;
        break;

      case SCAN_UP:
      case SCAN_DOWN:
        goto EnterCarriageReturn;

      case SCAN_ESC:
        return EFI_DEVICE_ERROR;

      default:
        break;
      }

      break;

EnterCarriageReturn:

    case CHAR_CARRIAGE_RETURN:
      //
      // Store Edit value back to Question
      //
      if (Question->Operand == EFI_IFR_DATE_OP) {
        switch (MenuOption->Sequence) {
        case 0:
          QuestionValue->Value.date.Month = (UINT8) EditValue;
          break;

        case 1:
          QuestionValue->Value.date.Day = (UINT8) EditValue;
          break;

        case 2:
          QuestionValue->Value.date.Year = (UINT16) EditValue;
          break;

        default:
          break;
        }
      } else if (Question->Operand == EFI_IFR_TIME_OP) {
        switch (MenuOption->Sequence) {
        case 0:
          QuestionValue->Value.time.Hour = (UINT8) EditValue;
          break;

        case 1:
          QuestionValue->Value.time.Minute = (UINT8) EditValue;
          break;

        case 2:
          QuestionValue->Value.time.Second = (UINT8) EditValue;
          break;

        default:
          break;
        }
      } else {
        //
        // Numeric
        //
        QuestionValue->Value.u64 = EditValue;
      }

      //
      // Adjust the value to the correct one.
      // Sample like: 2012.02.29 -> 2013.02.29 -> 2013.02.01
      //              2013.03.29 -> 2013.02.29 -> 2013.02.28
      //
      if (Question->Operand == EFI_IFR_DATE_OP && 
        (MenuOption->Sequence == 0 || MenuOption->Sequence == 2)) {
        AdjustQuestionValue (Question, (UINT8)MenuOption->Sequence);
      }

      //
      // Check to see if the Value is something reasonable against consistency limitations.
      // If not, let's kick the error specified.
      //
      Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);
      if (EFI_ERROR (Status)) {
        //
        // Input value is not valid, restore Question Value
        //
        GetQuestionValue (FormSet, Form, Question, TRUE);
      } else {
        SetQuestionValue (FormSet, Form, Question, TRUE);
        if (!DateOrTime || (Question->Storage != NULL)) {
          //
          // NV flag is unnecessary for RTC type of Date/Time
          //
          UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);
        }
      }

      return Status;
      break;

    case CHAR_BACKSPACE:
      if (ManualInput) {
        if (Count == 0) {
          break;
        }
        //
        // Remove a character
        //
        EditValue = PreviousNumber[Count - 1];
        UpdateStatusBar (Selection, INPUT_ERROR, Question->QuestionFlags, FALSE);
        Count--;
        Column--;
        PrintAt (Column, Row, L" ");
      }
      break;

    default:
      if (ManualInput) {
        if (HexInput) {
          if ((Key.UnicodeChar >= L'0') && (Key.UnicodeChar <= L'9')) {
            Digital = (UINT8) (Key.UnicodeChar - L'0');
          } else if ((Key.UnicodeChar >= L'A') && (Key.UnicodeChar <= L'F')) {
            Digital = (UINT8) (Key.UnicodeChar - L'A' + 0x0A);
          } else if ((Key.UnicodeChar >= L'a') && (Key.UnicodeChar <= L'f')) {
            Digital = (UINT8) (Key.UnicodeChar - L'a' + 0x0A);
          } else {
            UpdateStatusBar (Selection, INPUT_ERROR, Question->QuestionFlags, TRUE);
            break;
          }
        } else {
          if (Key.UnicodeChar > L'9' || Key.UnicodeChar < L'0') {
            UpdateStatusBar (Selection, INPUT_ERROR, Question->QuestionFlags, TRUE);
            break;
          }
        }

        //
        // If Count exceed input width, there is no way more is valid
        //
        if (Count >= InputWidth) {
          break;
        }
        //
        // Someone typed something valid!
        //
        if (Count != 0) {
          if (HexInput) {
            EditValue = LShiftU64 (EditValue, 4) + Digital;
          } else {
            EditValue = MultU64x32 (EditValue, 10) + (Key.UnicodeChar - L'0');
          }
        } else {
          if (HexInput) {
            EditValue = Digital;
          } else {
            EditValue = Key.UnicodeChar - L'0';
          }
        }

        if (EditValue > Maximum) {
          UpdateStatusBar (Selection, INPUT_ERROR, Question->QuestionFlags, TRUE);
          ASSERT (Count < sizeof (PreviousNumber) / sizeof (PreviousNumber[0]));
          EditValue = PreviousNumber[Count];
          break;
        } else {
          UpdateStatusBar (Selection, INPUT_ERROR, Question->QuestionFlags, FALSE);
        }

        Count++;
        ASSERT (Count < (sizeof (PreviousNumber) / sizeof (PreviousNumber[0])));
        PreviousNumber[Count] = EditValue;

        PrintCharAt (Column, Row, Key.UnicodeChar);
        Column++;
      }
      break;
    }
  } while (TRUE);

}
Exemplo n.º 21
0
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//
// PrintCRLF - Print out CR/LF
//
// Inputs:      None.
//
// Outputs:     None.
//
void PrintCRLF(void) { PrintChar('\r'); PrintChar('\n'); }
Exemplo n.º 22
0
static byte AskPassword (Password &password, int& pin)
{
	size_t pos = 0;
	byte scanCode;
	byte asciiCode;
	byte hidePassword = 1;

	pin = 0;

	Print ("Enter password");
	Print (PreventNormalSystemBoot ? " for hidden system:\r\n" : ": ");

	while (true)
	{
		asciiCode = GetKeyboardChar (&scanCode);

		switch (scanCode)
		{
		case TC_BIOS_KEY_ENTER:
			ClearBiosKeystrokeBuffer();
			PrintEndl();

			password.Length = pos;
			break;

		case TC_BIOS_KEY_BACKSPACE:
			if (pos > 0)
			{
				if (pos < MAX_PASSWORD)
					PrintBackspace();
				else
					PrintCharAtCursor (' ');

				--pos;
			}
			continue;

		case TC_BIOS_KEY_F5:
			hidePassword ^= 0x01;
			continue;

		default:
			if (scanCode == TC_BIOS_KEY_ESC || IsMenuKey (scanCode))
			{
				burn (password.Text, sizeof (password.Text));
				ClearBiosKeystrokeBuffer();

				PrintEndl();
				return scanCode;
			}
		}

		if (TC_BIOS_KEY_ENTER == scanCode)
			break;

		if (!IsPrintable (asciiCode) || pos == MAX_PASSWORD)
		{
			Beep();
			continue;
		}

		password.Text[pos++] = asciiCode;
		if (hidePassword) asciiCode = '*';
		if (pos < MAX_PASSWORD)
			PrintChar (asciiCode);
		else
			PrintCharAtCursor (asciiCode);
	}

	pos = 0;
	Print ("PIM: ");

	while (true)
	{
		asciiCode = GetKeyboardChar (&scanCode);

		switch (scanCode)
		{
		case TC_BIOS_KEY_ENTER:
			ClearBiosKeystrokeBuffer();
			PrintEndl();

			return TC_BIOS_KEY_ENTER;

		case TC_BIOS_KEY_BACKSPACE:
			if (pos > 0)
			{
				if (pos < MAX_PIM)
					PrintBackspace();
				else
					PrintCharAtCursor (' ');

				--pos;
				pin /= 10;
			}
			continue;

		default:
			if (scanCode == TC_BIOS_KEY_ESC || IsMenuKey (scanCode))
			{
				burn (password.Text, sizeof (password.Text));
				ClearBiosKeystrokeBuffer();

				PrintEndl();
				return scanCode;
			}
		}

		if (!IsDigit (asciiCode) || pos == MAX_PIM)
		{
			Beep();
			continue;
		}

		pin = 10*pin + (asciiCode - '0');
		pos++;

		if (pos < MAX_PIM)
			PrintChar (asciiCode);
		else
			PrintCharAtCursor (asciiCode);
	}
}
Exemplo n.º 23
0
int main()
{
	char c = ReadChar();
	PrintChar(c);
	return 0;
}
Exemplo n.º 24
0
    void NVMWrite( NVM_ADDR *dest, BYTE *src, BYTE count )
    {
    NVM_ADDR *pEraseBlock;
    BYTE    *memBlock;
    BYTE *pMemBlock;
    BYTE writeIndex;
    BYTE writeStart;
    BYTE writeCount;
    BYTE oldGIEH;
    DWORD oldTBLPTR;

    #if defined(VERIFY_WRITE)
        while (memcmppgm2ram( src, (ROM void *)dest, count ))
    #elif defined(CHECK_BEFORE_WRITE)
        if (memcmppgm2ram( src, (ROM void *)dest, count ))
    #endif
        {
            if ((memBlock = SRAMalloc( ERASE_BLOCK_SIZE )) == NULL)
                return;

            #if 0
                UART2PutROMString( (ROM char * const)"NVMWrite at " );
                PrintChar( (BYTE)(((WORD)dest>>8)&0xFF) );
                PrintChar( (BYTE)((WORD)dest&0xFF) );
                UART2PutROMString( (ROM char * const)" count " );
                PrintChar( count );
                UART2PutROMString( (ROM char * const)"\r\n" );
            #endif

            // First, get the nearest "left" erase block boundary
            pEraseBlock = (NVM_ADDR*)((long)dest & (long)(~(ERASE_BLOCK_SIZE-1)));
            writeStart = (BYTE)((BYTE)dest & (BYTE)(ERASE_BLOCK_SIZE-1));

            while( count )
            {
                // Now read the entire erase block size into RAM.
                NVMRead(memBlock, (ROM void*)pEraseBlock, ERASE_BLOCK_SIZE);

                // Erase the block.
                // Erase flash memory, enable write control.
                EECON1 = 0x94;

                oldGIEH = 0;
                if ( INTCONbits.GIEH )
                    oldGIEH = 1;
                INTCONbits.GIEH = 0;

                #if defined(MCHP_C18)
                    TBLPTR = (unsigned short long)pEraseBlock;
                #elif defined(HITECH_C18)
                    TBLPTR = (void*)pEraseBlock;
                #endif

                CLRWDT();

                EECON2 = 0x55;
                EECON2 = 0xaa;
                EECON1bits.WR = 1;
                NOP();

                EECON1bits.WREN = 0;

                oldTBLPTR = TBLPTR;

                if ( oldGIEH )
                    INTCONbits.GIEH = 1;

                // Modify 64-byte block of RAM buffer as per what is required.
                pMemBlock = &memBlock[writeStart];
                while( writeStart < ERASE_BLOCK_SIZE && count )
                {
                    *pMemBlock++ = *src++;

                    count--;
                    writeStart++;
                }

                // After first block write, next start would start from 0.
                writeStart = 0;

                // Now write entire 64 byte block in one write block at a time.
                writeIndex = ERASE_BLOCK_SIZE / WRITE_BLOCK_SIZE;
                pMemBlock = memBlock;
                while( writeIndex )
                {

                    oldGIEH = 0;
                    if ( INTCONbits.GIEH )
                        oldGIEH = 1;
                    INTCONbits.GIEH = 0;

                    TBLPTR = oldTBLPTR;

                    // Load individual block
                    writeCount = WRITE_BLOCK_SIZE;
                    while( writeCount-- )
                    {
                        TABLAT = *pMemBlock++;

                        TBLWTPOSTINC();
                    }

                    // Start the write process: reposition tblptr back into memory block that we want to write to.
                    #if defined(MCHP_C18)
                        _asm tblrdpostdec _endasm
                    #elif defined(HITECH_C18)
                        asm(" tblrd*-");
                    #endif

                    // Write flash memory, enable write control.
                    EECON1 = 0x84;

                    CLRWDT();

                    EECON2 = 0x55;
                    EECON2 = 0xaa;
                    EECON1bits.WR = 1;
                    NOP();
                    EECON1bits.WREN = 0;

                    // One less block to write
                    writeIndex--;

                    TBLPTR++;

                    oldTBLPTR = TBLPTR;

                    if ( oldGIEH )
                        INTCONbits.GIEH = 1;
                }

                // Go back and do it all over again until we write all
                // data bytes - this time the next block.
        #if !defined(WIN32)
                pEraseBlock += ERASE_BLOCK_SIZE;
        #endif
            }

            SRAMfree( memBlock );
        }
    }
Exemplo n.º 25
0
void usart1_print(char* c) {
    u8 a = 0;
    while (c[a]) {
        PrintChar(c[a++]);
    }
}
Exemplo n.º 26
0
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//
// PrintStringP - Print out a serial PSTR string
//
// Inputs:      Text string to print
//
// Outputs:     None.
//
void PrintStringP(const char *String) {
    char    Char;

    while( (Char = pgm_read_byte(String++)) )
        PrintChar(Char);
    }
Exemplo n.º 27
0
void Printnumber(char singlechar)	//picks set of nibbles to send on to DoNibbles
{
	  switch(singlechar)
	  {
	    
	    case 0: PrintChar(0x10); break;
	    case 1: PrintChar(0x11); break;
	    case 2: PrintChar(0x12); break;	
	    case 3: PrintChar(0x13); break;	
	    case 4: PrintChar(0x14); break;	
	    case 5: PrintChar(0x15); break;	
	    case 6: PrintChar(0x16); break;	
	    case 7: PrintChar(0x17); break;
	    case 8: PrintChar(0x18); break;	
	    case 9: PrintChar(0x19); break;	
	    default:PrintChar(0x79); break;
	    
	  }
	  
	  
}