Exemplo n.º 1
0
// Update screen and/or output changed joystick data to yaAGC.
void
yaAcaFrameClass::UpdateJoystick (void)
{
  static int LastAdjustedRoll = 1000, LastAdjustedPitch = 1000, LastAdjustedYaw = 1000;
  static int Last31 = -1;
  int New31, j;
  
  if (Roll.LastRawReading != Timer->Axes[Roll.Axis].CurrentRawReading)
    {	
      Roll.LastRawReading = Timer->Axes[Roll.Axis].CurrentRawReading;
      Timer->Translate (&Roll);
      ControllerRollLabel->SetLabel (wxString::Format (wxT ("%d"), Roll.CurrentAdjustedReading));
    }
  if (Pitch.LastRawReading != Timer->Axes[Pitch.Axis].CurrentRawReading)
    {	
      Pitch.LastRawReading = Timer->Axes[Pitch.Axis].CurrentRawReading;
      Timer->Translate (&Pitch);
      ControllerPitchLabel->SetLabel (wxString::Format (wxT ("%d"), Pitch.CurrentAdjustedReading));
    }
  if (Yaw.LastRawReading != Timer->Axes[Yaw.Axis].CurrentRawReading)
    {	
      Yaw.LastRawReading = Timer->Axes[Yaw.Axis].CurrentRawReading;
      Timer->Translate (&Yaw);
      ControllerYawLabel->SetLabel (wxString::Format (wxT ("%d"), Yaw.CurrentAdjustedReading));
    }
    
  // Report to yaAGC.
  New31 = 077777;
  if (Roll.CurrentAdjustedReading < 0)
    New31 &= ~040040;
  else if (Roll.CurrentAdjustedReading > 0)
    New31 &= ~040020;
  if (Yaw.CurrentAdjustedReading < 0)
    New31 &= ~040010;
  else if (Yaw.CurrentAdjustedReading > 0)
    New31 &= ~040004;
  if (Pitch.CurrentAdjustedReading < 0)
    New31 &= ~040002;
  else if (Pitch.CurrentAdjustedReading > 0)
    New31 &= ~040001;
  if (ServerSocket != -1 && New31 != Last31)
    {
      unsigned char Packet[8];
      Last31 = New31;
      // First, create the mask which will tell the CPU to only pay attention to
      // relevant bits of channel (031).
      FormIoPacket (0431, 040077, Packet);
      FormIoPacket (031, New31, &Packet[4]);
      // And, send it all.
      j = send (ServerSocket, (const char *) Packet, 8, MSG_NOSIGNAL);
      if (j == SOCKET_ERROR && SOCKET_BROKEN)
        {
	  close (ServerSocket);
	  ServerSocket = -1;
          fprintf (stdout, "\nServer connection lost.\n");
	  return;
	}
    }
    
  if (Roll.CurrentAdjustedReading != LastAdjustedRoll)
    {
      OutputTranslated (0170, LastAdjustedRoll = Roll.CurrentAdjustedReading);
    }
  if (Pitch.CurrentAdjustedReading != LastAdjustedPitch)
    {
      OutputTranslated (0166, LastAdjustedPitch = Pitch.CurrentAdjustedReading);
    }
  if (Yaw.CurrentAdjustedReading != LastAdjustedYaw)
    {
      OutputTranslated (0167, LastAdjustedYaw = Yaw.CurrentAdjustedReading);
    }
    
}
Exemplo n.º 2
0
// Print current logical joystick readings in terminal.
static void
PrintJoy (void)
{
  int j, Changed = 0, New31;
  static int Last31 = 0;
  
  // Report to yaAGC.
  New31 = 077777;
  if (Roll.CurrentAdjustedReading < 0)
    New31 &= ~040040;
  else if (Roll.CurrentAdjustedReading > 0)
    New31 &= ~040020;
  if (Yaw.CurrentAdjustedReading < 0)
    New31 &= ~040010;
  else if (Yaw.CurrentAdjustedReading > 0)
    New31 &= ~040004;
  if (Pitch.CurrentAdjustedReading < 0)
    New31 &= ~040002;
  else if (Pitch.CurrentAdjustedReading > 0)
    New31 &= ~040001;
  if (ServerSocket != -1 && (New31 != Last31 || First))
    {
      unsigned char Packet[8];
      Last31 = New31;
      // First, create the mask which will tell the CPU to only pay attention to
      // relevant bits of channel (031).
      FormIoPacket (0431, 040077, Packet);
      FormIoPacket (031, New31, &Packet[4]);
      // And, send it all.
      j = send (ServerSocket, Packet, 8, MSG_NOSIGNAL);
      if (j == SOCKET_ERROR && SOCKET_BROKEN)
        {
	  close (ServerSocket);
	  ServerSocket = -1;
          fprintf (stdout, "\nServer connection lost.\n");
	  return;
	}
    }
  if (Roll.CurrentAdjustedReading != LastRoll || First)
    {
      OutputTranslated (0170, Roll.CurrentAdjustedReading);
      Changed = 1;
    }
  if (Pitch.CurrentAdjustedReading != LastPitch || First)
    {
      OutputTranslated (0166, Pitch.CurrentAdjustedReading);
      Changed = 1;
    }
  if (Yaw.CurrentAdjustedReading != LastYaw || First)
    {
      OutputTranslated (0167, Yaw.CurrentAdjustedReading);
      Changed = 1;
    }
  // Local display.
  if (Changed)
    {
      fprintf (stdout, "\rRoll=%+03d\tPitch=%+03d\tYaw=%+03d", 
      	      LastRoll = Roll.CurrentAdjustedReading, 
	      LastPitch = Pitch.CurrentAdjustedReading, 
	      LastYaw = Yaw.CurrentAdjustedReading);
      fflush (stdout);
      First = 0;
    }
}
Exemplo n.º 3
0
static void
PrintJoy (void)
{
  int j, Changed = 0, New31;
  int ScaledRoll, ScaledPitch, ScaledYaw;
  static int TranslatedRoll = 0, TranslatedPitch = 0, TranslatedYaw = 0;
  static int Last31 = 0;
  
  // Adjust for the operating system, driver, and joystick hardware.
  ScaledRoll = *Roll * RollFactor + RollOffset;
  ScaledPitch = *Pitch * PitchFactor + PitchOffset;
  ScaledYaw = *Yaw * YawFactor + YawOffset;
  
  // Report to yaAGC.
  New31 = 077777;
  if (ScaledRoll <= -DETENT)
    New31 &= ~040040;
  else if (ScaledRoll >= DETENT)
    New31 &= ~040020;
  if (ScaledYaw <= -DETENT)
    New31 &= ~040010;
  else if (ScaledYaw >= DETENT)
    New31 &= ~040004;
  if (ScaledPitch <= -DETENT)
    New31 &= ~040002;
  else if (ScaledPitch >= DETENT)
    New31 &= ~040001;
  if (ServerSocket != -1 && (New31 != Last31 || First))
    {
      unsigned char Packet[8];
      Last31 = New31;
      // First, create the mask which will tell the CPU to only pay attention to
      // relevant bits of channel (031).
      FormIoPacket (0431, 040077, Packet);
      FormIoPacket (031, New31, &Packet[4]);
      // And, send it all.
      j = send (ServerSocket, Packet, 8, MSG_NOSIGNAL);
      if (j == SOCKET_ERROR && SOCKET_BROKEN)
        {
	  close (ServerSocket);
	  ServerSocket = -1;
          fprintf (Out, "\nServer connection lost.\n");
	  return;
	}
    }
  if (ScaledRoll != LastRoll || First)
    {
      TranslatedRoll = OutputTranslated (0170, ScaledRoll);
      Changed = 1;
    }
  if (ScaledPitch != LastPitch || First)
    {
      TranslatedPitch = OutputTranslated (0166, ScaledPitch);
      Changed = 1;
    }
  if (ScaledYaw != LastYaw || First)
    {
      TranslatedYaw = OutputTranslated (0167, ScaledYaw);
      Changed = 1;
    }
  // Local display.
  if (Changed)
    {
      fprintf (Out, "\rRoll=%+04d (%+03d)   Pitch=%+04d (%+03d)   Yaw=%+04d (%+03d)", 
      	      ScaledRoll, TranslatedRoll,
	      ScaledPitch, TranslatedPitch,
	      ScaledYaw, TranslatedYaw);
      fflush (Out);
      LastRoll = ScaledRoll;
      LastPitch = ScaledPitch;
      LastYaw = ScaledYaw;
      First = 0;
    }
}