Example #1
0
/* FixedDelayTask: Changes the state of the task's attributed output I/O port before and
** after executing a fixed number of loop iterations The number of iterations is a param-
** eter transfered by main. */
void FixedDelayTask(void *argument)
{
  UINT32 i;
  TaskParametersDef *TaskParameters = (TaskParametersDef *)argument;
  ToggleBit(TaskParameters->GPIO_Pin);
  for (i = 0; i < TaskParameters->Delay; i += 1);
  ToggleBit(TaskParameters->GPIO_Pin);
  OSEndTask();
} /* end of FixedDelayTask */
Example #2
0
/* Connect is designed to be run in a different thread as it only 
   exits if wiiremote is either disabled or a connection is made*/
bool CWiiRemote::Connect()
{
#ifndef _DEBUG
  cwiid_set_err(ErrorCallback);
#endif
  while (!m_connected)
  {
    g_Ping->Send(m_Socket, m_MyAddr);
    int flags = 0;
    ToggleBit(flags, CWIID_FLAG_MESG_IFC);
    ToggleBit(flags, CWIID_FLAG_REPEAT_BTN);

    m_wiiremoteHandle = cwiid_connect(&m_btaddr, flags);
    if (m_wiiremoteHandle != NULL)
    {
      SetupWiiRemote();
      // get battery state etc.
      cwiid_state wiiremote_state;
      int err = cwiid_get_state(m_wiiremoteHandle, &wiiremote_state);
      if (!err)
      {
        char Mesg[1024];
        sprintf(Mesg, "%i%% battery remaining", static_cast<int>(((float)(wiiremote_state.battery)/CWIID_BATTERY_MAX)*100.0));
        CPacketNOTIFICATION notification("Wii Remote connected", Mesg, ICON_PNG, g_BluetoothIconPath.c_str());
        notification.Send(m_Socket, m_MyAddr);
      }
      else
      {
        printf("Problem probing for status of WiiRemote; cwiid_get_state returned non-zero\n");
        CPacketLOG log(LOGNOTICE, "Problem probing for status of WiiRemote; cwiid_get_state returned non-zero");
        log.Send(m_Socket, m_MyAddr);
        CPacketNOTIFICATION notification("Wii Remote connected", "", ICON_PNG, g_BluetoothIconPath.c_str());
        notification.Send(m_Socket, m_MyAddr);
      }
#ifdef CWIID_OLD
      /* CheckIn to say that this is the last msg, If this isn't called it could give issues if we Connects -> Disconnect and then try to connect again 
         the CWIID_OLD hack would automaticly disconnect the wiiremote as the lastmsg is too old. */
      CheckIn();
#endif      
      m_connected = true;

      CPacketLOG log(LOGNOTICE, "Sucessfully connected a WiiRemote");
      log.Send(m_Socket, m_MyAddr);
      return true;
    }
    //Here's a good place to have a quit flag check...

  }
  return false;
}
Example #3
0
/* ButtonTask: Checks if the button is still pressed and if not re-enables the button's
** ISR. (Also toggles a GPIO pin for debugging purposes.) */
void ButtonTask(void *argument)
{
  UINT32 i;
  TaskParametersDef *TaskParameters = (TaskParametersDef *)argument;
  ToggleBit(TaskParameters->Flag_Pin);
  for (i = 0; i < TaskParameters->Delay; i += 1);
  ToggleBit(TaskParameters->Flag_Pin);
  if (IsPressed(TaskParameters->Button_Pin))         // Is button still pressed?
     OSScheduleSuspendedTask(TaskParameters->event); // Yes, reschedule the task
  else {
     // No, clear interrupt flag to prevent button rebounds
     ClearInt(TaskParameters->Button_Pin);
     EnableInt(TaskParameters->Button_Pin);
  }
  OSSuspendSynchronousTask();
} /* end of ButtonTask */
Example #4
0
/* VariableDelayTask: Same as FixedDelayTask but performs an additional iteration every
** time the task is invoked and until it reaches a limit fixed by main. Once number of
** iterations attains the limit, the process restarts from 1. */
void VariableDelayTask(void *argument)
{ // Caution: Unfortunately, TI Code Composer does not directly comply with ANSI C that
  // dictates that static variables are initialized to 0 when no other initializer is
  // specified.
  static UINT32 k = 0;
  UINT32 i;
  TaskParametersDef *TaskParameters = (TaskParametersDef *)argument;
  ToggleBit(TaskParameters->GPIO_Pin);
  if (k >= TaskParameters->Delay)
     k = 1;
  else
     k += 100;
  for (i = 0; i < k; i++);
  ToggleBit(TaskParameters->GPIO_Pin);
  OSEndTask();
} /* end of VariableDelayTask */
Example #5
0
void CWiiRemote::Initialize(CAddress Addr, int Socket)
{
  m_connected = false;
  m_lastKeyPressed          = 0;
  m_LastKey                 = 0;
  m_buttonRepeat            = false;
  m_lastKeyPressedNunchuck  = 0;
  m_LastKeyNunchuck         = 0;
  m_buttonRepeatNunchuck    = false;
  m_useIRMouse              = true;
  m_rptMode                 = 0;

  m_Socket = Socket;
  m_MyAddr = Addr;

  m_NumSamples = WIIREMOTE_SAMPLES;

  m_MaxX = WIIREMOTE_X_MAX;
  m_MaxY = WIIREMOTE_Y_MAX;
  m_MinX = WIIREMOTE_X_MIN;
  m_MinY = WIIREMOTE_Y_MIN;
#ifdef CWIID_OLD
  m_LastMsgTime = getTicks();
#endif

  //All control bits are set to false when cwiid is started
  //Report Button presses
  ToggleBit(m_rptMode, CWIID_RPT_BTN);
  if (g_AllowNunchuck)
    ToggleBit(m_rptMode, CWIID_RPT_NUNCHUK);

  //If wiiremote is used as a mouse, then report the IR sources
#ifndef CWIID_OLD  
  if (m_useIRMouse) 
#endif
    ToggleBit(m_rptMode, CWIID_RPT_IR);	

  //Have the first and fourth LED on the Wiiremote shine when connected
  ToggleBit(m_ledState, CWIID_LED1_ON);	
  ToggleBit(m_ledState, CWIID_LED4_ON);
}
Example #6
0
void SysTick_Handler(void)
{
// длительность обработки прерывания 2 мкс при 72 МН
    ToggleBit( PortTest, TestPoint2 );
    MsCounter++;
    TsmTimeout++;
    RcvTimeout++;
    FlashTimeout++; 
    NetTimeout++; 
    SpiTimeout++;
    SendTimeout++;
}
Example #7
0
/* Disable mouse emulation */
void CWiiRemote::DisableMouseEmulation()
{
  if (!m_useIRMouse)
    return;

  m_useIRMouse = false;
#ifndef CWIID_OLD
  //We toggle IR Reporting (Save resources?)  
  if (m_rptMode & CWIID_RPT_IR)
    ToggleBit(m_rptMode, CWIID_RPT_IR);
  if (m_connected)
    SetRptMode();
#endif

  CPacketLOG log(LOGDEBUG, "Disabled WiiRemote mouse emulation");
  log.Send(m_Socket, m_MyAddr);
}
Example #8
0
void TIM5_IRQHandler(void)
{
short int itstatus = 0x0, itenable = 0x0;
  
// длительность обработки прерывания 2 мкс при 72 МН
    //if( GetOutBit( PortSpi2, Spi2_SS ) ) ClrBit( PortSpi2, Spi2_SS );
    itstatus = TIM5->SR & TIM_IT_Update;
    itenable = TIM5->DIER & TIM_IT_Update;
    if ((itstatus != RESET) && (itenable != RESET)) {
	TIM5->SR = ~TIM_IT_Update;
	ToggleBit( PortTest, TestPoint6 );
	FlagAxel = 1;
        /* Pin PB.07 toggling with frequency = ??? Hz */
        //if( (GPIOB->ODR & GPIO_Pin_6 ) != Bit_RESET ) GPIOB->BSRRH = GPIO_Pin_6;
	//else GPIOB->BSRRL = GPIO_Pin_6;
    }
}
Example #9
0
/**
 * Check the slope of a tile of a new station.
 * @param north_tile Norther tile of the station rect.
 * @param cur_tile Tile to check.
 * @param statspec Station spec.
 * @param axis Axis of the new station.
 * @param plat_len Platform length.
 * @param numtracks Number of platforms.
 * @return Succeeded or failed command.
 */
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
{
	TileIndexDiff diff = cur_tile - north_tile;
	Slope slope = GetTileSlope(cur_tile);

	StationResolverObject object(statspec, NULL, cur_tile, CBID_STATION_LAND_SLOPE_CHECK,
			(slope << 4) | (slope ^ (axis == AXIS_Y && HasBit(slope, CORNER_W) != HasBit(slope, CORNER_E) ? SLOPE_EW : 0)),
			(numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff)));
	object.station_scope.axis = axis;

	uint16 cb_res = object.ResolveCallback();

	/* Failed callback means success. */
	if (cb_res == CALLBACK_FAILED) return CommandCost();

	/* The meaning of bit 10 is inverted for a grf version < 8. */
	if (statspec->grf_prop.grffile->grf_version < 8) ToggleBit(cb_res, 10);
	return GetErrorMessageFromLocationCallbackResult(cb_res, statspec->grf_prop.grffile, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}
Example #10
0
global func SetBit(int iOldVal, int iBitNr, bool iBit)
  {
  if(GetBit(iOldVal, iBitNr) != (iBit != 0)) 
    return(ToggleBit(iOldVal, iBitNr));
  return(iOldVal);
  }
Example #11
0
	virtual void OnClick(Point pt, int widget, int click_count)
	{
		/* clicked a letter */
		if (widget >= WID_OSK_LETTERS) {
			WChar c = _keyboard[this->shift][widget - WID_OSK_LETTERS];

			if (!IsValidChar(c, this->qs->text.afilter)) return;

			if (this->qs->text.InsertChar(c)) this->OnEditboxChanged(WID_OSK_TEXT);

			if (HasBit(_keystate, KEYS_SHIFT)) {
				ToggleBit(_keystate, KEYS_SHIFT);
				this->UpdateOskState();
				this->SetDirty();
			}
			return;
		}

		switch (widget) {
			case WID_OSK_BACKSPACE:
				if (this->qs->text.DeleteChar(WKC_BACKSPACE)) this->OnEditboxChanged(WID_OSK_TEXT);
				break;

			case WID_OSK_SPECIAL:
				/*
				 * Anything device specific can go here.
				 * The button itself is hidden by default, and when you need it you
				 * can not hide it in the create event.
				 */
				break;

			case WID_OSK_CAPS:
				ToggleBit(_keystate, KEYS_CAPS);
				this->UpdateOskState();
				this->SetDirty();
				break;

			case WID_OSK_SHIFT:
				ToggleBit(_keystate, KEYS_SHIFT);
				this->UpdateOskState();
				this->SetDirty();
				break;

			case WID_OSK_SPACE:
				if (this->qs->text.InsertChar(' ')) this->OnEditboxChanged(WID_OSK_TEXT);
				break;

			case WID_OSK_LEFT:
				if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateData();
				break;

			case WID_OSK_RIGHT:
				if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateData();
				break;

			case WID_OSK_OK:
				if (this->qs->orig == NULL || strcmp(this->qs->text.buf, this->qs->orig) != 0) {
					/* pass information by simulating a button press on parent window */
					if (this->qs->ok_button >= 0) {
						this->parent->OnClick(pt, this->qs->ok_button, 1);
						/* Window gets deleted when the parent window removes itself. */
						return;
					}
				}
				delete this;
				break;

			case WID_OSK_CANCEL:
				if (this->qs->cancel_button >= 0) { // pass a cancel event to the parent window
					this->parent->OnClick(pt, this->qs->cancel_button, 1);
					/* Window gets deleted when the parent window removes itself. */
					return;
				} else { // or reset to original string
					qs->text.Assign(this->orig_str_buf);
					qs->text.MovePos(WKC_END);
					this->OnEditboxChanged(WID_OSK_TEXT);
					delete this;
				}
				break;
		}
	}
void Leds_RedToggle()
{
	ToggleBit(PORTE, 4);
}
void Leds_YellowToggle()
{
	ToggleBit(PORTE, 3);
}
void Leds_GreenToggle()
{
	ToggleBit(PORTE, 2);
}