Beispiel #1
0
void displaySettings() {
	char mode_buf[32];
	snprintf(mode_buf, sizeof(mode_buf), "%s", "settings");

	/* TODO : Settings display
	 * We display all settings lines, highlighting the active row 
	 * Static display of settings, bitmapLine under active row
	 * 0,0  mode buffer
	 * 0,12 tcr buffer
	 * 0,24 flip buffer
	 * 0,36 
	 * Line at 0,(currentSetting * 13)
	 * */
	char item1[32];
	char item2[32];
	char item3[32];
	char item4[32];

	double tcr = ctx.settings.tcrValue * 100000;
	int cleanTCR = (int)tcr;
	snprintf(item1, sizeof(item1), "%s: %d", "TCR", cleanTCR);
	snprintf(item2, sizeof(item2), "%d", ctx.atomizer.resistance);

	int pos = ctx.settings.setPos * 12 + 10;

	Display_Clear();
	Display_PutText(0, 0, mode_buf, FONT_DEJAVU_8PT);
	Display_PutText(0, 12, item1, FONT_DEJAVU_8PT);
	Display_PutText(0, 24, item2, FONT_DEJAVU_8PT);
	Display_PutPixels(0, pos, bitmapLine, bitmapLineWidth, bitmapLineHeight);
	Display_Update();
}
Beispiel #2
0
task main()
{
	Task_Kill(displayDiagnostics);
	Display_Clear();
	initializeGlobalVariables(); // Defined in "initialize.h", this intializes all struct members.

	const int finish_delay = 4*1000; // MAGIC_NUM: milliseconds to delay when program ends. // TODO: Figure out why the delay is nowhere near this.
	TFileHandle IO_handle;
	TFileIOResult IO_result;
	const string filename = "_reset_pods.txt";
	const string filename_temp = "_reset_pods_tmp.txt"; // temp makes the filename too long??
	int file_size = 0;
	short rotation[POD_NUM] = {0,0,0,0};


	// Read in all the values of the pods from a text file.
	OpenRead(IO_handle, IO_result, filename, file_size); // TODO: Add more error handling.
	if (IO_result==ioRsltSuccess) {
		nxtDisplayTextLine(0, "Read from file");
		nxtDisplayTextLine(1, "\"_reset_pods.txt\"");
	} else if (IO_result==ioRsltFileNotFound) {
		OpenRead(IO_handle, IO_result, filename_temp, file_size); // TODO: Add more error handling.
		if (IO_result==ioRsltSuccess) {
			nxtDisplayTextLine(0, "Read from file");
			nxtDisplayTextLine(1, "\"_pods_tmp.txt\"");
		} else if (	(IO_result==ioRsltFileNotFound)	||
					(IO_result==ioRsltNoSpace)		||
					(IO_result==ioRsltNoMoreFiles)	) {
			nxtDisplayTextLine(2, "No data file.");
			nxtDisplayTextLine(3, "Terminating.");
			Time_Wait(finish_delay);
			return; // The only way to break out of this function?
		}
	} else if ((IO_result==ioRsltNoSpace)||(IO_result==ioRsltNoMoreFiles)) {
		nxtDisplayTextLine(2, "No data file.");
		nxtDisplayTextLine(3, "Terminating.");
		Time_Wait(finish_delay);
		return; // The only way to break out of this function?
	}
	for (int i=POD_FR; i<(int)POD_NUM; i++) {
		ReadShort(IO_handle, IO_result, rotation[i]);
	}
	Close(IO_handle, IO_result);

	nxtDisplayTextLine(3, "FL:%5d FR:%5d", rotation[POD_FL], rotation[POD_FR]);
	nxtDisplayTextLine(4, "BL:%5d BR:%5d", rotation[POD_BL], rotation[POD_BR]);

	nxtDisplayCenteredTextLine(6, "Press [ENTER] to");
	nxtDisplayCenteredTextLine(7, "end program.");
	do {
		Buttons_UpdateData();
		Time_Wait(100); // MAGIC_NUM: Arbitrary LCD refresh delay.
	} while (Buttons_Released(NXT_BUTTON_YES)==false);
}
Beispiel #3
0
void displayVW() {
	char mode_buf[3];
	char out_buf[5];
	char bat_buf[5];
	
	snprintf(mode_buf, sizeof(mode_buf), "%s", "vw");
	snprintf(out_buf, sizeof(out_buf), "%dw", ctx.settings.tW/1000);
	snprintf(bat_buf, sizeof(bat_buf), "%d%%", ctx.battery.percent);
	
	Display_Clear();
	Display_PutPixels(4, 2, bitmapBottle, bitmapBottleWidth, bitmapBottleHeight);
	Display_PutText(24, 0, mode_buf, FONT_DEJAVU_8PT);
	Display_PutPixels(0, 112, bitmapLine, bitmapLineWidth, bitmapLineHeight);
	Display_PutText(0, 116, out_buf, FONT_DEJAVU_8PT);
	Display_PutText(32, 116, bat_buf, FONT_DEJAVU_8PT);
	Display_Update();
}
Beispiel #4
0
void Display_Init() {
	switch(Dataflash_info.hwVersion) {
		case 102:
		case 103:
		case 106:
		case 108:
		case 109:
		case 111:
			Display_type = DISPLAY_SSD1327;
			break;
		default:
			Display_type = DISPLAY_SSD1306;
			break;
	}
	Display_Clear();
	Display_SSD_Init();
}
Beispiel #5
0
int main() {
	uint8_t state;
	char buf[100];

	while(1) {
		// Build state report
		state = Button_GetState();
		sprintf(buf, "Mask: %02X\n\nFire: %d\nRight: %d\nLeft: %d",
			state,
			(state & BUTTON_MASK_FIRE) ? 1 : 0,
			(state & BUTTON_MASK_RIGHT) ? 1 : 0,
			(state & BUTTON_MASK_LEFT) ? 1 : 0);

		// Clear and blit text
		Display_Clear();
		Display_PutText(0, 0, buf, FONT_DEJAVU_8PT);
		Display_Update();
	}
}
Beispiel #6
0
void displayFiring() {
	char temp_buf[12];
	char out_buf[5];
	snprintf(temp_buf, sizeof(temp_buf), "%dc", (int)ctx.coil.temp);
	snprintf(out_buf, sizeof(out_buf), "%dw",
			(ctx.atomizer.voltage * ctx.atomizer.current) / 1000000);

	Display_Clear();

	int lines;
	lines = numLines();
	for(int i = 0; i < lines; i += 2) {
		Display_PutPixels(0, i, bitmapLine, bitmapLineWidth, bitmapLineHeight);
	}

	Display_PutPixels(0, 112, bitmapLine, bitmapLineWidth, bitmapLineHeight);
	Display_PutText(0, 116, temp_buf, FONT_DEJAVU_8PT);
	Display_PutText(32, 116, out_buf, FONT_DEJAVU_8PT);
	Display_Update();
}
Beispiel #7
0
// Main
int main() {
	// initial settings, will change to user interactive / eeprom
	ctx.settings.mode = 3;
	ctx.settings.maxCtrlWatts = 75000;
	ctx.settings.maxWatts = 75000;
	ctx.settings.minTemp = 60;
	ctx.settings.maxTemp = 300;
	ctx.settings.tcrValue = 0.00092;

	ctx.settings.tT = 248;
	ctx.settings.tW = 56000;

	ctx.settings.lockRes = false;
	ctx.settings.flip = false;
	ctx.settings.stealth = false;
	ctx.settings.lock = false;
	ctx.settings.timeout = 10;

	// init timers
	uint8_t timeTimer;
	timeTimer = Timer_CreateTimer(1, 1, incrementTime, 1);
	uint8_t loopTimer;
	loopTimer = Timer_CreateTimer(FPS, 1, readyLoop, 1);

	// init atomizer
	Atomizer_SetErrorLock(true);

	// main loop, rest is event handling
	while(1) {
		loop = 0;
		// collect runtime data
		collectData();

		// do controls
		doControls();

		if(ctx.state.firing) {
			displayFiring();
		} else {
			if(ctx.state.idleTimer < 20) {
				switch(ctx.settings.mode) {
					case 0: // settings
						displaySettings();
						break;
					case 1: // vw
						displayVW();
						break;
					case 2: // bp
						displayBP();
						break;
					case 3: // tc
						displayTC();
						break;
				}
			} else {
				// switch to low power mode
				Display_Clear();
				Display_Update();
				sleep();
			}
		}

		// waste time until loop refresh timer is ready
		while(loop == 0) {}
	}

	return 0;
}
Beispiel #8
0
task Display()
{
	typedef enum DisplayMode {
		DISP_FCS,			// Default FCS screen.
		DISP_ENCODERS,		// Raw encoder values.
		DISP_LIFT,			// PID, status, mode
		DISP_HOPPER,		// Maths variables.
		DISP_SENSORS,		// Might need to split this into two screens.
		DISP_JOYSTICKS,		// For convenience. TODO: Add buttons, D-pad, etc.?
		DISP_NUM
	};

	Task_Spawn(displayDiagnostics); // Explicit here: this is only spawned when buttons are pressed.
	DisplayMode isMode = DISP_FCS;

	// We don't need to wait for start. ;)

	while (true) {
		Buttons_UpdateData();

		switch (isMode) {
			case DISP_FCS :
				break;
			case DISP_ENCODERS :
				nxtDisplayTextLine(0, "Lift :  %+6i", lift_pos);
				nxtDisplayTextLine(1, "Mtr L:  %+6i", Motor_GetEncoder(encoder_L));
				nxtDisplayTextLine(2, "Mtr R:  %+6i", Motor_GetEncoder(encoder_R));
				break;
			case DISP_SENSORS :
				nxtDisplayTextLine(0, "Angle: %3i", heading);
				nxtDisplayTextLine(1, "IR A : %3i", IR_A);
				nxtDisplayTextLine(2, "IR B : %3i", IR_B);
				nxtDisplayTextLine(3, "IR C : %3i", IR_C);
				nxtDisplayTextLine(4, "IR D : %3i", IR_D);
				nxtDisplayTextLine(5, "IR E : %3i", IR_E);
				break;
			case DISP_LIFT :
				string lift_manual_str;
				string lift_status_str;
				if (is_lift_manual) {
					lift_manual_str = "MANUAL";
				} else {
					lift_manual_str = "PID";
				}
				if (isDown) {
					lift_status_str = "DOWN";
				} else {
					lift_status_str = "UP";
				}
				nxtDisplayCenteredTextLine(0, "Lift-%s-%s", lift_manual_str, lift_status_str);
				nxtDisplayTextLine(1, "Pos: %+6i", lift_pos);
				nxtDisplayTextLine(2, "Tgt: %+6i", lift_target);
				nxtDisplayTextLine(3, "Pwr: %+3.3f", power_lift);
				nxtDisplayCenteredTextLine(4, "%+4i  %+4i  %+4i", term_P_lift, term_I_lift, term_D_lift);
				break;
			case DISP_HOPPER :
				nxtDisplayTextLine(0, "XYZ %+2.1f %+2.1f %3i", hopper_x_pos, hopper_y_pos, hopper_z_pos);
				nxtDisplayTextLine(1, "XYZ %+2.1f %+2.1f %3i", hopper_x_target, hopper_y_target, hopper_z_target);
				nxtDisplayTextLine(2, "k,i %+4i %+4i", hopper_theta, hopper_phi);
				nxtDisplayTextLine(3, "r,h %3.1f %3.1f", hopper_r, hopper_h);
				nxtDisplayTextLine(4, "encdr: %+6d", hopper_pos);
				nxtDisplayTextLine(5, "tgt  : %+6d", hopper_target);
				break;
			case DISP_JOYSTICKS :
				nxtDisplayCenteredTextLine(0, "--Driver I:--");
				nxtDisplayCenteredTextLine(1, "LX:%4i RX:%4i", joystick.joy1_x1, joystick.joy1_x2);
				nxtDisplayCenteredTextLine(2, "LY:%4i RY:%4i", joystick.joy1_y1, joystick.joy1_y2);
				nxtDisplayCenteredTextLine(4, "--Driver II:--");
				nxtDisplayCenteredTextLine(5, "LX:%4i RX:%4i", joystick.joy2_x1, joystick.joy2_x2);
				nxtDisplayCenteredTextLine(6, "LY:%4i RY:%4i", joystick.joy2_y1, joystick.joy2_y2);
				break;
			default :
				nxtDisplayCenteredTextLine(2, "Debug info");
				nxtDisplayCenteredTextLine(3, "for this screen");
				nxtDisplayCenteredTextLine(4, "is not currently");
				nxtDisplayCenteredTextLine(5, "available.");
				break;
		}

		if (Buttons_Released(NXT_BUTTON_L)==true) {
			Display_Clear();
			isMode = (DisplayMode)((isMode+DISP_NUM-1)%DISP_NUM);
			if (isMode==DISP_FCS) {
				Task_Spawn(displayDiagnostics);
			} else {
				Task_Kill(displayDiagnostics);
			}
		}
		if (Buttons_Released(NXT_BUTTON_R)==true) {
			Display_Clear();
			isMode = (DisplayMode)((isMode+DISP_NUM+1)%DISP_NUM);
			if (isMode==DISP_FCS) {
				Task_Spawn(displayDiagnostics);
			} else {
				Task_Kill(displayDiagnostics);
			}
		}
		Time_Wait(50); // MAGIC_NUM: Prevents the LCD from updating itself to death.
	}
}