Skip to content. | Skip to navigation

Personal tools

display.cpp

display.cpp

display.cpp

/////////////////////////////////////////////////////////////////////////////
// DISPLAY.CPP
//
//  Last updated: 5/13/2004
//
//  Part of the source code for the Vane End Actuator Control System
//
//  Contains routines for updating the on-screen display
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////
// CmdLine - display a string on the command line
void CmdLine(char *data)
// Displays the string in data on the command line.
{
	char *temp;

	if (strlen(data) > 19)
		temp = &data[strlen(data) - 19];
	else
		temp = data;
	PutString16(temp,28,192,456,BLACK,SHECMEDGRAY);
}

/////////////////////////////////////////////////////////////////////////////
// UpdateCursor - Make the cursor blink when it's supposed to.
void UpdateCursor(char *data)
// Maintains a blinking cursor on the command line.
{
	char *temp;

	if (strlen(data) > 19)
		temp = &data[strlen(data) - 19];
	else
		temp = data;
	// Make the cursor blink every CursorBlinkRate milliseconds
	if ((Timer - CursorTimer) > CursorBlinkRate)
	{
		if (strlen(data) > 19)
			temp = &data[strlen(data) - 19];
		if (Cursor)
		{
			PutChar16('_',strlen(temp)*8+28,456,BLACK,SHECMEDGRAY);
			Cursor = 0;
		}
		else
		{
			PutChar16(' ',strlen(temp)*8+28,456,BLACK,SHECMEDGRAY);
			Cursor = 1;
		}
		CursorTimer = Timer;
	}
}

/////////////////////////////////////////////////////////////////////////////
// UpdateTime - Update the onscreen UT and ET times
void UpdateTime(int UpdateAll)
// Pass a 1 in UpdateAll to display every digit,
// otherwise UpdateTime will only display digits that have changed
{
	int i;
	char s[255];

	// Calculate elapsed time since program began
	et = Timer + HighTimer * maxdword;
	// Convert ms to days.
	et = et / 86400000.0;

	// Calculate average and max cycle rates
	CycleHistory[CycleIndex] = Timer - MainLoopTimer;
	CycleIndex++;
	if (CycleIndex >= CycleHistorySize) CycleIndex = 0;
	MainLoopTimer = Timer;
	// Output the longest recent cycle time
	CycleMax = 0;
	CycleAv = 0;
	for (i=0;i<CycleHistorySize;i++)
	{
		if (CycleHistory[i] > CycleMax)
			CycleMax = CycleHistory[i];
		CycleAv += CycleHistory[i];
	}
	CycleAv /= CycleHistorySize;

	if (UpdateAll)
	{
		// Display elapsed time
		sprintf(s,"%6.2lfd",et);
		PutString16(s,452,508,lby+8,BLACK,SHECMEDGRAY);
		oldet = et;
		// Display current UT
		gettime(&t);
		sprintf(s,"%02d",t.hour);
		PutString16(s,564,580,lby+8,BLACK,SHECMEDGRAY);
		sprintf(s,"%02d",t.minute);
		PutString16(s,588,604,lby+8,BLACK,SHECMEDGRAY);
		sprintf(s,"%02d",t.second);
		PutString16(s,612,628,lby+8,BLACK,SHECMEDGRAY);
		oldt = t;
		// Display cycle rate average and max
		sprintf(s,"%4d",CycleAv);
		PutString16(s,68,100,lby+8,BLACK,SHECMEDGRAY);
		OldCycleAv = CycleAv;
		sprintf(s,"%4d",CycleMax);
		PutString16(s,132,164,lby+8,BLACK,SHECMEDGRAY);
		OldCycleMax = CycleMax;
	}
	else
	{
		// Display elapsed time
		if (et - oldet > 0.01)
		{
			sprintf(s,"%6.2lfd",et);
			PutString16(s,452,508,lby+8,BLACK,SHECMEDGRAY);
			oldet = et;
		}

		// Display current UT
		gettime(&t);
		if (t.hour != oldt.hour)
		{
			sprintf(s,"%02d",t.hour);
			PutString16(s,564,580,lby+8,BLACK,SHECMEDGRAY);
		}
		if (t.minute != oldt.minute)
		{
			sprintf(s,"%02d",t.minute);
			PutString16(s,588,604,lby+8,BLACK,SHECMEDGRAY);
		}
		if (t.second != oldt.second)
		{
			sprintf(s,"%02d",t.second);
			PutString16(s,612,628,lby+8,BLACK,SHECMEDGRAY);
		}
		oldt = t;

		// Display cycle av and max
		if (CycleAv != OldCycleAv)
		{
			sprintf(s,"%4d",CycleAv);
			PutString16(s,68,100,lby+8,BLACK,SHECMEDGRAY);
			OldCycleAv = CycleAv;
		}
		if (CycleMax != OldCycleMax)
		{
			sprintf(s,"%4d",CycleMax);
			PutString16(s,132,164,lby+8,BLACK,SHECMEDGRAY);
			OldCycleMax = CycleMax;
		}

	}
}

/////////////////////////////////////////////////////////////////////////////
// InitDisplay - Draw the intial screen (all windows, static text, etc.
void InitDisplay()
{
	int i;
  char s[255];

	// Initialize cycle rate variables
	MainLoopTimer = Timer;
	for (i=0;i < CycleHistorySize;i++)
		CycleHistory[i] = 0;
	OldCycleAv = 9999;
	OldCycleMax = 9999;

	// This routine draws all static screen items.
	int x,y;

	// All of the big shadowed boxes
	// Vane end box
	ShadowBox(0,0,639,vbby,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	// Instrument rotator box
	ShadowBox(0,ibty,519,ibby,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	// Flags box
	ShadowBox(520,fbty,639,fbby,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	// Cass-M3 box
	ShadowBox(520,cbty,639,cbby,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	// Air/Vacuum M2 Mirror Support box
	ShadowBox(0,sbty,519,sbby,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	// Input box
	ShadowBox(0,lby,199,479,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	PutString16("Input  9999 av 9999 mx",12,189,lby+8,BLACK,SHECMEDGRAY);
	PutString16("* ",12,28,456,BLACK,SHECMEDGRAY);
	// System log box
	ShadowBox(200,lby,639,479,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	PutString16("System Messages 999-999   ET: 999.99d   UT: 99 99 99",212,630,lby+8,BLACK,SHECMEDGRAY);

	// Vane end encoders and tensions
	x = 12;
	y = 8;
	PutString16("      Req    Val  M L  Ten  E         Req    Val  M L  Ten  E      Req   Val",x,x+622,y,BLACK,SHECMEDGRAY);
	HLine(x+4*8,x+29*8-1,y+15,BLACK);
	HLine(x+36*8,x+61*8-1,y+15,BLACK);
	HLine(x+66*8,x+77*8-1,y+15,BLACK);
	PutString16("A:a 999999 999999 * * 99999 *   A:d 999999 999999 * * 99999 *   X:99999 99999",x,x+622,y+18,BLACK,SHECMEDGRAY);
	PutString16("R:e 999999 999999 * * 99999 *   R:h 999999 999999 * * 99999 *   Y:99999 99999",x,x+622,y+34,BLACK,SHECMEDGRAY);
	PutString16("      æm     æm        Lbs            æm     æm        Lbs      Z:99999 99999",x,x+622,y+50,BLACK,SHECMEDGRAY);
	PutString16("A:b 999999 999999 * * 99999 *   A:c 999999 999999 * * 99999 *   H:99999 99999",x,x+622,y+66,BLACK,SHECMEDGRAY);
	PutString16("R:f 999999 999999 * * 99999 *   R:g 999999 999999 * * 99999 *   V:99999 99999",x,x+622,y+82,BLACK,SHECMEDGRAY);
	PutString16("NW1",x,x+24,y+4,SHECWHITE,SHECMEDGRAY);
	PutString16("NE4",x+32*8,x+32*8+24,y+4,SHECWHITE,SHECMEDGRAY);
	PutString16("SW2",x,x+24,y+52,SHECWHITE,SHECMEDGRAY);
	PutString16("SE3",x+32*8,x+32*8+24,y+52,SHECWHITE,SHECMEDGRAY);

	// Status box (Labels for the LEDs)
	x = 520+12;
	y = fbty+8;
	PutString16("Fatal  Flags",x,x+96,y,BLACK,SHECMEDGRAY);
	HLine(x,x+95,y+15,BLACK);
	y = y + 18;
	PutString16("  INI  Error",x,x+96,y,BLACK,SHECMEDGRAY);
	PutString16("  Home Error",x,x+96,y+16,BLACK,SHECMEDGRAY);
	PutString16("  Motor Temp",x,x+96,y+32,BLACK,SHECMEDGRAY);
	PutString16("  Emerg Stop",x,x+96,y+48,BLACK,SHECMEDGRAY);
	PutString16("  Motion Err",x,x+96,y+64,BLACK,SHECMEDGRAY);
	PutString16("  Check  Err",x,x+96,y+80,BLACK,SHECMEDGRAY);
	PutString16("  Posn  Comm",x,x+96,y+96,BLACK,SHECMEDGRAY);
	PutString16("  Tnsn  Comm",x,x+96,y+112,BLACK,SHECMEDGRAY);
	PutString16("  Posn Limit",x,x+96,y+128,BLACK,SHECMEDGRAY);
	PutString16("  Tnsn Limit",x,x+96,y+144,BLACK,SHECMEDGRAY);

	// Instrument rotators
	x = 12;
	y = ibty+8;
	PutString16("  IR      Req      Val     Vel  Volt E M L B P H Z   Encoder",x,x+62*8,y,BLACK,SHECMEDGRAY);
	HLine(x+7*8,x+62*8,y+15,BLACK);
	y = y+18;
	PutString16("0 NASW +000.000 +000.000 +0.000 +9.9 * * * * * * * +0000000000",x,x+62*8,y,BLACK,SHECMEDGRAY);
	PutString16("1 NASE +000.000 +000.000 +0.000 +9.9 * * * * * * * +0000000000",x,x+62*8,y+16,BLACK,SHECMEDGRAY);
	PutString16("2 CASS +000.000 +000.000 +0.000 +9.9 * * * * * * * +0000000000",x,x+62*8,y+32,BLACK,SHECMEDGRAY);
	PutString16("3 AUX1 +000.000 +000.000 +0.000 +9.9 * * * * * * * +0000000000",x,x+62*8,y+48,BLACK,SHECMEDGRAY);
	PutString16("4 AUX2 +000.000 +000.000 +0.000 +9.9 * * * * * * * +0000000000",x,x+62*8,y+64,BLACK,SHECMEDGRAY);
	PutString16("5 AUX3 +000.000 +000.000 +0.000 +9.9 * * * * * * * +0000000000",x,x+62*8,y+80,BLACK,SHECMEDGRAY);
	PutString16(" Error                 Vel                 Volts",x,x+62*8,y+96,BLACK,SHECMEDGRAY);
	PutString16(" ñ1000               ñ1.000                ñ10.0",x,x+62*8,y+112,BLACK,SHECMEDGRAY);

  // M2 Support System
	if (f11Present && !f5Present) {
		PutString16("Pressure/Vacuum Control",x,x+23*8,sbty+8,BLACK,SHECMEDGRAY);
		HLine(x,x+23*8,sbty+8+14,BLACK);
		PutString16("Mode: IDLE",x+24*8,x+24*8+10*8,sbty+8,BLACK,SHECMEDGRAY);
		PutString16("Pulse:Presþ xxxxms",x,x+18*8,sbty+8+16,BLACK,SHECMEDGRAY);
		PutString16("       Vacþ xxxxms",x,x+18*8,sbty+8+32,BLACK,SHECMEDGRAY);
		PutString16("M2w: xxx.xxxLbs",x,x+15*8,sbty+8+48,BLACK,SHECMEDGRAY);
		PutString16("i: +x.xxx",x+19*8,x+19*8+9*8,sbty+8+16,BLACK,SHECMEDGRAY);
		PutString16("j: +x.xxx",x+19*8,x+19*8+9*8,sbty+8+32,BLACK,SHECMEDGRAY);
		PutString16("k: +x.xxx",x+19*8,x+19*8+9*8,sbty+8+48,BLACK,SHECMEDGRAY);
	  // Graph with averages
		PutString16("  mV  ",x+29*8,x+29*8+6*8,sbty+12+16,BLACK,SHECMEDGRAY);
		PutString16("ñx.xxx",x+29*8,x+29*8+6*8,sbty+12+32,BLACK,SHECMEDGRAY);
		PutString16("P: xxx.xxx",x+50*8,x+50*8+10*8,sbty+8+16,BLACK,SHECMEDGRAY);
		PutString16("I: xxx.xxx",x+50*8,x+50*8+10*8,sbty+8+32,BLACK,SHECMEDGRAY);
		PutString16("D: xxx.xxx",x+50*8,x+50*8+10*8,sbty+8+48,BLACK,SHECMEDGRAY);
	}

  if (Telescope == 2)
  {
    x = 520+12;
    y = cbty+8;
    PutString16("M3 Position",x,x+88,y,BLACK,SHECMEDGRAY);
    HLine(x,x+87,y+15,BLACK);
  }

	// Display all fatal flag LEDs
	Flags.DisplayAll();

	// Display full current timers
	UpdateTime(1);

	// Display Logs
	Log.Display();
	InputLog.Display();

  // Display instrument rotators
  for (i=0;i<=5;i++)
  	IRs[i].DisplayAll();

	// Pressure/Vacuum parameters and mode
  if (f11Present && !f5Present) PresVac[0].Display();

  // Display instrument rotator, Pres/Vac charts
  IRErr2Chart.Display();
  IRErrChart.Display();
  IRVel2Chart.Display();
  IRVelChart.Display();
  IRVoltChart.Display();
	DisplayScales();

	if (f11Present && !f5Present) {
		PresVacCharts[0].Display();
	}
	else if (f5Present) {
		PresVacCharts[1].Display();
		PresVacCharts[2].Display();
		PresVacCharts[3].Display();
		PresVacCharts[4].Display();
	}

	// Display an already entered command if necessary
	CmdLine(kbline);
}

/////////////////////////////////////////////////////////////////////////////
// DisplayHelp - Display a list of all keyboard commands
void DisplayHelp()
// Displays an abbreviated list of local keyboard commands
{
	int i;

	ShadowBox(0,0,639,479,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	// display help lines
	for (i = 0;i<NumHelpLines;i++)
		PutString16(HelpText[i],12,632,i*16+8,BLACK,SHECMEDGRAY);
}

/////////////////////////////////////////////////////////////////////////////
// DisplayScales - Display IRs + DGH_Average chart scales
void DisplayScales()
// Display instrument rotator chart scales and DGH average chart scale
{
	char s[50];

  sprintf(s,"ñ%5.3f",IRErrChart.GetScale());
  PutString16(s,12+0*8,12+6*8,ibty+26+7*16,BLACK,SHECMEDGRAY);
  sprintf(s,"ñ%5.3f",IRVelChart.GetScale());
  PutString16(s,12+21*8,12+27*8,ibty+26+7*16,BLACK,SHECMEDGRAY);
  sprintf(s,"ñ%5.1f",IRVoltChart.GetScale());
  PutString16(s,12+42*8,12+48*8,ibty+26+7*16,BLACK,SHECMEDGRAY);

	if (f11Present && !f5Present) {
		sprintf(s,"ñ%5.3f",PresVacCharts[0].GetScale());
		PutString16(s,244,292,sbty+12+32,BLACK,SHECMEDGRAY);
	}
}

/////////////////////////////////////////////////////////////////////////////
// ScreenDump - Copy the screen image to a BMP file
void ScreenDump()
// Copies the screen to the Windows BMP file SCREEN.BMP
{
	struct BITMAPFILEHEADER
	{
		word bfType;
		dword bfSize;
		word bfReserved1;
		word bfReserved2;
		dword bfOffBits;
	} FileHeader;

	struct BITMAPINFOHEADER
	{
		dword biSize;
		dword biWidth;
		dword biHeight;
		word biPlanes;
		word biBitCount;
		dword biCompression;
		dword biSizeImage;
		dword biXPelsPerMeter;
		dword biYPelsPerMeter;
		dword biClrUsed;
		dword biClrImportant;
	} InfoHeader;

	struct RGBQUAD
	{
		byte rgbBlue;
		byte rgbGreen;
		byte rgbRed;
		byte rgbReserved;
	} RGB;

	FILE *fout;
	dword OffBits;
	dword Size;
	int x,y;
	byte temp;
	union REGS regs;

	FileHeader.bfType = 0x4D42;
	FileHeader.bfSize = 0;
	FileHeader.bfReserved1 = 0;
	FileHeader.bfReserved2 = 0;
	FileHeader.bfOffBits = 0;

	InfoHeader.biSize = sizeof(BITMAPINFOHEADER);
	InfoHeader.biWidth = 640;
	InfoHeader.biHeight = 480;
	InfoHeader.biPlanes = 1;
	InfoHeader.biBitCount = 8;
	InfoHeader.biCompression = 0;
	InfoHeader.biSizeImage = 640*480;
	InfoHeader.biXPelsPerMeter = 0;
	InfoHeader.biYPelsPerMeter = 0;
	InfoHeader.biClrUsed = 0;
	InfoHeader.biClrImportant = 0;

	fout = fopen("SCREEN.BMP","wb");
	fwrite(&FileHeader,sizeof(BITMAPFILEHEADER),1,fout);
	fwrite(&InfoHeader,sizeof(BITMAPINFOHEADER),1,fout);
	RGB.rgbReserved = 0;
	// Write palette
	for (y = 0;y <= 255;y++)
	{
		Watchdog();
		// Read a VGA DAC
		regs.w.ax = 0x1015;
		regs.w.bx = y;
		int386(0x10,&regs,&regs);
		RGB.rgbRed = (regs.w.dx >> 6) & 0xFF;
		RGB.rgbGreen = (regs.w.cx >> 6) & 0xFF;
		RGB.rgbBlue = (regs.w.cx << 2) & 0xFF;
		fwrite(&RGB,sizeof(RGBQUAD),1,fout);
	}
	// Write pixels
	OffBits = ftell(fout);
	for (y = 479;y >= 0;y--)
	{
		Watchdog();
		for (x=0;x<=639;x++)
		{
			temp = GetPixel(x,y);
			fwrite(&temp,1,1,fout);
		}
	}
	Size = ftell(fout);
	FileHeader.bfSize = Size;
	FileHeader.bfOffBits = OffBits;
	fseek(fout,0,SEEK_SET);
	fwrite(&FileHeader,sizeof(BITMAPFILEHEADER),1,fout);
	fclose(fout);
}

Generated by GNU Enscript 1.6.5.2.
Document Actions