Exemplo n.º 1
0
void logger_start()
{
	if (!config.logger.enabled)
		return;

	logger_next_flight();

	if (!storage_ready())
	{
		gui_showmessage_P(PSTR("SD card error!"));

		fc.logger_state = LOGGER_ERROR;

		return;
	}

	uint8_t sec;
	uint8_t min;
	uint8_t hour;
	uint8_t day;
	uint8_t wday;
	uint8_t month;
	uint16_t year;

	datetime_from_epoch(time_get_utc(), &sec, &min, &hour, &day, &wday, &month, &year);

	char path[128];

	//base dir
	sprintf_P(path, PSTR("%S"), LOG_DIR);
	f_mkdir(path);
	//year
	sprintf_P(path, PSTR("%S/%04d"), LOG_DIR, year);
	f_mkdir(path);
	//month
	sprintf_P(path, PSTR("%S/%04d/%02d"), LOG_DIR, year, month);
	f_mkdir(path);
	//day
	sprintf_P(path, PSTR("%S/%04d/%02d/%02d"), LOG_DIR, year, month, day);
	f_mkdir(path);

	switch (config.logger.format)
	{
		case(LOGGER_IGC):
			fc.logger_state = igc_start(path);
		break;

		case(LOGGER_KML):
			fc.logger_state = kml_start(path);
		break;

		case(LOGGER_RAW):
			fc.logger_state = raw_start(path);
		break;
	}
}
Exemplo n.º 2
0
bool StoreEEPROM()
{
	ewdt_reset();
	DEBUG("Storing settings\n");

	if (!storage_ready())
	{
		DEBUG("Error: Storage not available\n");
		return false;
	}

	FIL * ee_file;
	ee_file = new FIL;

	if (f_open(ee_file, "CFG.EE", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
	{
		DEBUG("Unable to create file\n");
		delete ee_file;

		return false;
	}
	uint16_t wd = 0;

	eeprom_busy_wait();
	eeprom_update_dword(&config_ee.build_number, BUILD_NUMBER);

	uint16_t i = 0;
	do
	{
		uint8_t buf[256];
		uint16_t rwd;

		if (i + sizeof(buf) < sizeof(cfg_t))
			wd = sizeof(buf);
		else
			wd = sizeof(cfg_t) - i;


		eeprom_busy_wait();
		eeprom_read_block(buf, (uint8_t *)(APP_INFO_EE_offset + i), wd);


		assert(f_write(ee_file, buf, wd, &rwd) == FR_OK);

		i += wd;
	} while (i < sizeof(cfg_t));

	f_close(ee_file);
	DEBUG("File closed\n");

	delete ee_file;
	return true;
}
Exemplo n.º 3
0
void skybean_file(uint8_t op)
{
	switch (op)
	{
		case(0x00):
			skybean_startpacket(1, SKYBEAN_FILE, op);
			skybean_stream.Write(storage_ready());
		break;

		case(0x01):
			skybean_file_list();
		break;

		case(0x02):
			skybean_startpacket(1, SKYBEAN_FILE, op);
			skybean_stream.Write(skybean_file_write());
		break;

		case(0x03):
			skybean_file_read();
		break;

		case(0x04):
			skybean_startpacket(1, SKYBEAN_FILE, op);
			skybean_stream.Write(skybean_file_close());
		break;

		case(0x05):
			skybean_startpacket(1, SKYBEAN_FILE, op);
			skybean_stream.Write(skybean_file_delete());
		break;

		case(0x06):
			skybean_startpacket(1, SKYBEAN_FILE, op);
			skybean_stream.Write(skybean_file_push());
		break;

		case(0x07):
			skybean_file_pull();
		break;

		case(0x08):
			skybean_startpacket(1, SKYBEAN_FILE, op);
			skybean_stream.Write(skybean_file_mkdir());
		break;
	}
}
Exemplo n.º 4
0
void gui_factory_test_init()
{
	DEBUG(" *** Factory test ***\n");
	fc_pause();
	led_notify_disable();

	//We need to test gps and bt module
	if (!bt_ready())
	{
		DEBUG("Force enable BT\n");
		bt_module_init();
	}

	if (!gps_selftest())
	{
		DEBUG("Force enable GPS\n");
		gps_start();
	}

	buzzer_set_vol(0);
	buzzer_set_freq(0);
	f_test_button_test = 0;

	f_test_lcd = FTEST_LCD_MIN_AUTO;

	if (storage_ready())
	{
		FILINFO fno;

		if (f_stat("SET_CONT", &fno) == FR_OK)
		{
			f_test_lcd_cont_max = 110;
			f_test_lcd_cont_min = 70;
			f_test_lcd_cont = 4;

			f_test_lcd = FTEST_LCD_DONE;
		}
	}


	disp.SetFlip(false);
	disp.SetInvert(false);
}
Exemplo n.º 5
0
void gui_factory_test_loop()
{
	gui_dialog_P(PSTR("Factory test"));

	bool blik = GUI_BLINK_TGL(1000);
	bool res;
	bool err = false;

	if (f_test_lcd)
	{
		char tmp[16];

		disp.LoadFont(F_TEXT_L);
		switch (f_test_lcd)
		{
			case(FTEST_LCD_MIN_AUTO):
				strcpy_P(tmp, PSTR("Min auto"));
			break;
			case(FTEST_LCD_MIN):
				strcpy_P(tmp, PSTR("Set minimum"));
			break;
			case(FTEST_LCD_MAX_AUTO):
				strcpy_P(tmp, PSTR("Max auto"));
			break;
			case(FTEST_LCD_MAX):
				strcpy_P(tmp, PSTR("Set maximum"));
			break;
			case(FTEST_LCD_MID):
				strcpy_P(tmp, PSTR("Set optimal"));
			break;
		}
		gui_caligh_text(tmp, GUI_DISP_WIDTH / 2, GUI_DIALOG_TOP);

		disp.DrawLine(4, 24, 14, 24, 1);
		disp.DrawLine(4, 26, 14, 26, 1);
		disp.DrawLine(4, 28, 14, 28, 1);
		disp.DrawLine(4, 30, 14, 30, 1);
		disp.DrawLine(4, 32, 14, 32, 1);

		disp.DrawLine(16, 24, 16, 32, 1);
		disp.DrawLine(18, 24, 18, 32, 1);
		disp.DrawLine(20, 24, 20, 32, 1);
		disp.DrawLine(22, 24, 22, 32, 1);
		disp.DrawLine(24, 24, 24, 32, 1);

		disp.DrawRectangle(26, 24, 35, 33, 1, 1);

		disp.DrawRectangle(37, 24, 46, 33, 1, 0);

		disp.DrawRectangle(48, 24, 57, 33, 1, 0);
		disp.DrawRectangle(50, 26, 55, 31, 1, 0);
		disp.DrawRectangle(52, 28, 53, 29, 1, 0);

		disp.DrawCircle(71, 35, 1, 1);
		disp.DrawCircle(71, 35, 3, 1);
		disp.DrawCircle(71, 35, 5, 1);
		disp.DrawCircle(71, 35, 7, 1);
		disp.DrawCircle(71, 35, 9, 1);

		disp.LoadFont(F_TEXT_M);
		disp.GotoXY(4, 36);
		fprintf_P(lcd_out, PSTR("%03d"), f_test_lcd_cont_min);
		disp.GotoXY(24, 36);
		fprintf_P(lcd_out, PSTR("%03d"), f_test_lcd_cont);
		disp.GotoXY(44, 36);
		fprintf_P(lcd_out, PSTR("%03d"), f_test_lcd_cont_max);

		if (f_test_lcd == FTEST_LCD_MIN_AUTO || f_test_lcd == FTEST_LCD_MAX_AUTO)
		{
			f_test_lcd_cont = (f_test_lcd_cont + 1) % 128;
		}

		led_set(0, f_test_lcd_cont / 4, 0);

		if (f_test_lcd == FTEST_LCD_MID)
			disp.SetContrast(lcd_contrast_min + ((lcd_contrast_max - lcd_contrast_min) * f_test_lcd_cont) / GUI_CONTRAST_STEPS);
		else
			disp.SetContrast(f_test_lcd_cont);

		return;
	}

	//store contrast values
	eeprom_busy_wait();
	eeprom_update_byte(&config_ro.lcd_contrast_max, f_test_lcd_cont_max);
	eeprom_update_byte(&config_ro.lcd_contrast_min, f_test_lcd_cont_min);
	eeprom_update_byte(&config_ee.gui.contrast, f_test_lcd_cont);
	eeprom_busy_wait();

	//reload contrast value
	gui_load_eeprom();

	disp.LoadFont(F_TEXT_S);
	uint8_t f_h = disp.GetTextHeight();

	if (!mems_i2c_selftest())
	{
		if (blik)
		{
			disp.GotoXY(4, f_h * 3.5 + 3);
			fprintf_P(lcd_out, PSTR("I2C ERROR"));
			assert(0);
		}
		err = true;
	}
	else
	{
		res = ms5611.SelfTest();
		if (!res) err = true;
		if (res || blik)
		{
			disp.GotoXY(4, f_h * 2 + 3);
			fprintf_P(lcd_out, PSTR("MS5611:%s"), (res) ? "OK" : "ERR");
			assert(res);
		}

		res = lsm303d.SelfTest();
		if (!res) err = true;
		if (res || blik)
		{
			disp.GotoXY(4, f_h * 3 + 3);
			fprintf_P(lcd_out, PSTR("LSM303:%s"), (res) ? "OK" : "ERR");
			assert(res);
		}

		res = l3gd20.SelfTest();
		if (!res) err = true;
		if (res || blik)
		{
			disp.GotoXY(4, f_h * 4 + 3);
			fprintf_P(lcd_out, PSTR("L3GD20:%s"), (res) ? "OK" : "ERR");
			assert(res);
		}

		res = sht21.SelfTest();
		if (!res) err = true;
		if (res || blik)
		{
			disp.GotoXY(4, f_h * 5 + 3);
			fprintf_P(lcd_out, PSTR("SHT21:%s"), (res) ? "OK" : "ERR");
			assert(res);
		}
	}

	res = bt_ready();
	if (!res) err = true;
	if (res || blik)
	{
		assert(res);
		disp.GotoXY(4, f_h * 6 + 3);
		if (!res)
		{
			fprintf_P(lcd_out, PSTR("BT:ERR"));
		}
		else
		{
			if (bt_get_module_type() == BT_PAN1322)
				fprintf_P(lcd_out, PSTR("BT:1322"));
			else
				fprintf_P(lcd_out, PSTR("BT:1026"));
		}
	}

	res = storage_ready();
	if (!res) err = true;
	if (res || blik)
	{
		disp.GotoXY(GUI_DISP_WIDTH / 2, f_h * 2 + 3);
		fprintf_P(lcd_out, PSTR("SD:%s"), (res) ? "OK" : "ERR");
		assert(res);
	}

	res = gps_selftest();
	if (!res) err = true;
	if (res || blik)
	{
		disp.GotoXY(GUI_DISP_WIDTH / 2, f_h * 3 + 3);
		fprintf_P(lcd_out, PSTR("GPS:%s"), (res) ? "OK" : "ERR");
		assert(res);
	}

	res = f_test_button_test == 0b00000111;
	if (!res) err = true;
	if (res || blik)
	{
		disp.GotoXY(GUI_DISP_WIDTH / 2, f_h * 4 + 3);
		fprintf_P(lcd_out, PSTR("BUT:%d %d %d"), f_test_button_test & (1 << 0), (f_test_button_test & (1 << 1)) >> 1, (f_test_button_test & (1 << 2)) >> 2);
		assert(res);
	}