Skip to content. | Skip to navigation

Personal tools

remote/display.cpp

remote/display.cpp

remote/display.cpp

/////////////////////////////////////////////////////////////////////////////
// DISPLAY.CPP
//
//  Last updated: 1/30/2005
//
//  Part of the source code for the remote M3 Program
//
//  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) > MaxCmdLine)
		temp = &data[strlen(data) - MaxCmdLine];
	else
		temp = data;
	PutString16(temp,468,632,452,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) > MaxCmdLine)
		temp = &data[strlen(data) - MaxCmdLine];
	else
		temp = data;
	// Make the cursor blink every CursorBlinkRate milliseconds
	if ((msTimer - CursorTimer) > CursorBlinkRate)
	{
		if (strlen(data) > MaxCmdLine)
			temp = &data[strlen(data) - MaxCmdLine];
		if (Cursor)
		{
			PutChar16('_',strlen(temp)*8+468,452,BLACK,SHECMEDGRAY);
			Cursor = 0;
		}
		else
		{
			PutChar16(' ',strlen(temp)*8+468,452,BLACK,SHECMEDGRAY);
			Cursor = 1;
		}
		CursorTimer = msTimer;
	}
}

/////////////////////////////////////////////////////////////////////////////
// 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 = msTimer + HighmsTimer * maxdword;
	// Convert ms to days.
	et = et / 86400000.0;

	// Calculate average and max cycle rates
	CycleHistory[CycleIndex] = msTimer - MainLoopTimer;
	CycleIndex++;
	if (CycleIndex >= CycleHistorySize) CycleIndex = 0;
	MainLoopTimer = msTimer;
	// 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,252,308,364,BLACK,SHECMEDGRAY);
		oldet = et;
		// Display current local time
		gettime(&t);
		sprintf(s,"%02d",t.hour);
		PutString16(s,364,380,364,BLACK,SHECMEDGRAY);
		sprintf(s,"%02d",t.minute);
		PutString16(s,388,404,364,BLACK,SHECMEDGRAY);
		sprintf(s,"%02d",t.second);
		PutString16(s,412,428,364,BLACK,SHECMEDGRAY);
		oldt = t;
		// Display cycle rate average and max
		sprintf(s,"%4d",CycleAv);
		PutString16(s,508,540,364,BLACK,SHECMEDGRAY);
		OldCycleAv = CycleAv;
		sprintf(s,"%4d",CycleMax);
		PutString16(s,572,604,364,BLACK,SHECMEDGRAY);
		OldCycleMax = CycleMax;
	}
	else
	{
		// Display elapsed time
		if (et - oldet > 0.01)
		{
			sprintf(s,"%6.2lfd",et);
			PutString16(s,252,308,364,BLACK,SHECMEDGRAY);
			oldet = et;
		}

		// Display current local time
		gettime(&t);
		if (t.hour != oldt.hour)
		{
			sprintf(s,"%02d",t.hour);
			PutString16(s,364,380,364,BLACK,SHECMEDGRAY);
		}
		if (t.minute != oldt.minute)
		{
			sprintf(s,"%02d",t.minute);
			PutString16(s,388,404,364,BLACK,SHECMEDGRAY);
		}
		if (t.second != oldt.second)
		{
			sprintf(s,"%02d",t.second);
			PutString16(s,412,428,364,BLACK,SHECMEDGRAY);
		}
		oldt = t;

		// Display cycle av and max
		if (CycleAv != OldCycleAv)
		{
			sprintf(s,"%4d",CycleAv);
			PutString16(s,508,540,364,BLACK,SHECMEDGRAY);
			OldCycleAv = CycleAv;
		}
		if (CycleMax != OldCycleMax)
		{
			sprintf(s,"%4d",CycleMax);
			PutString16(s,572,604,364,BLACK,SHECMEDGRAY);
			OldCycleMax = CycleMax;
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// InitDisplay - Draw the intial screen (all windows, static text, etc.
void InitDisplay()
{
	int i,x,y,r1,r2,xoff,yoff;

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

	// This routine draws all static screen items.

	// All of the big shadowed boxes

	// M3 Box
	ShadowBox(0,0,359,351,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);

	// Tilt Display
	x = TiltX;
	y = TiltY;
	PutString16("Tilt",x-65,x-65+32,10,BLACK,SHECMEDGRAY);
	Ellipse(x,y,45,60,BLACK);
	PutChar16('A',x-3,y-18,BLACK,SHECMEDGRAY);
	Box(x-5,y-42,x+5,y-22,SHECDARKGRAY);
	PutChar16('B',x-12,y+17,BLACK,SHECMEDGRAY);
	Box(x-26,y+15,x-16,y+35,SHECDARKGRAY);
	PutChar16('C',x+5,y+17,BLACK,SHECMEDGRAY);
	Box(x+16,y+15,x+26,y+35,SHECDARKGRAY);

	// Main Display
	PutString16("Device          Mtn            Position",12,349,148,BLACK,SHECMEDGRAY);
	HLine(12,349,165,BLACK);
	y = 168;
	//PutString16("Tilt A               ???????V  xxx.xxxmm",12,349,y+128,BLACK,SHECMEDGRAY);
	//PutString16("Tilt B               ???????V  xxx.xxxmm",12,349,y+144,BLACK,SHECMEDGRAY);
	//PutString16("Tilt C               ???????V  xxx.xxxmm",12,349,y+160,BLACK,SHECMEDGRAY);
	PutString16("Tilt A                         ???????V",12,349,y,BLACK,SHECMEDGRAY);
	PutString16("Tilt B                         ???????V",12,349,y+16,BLACK,SHECMEDGRAY);
	PutString16("Tilt C                         ???????V",12,349,y+32,BLACK,SHECMEDGRAY);
	PutString16("12VDC Monitor                  ???????V",12,349,y+48,BLACK,SHECMEDGRAY);

	// Stepper box
	ShadowBox(360,0,639,351,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	PutString16("Stepper    Dir Stp Mon Pwr Cur",372,629,12,BLACK,SHECMEDGRAY);
	HLine(372,629,29,BLACK);
	PutString16("Tilt A      þ   þ   þ   þ   þ ",372,629,32,BLACK,SHECMEDGRAY);
	PutString16("Tilt B      þ   þ   þ   þ   þ ",372,629,48,BLACK,SHECMEDGRAY);
	PutString16("Tilt C      þ   þ   þ   þ   þ ",372,629,64,BLACK,SHECMEDGRAY);
	PutString16("Mirror Support",372,629,148,BLACK,SHECMEDGRAY);
	HLine(372,629,165,BLACK);
	PutString16("A-C Load:   xxx.xxxV",372,629,168,BLACK,SHECMEDGRAY);
	PutString16("A-B Load:   xxx.xxxV",372,629,184,BLACK,SHECMEDGRAY);
	PutString16("B-C Load:   xxx.xxxV",372,629,200,BLACK,SHECMEDGRAY);
	PutString16("Tilt Brakes þ",372,629,216,BLACK,SHECMEDGRAY);
	PutString16("M3w: xxx.xxxLbs",492,612,216,BLACK,SHECMEDGRAY);
	PutString16("Pressure/Vacuum Control",372,629,236,BLACK,SHECMEDGRAY);
	HLine(372,629,253,BLACK);
	PutString16("ñ0.3",372,412,276,BLACK,SHECMEDGRAY);
	PutString16("P:xxx.xxx",556,629,264,BLACK,SHECMEDGRAY);
	PutString16("I:xxx.xxx",556,629,280,BLACK,SHECMEDGRAY);
	PutString16("D:xxx.xxx",556,629,296,BLACK,SHECMEDGRAY);
	PutString16("Mode: OFF",556,629,312,BLACK,SHECMEDGRAY);
	PutString16("pulse: Pres þ xxxx ms",372,555,312,BLACK,SHECMEDGRAY);
	PutString16("        Vac þ xxxx ms",372,555,328,BLACK,SHECMEDGRAY);

	// System log box
	ShadowBox(0,352,439,479,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	PutString16("System Messages 999-999   ET: 999.99d   LT: 99 99 99",12,430,364,BLACK,SHECMEDGRAY);

	PutString16("  LCU Communication Status",20,228,324,BLACK,SHECMEDGRAY);

	// Input box
	ShadowBox(440,352,639,479,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	PutString16("Input  9999 av 9999 mx",452,629,364,BLACK,SHECMEDGRAY);
	PutString16("* ",452,468,452,BLACK,SHECMEDGRAY);

	// Display full current timers
	UpdateTime(1);

	// Display Logs
	Log->DisplayAll();
	InputLog->DisplayAll();

	// Display subsystems
	// Tilts
	Tilt.DisplayAll();
	// Pressure/Vacuum chart and mode
	PresVacChart.Display();
	PresVac.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(50,34,589,383,SHECLIGHTGRAY,SHECDARKGRAY,SHECMEDGRAY);
	// display help lines
	for (i = 0;i<NumHelpLines;i++)
		PutString16(HelpText[i],62,578,34+i*16+8,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++)
	{
		// 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--)
	{
		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