main_app.cpp 35.5 KB
Newer Older
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
/*
 * main_app.cpp
 */

#include <main.h>

#include <api/init.h>
#include <stdio.h>
#include <api/io_handle.h>
#include <api/dev_request.h>


#if (USE_SCREEN_GUI == true)
#include "lib/gfx/window.h"
#include "lib/gfx/PasswordWindowNumeric.h"
#endif


#ifdef _USE_HIH613x
#include <device/hih6130.h>
#endif
#ifdef _USE_MPU60x0_9150
#include <device/mpu60x0_9x50.h>
#endif
#ifdef _USE_AK8975
#include <device/ak8975.h>
#endif
#ifdef _USE_BMP180
#include <device/bmp180.h>
#endif
#ifdef _USE_MPL3115A2
#include <device/mpl3115a2.h>
#endif
#ifdef _USE_MPR121
#include <device/mpr121.h>
#endif
#ifdef _USE_L3GD20
#include <device/l3gd20.h>
#endif
#ifdef _USE_BMA250
#include <device/bma250.h>
#endif
#ifdef _USE_LSM9DS1
#include <device/lsm9ds1.h>
#endif
#ifdef _USE_LPS25HB
#include <device/lps25hb.h>
#endif
#ifdef _USE_MCP79410
#include <device/mcp79410.h>
#endif
#ifdef _USE_TCN75A
#include <device/tcn75s.h>
#endif
#ifdef _USE_SSD1331
#include <device/ssd1331.h>
#endif
#include <sys/core_init.h>
#include <app/sys/cmd.h>

#include <app/lwip/http_client/http_client.h>

#if (USE_SCREEN_GUI == true)
GI::Screen::Gfx::Window *MainWindow = NULL;
GI::Screen::Gfx::TextBox *SensorResultTextboxGlobal;
#endif

#if (USE_UART == 1 && USE_TERMINAL == 1)
Cmd *term_cmd;

void cmdCharRecCallback(char data)
{
	term_cmd->parse(data);
}
#endif

void main_app(void)
{
	GI::Sys::Timer timer_touch = GI::Sys::Timer(20);
	GI::Sys::Timer blink_timer = GI::Sys::Timer(100);

	bool led_state = false;

#ifdef _USE_HIH613x
	GI::Sys::Timer hih613timer = GI::Sys::Timer(1000);
#endif
#if defined(_USE_MPU60x0_9150) && defined(_USE_AK8975)
	GI::Sys::Timer mpu60x0_9x50_timer = GI::Sys::Timer(200);
#endif
#ifdef _USE_BMP180
	GI::Sys::Timer bmp180_timer = GI::Sys::Timer(1000);
#endif
#ifdef _USE_MPL3115A2
	GI::Sys::Timer mpl3115_timer = GI::Sys::Timer(1000);
#endif
#ifdef _USE_MPR121
	GI::Sys::Timer mpr121_timer = GI::Sys::Timer(50);
#endif
#ifdef _USE_L3GD20
    GI::Sys::Timer l3gd20_timer = GI::Sys::Timer(50);
#endif
#ifdef _USE_BMA250
    GI::Sys::Timer bma250_timer = GI::Sys::Timer(50);
#endif
#ifdef _USE_LSM9DS1
    GI::Sys::Timer lsm9ds1_timer = GI::Sys::Timer(50);
#endif
#ifdef _USE_LPS25HB
    GI::Sys::Timer lps25hb_timer = GI::Sys::Timer(25);
#endif
#ifdef _USE_MCP79410
    GI::Sys::Timer mcp79410_timer = GI::Sys::Timer(250);
#endif
#ifdef _USE_TCN75A
    GI::Sys::Timer tcn75a_timer = GI::Sys::Timer(1000);
    GI::Sys::Timer tcn75a_timer_ready = GI::Sys::Timer(100);
#endif


#if (USE_SCREEN_GUI == true)
#if (USE_WINDOW == true)
	/*
	 * Create one parent window.
	 */
	MainWindow = new GI::Screen::Gfx::Window(NULL, dev.SCREEN[0]);
	MainWindow->AllowHScroll = false;
	MainWindow->AllowVScroll = false;
	MainWindow->HideHScroll = true;
	MainWindow->HideVScroll = true;
	MainWindow->MaxMinEnabled = true;
	MainWindow->MinimizeButonEnabled = false;
	MainWindow->CloseButonEnabled = false;
	MainWindow->Caption->textAlign = alignLeft;

	/*
	 * Create a picture box.
	 */
	newPictureBox(MainWindow, FlirPictureBox);
	//FlirPictureBox_Global = FlirPictureBox;
	FlirPictureBox->Position.X = 10;
	FlirPictureBox->Position.Y = 10;
	FlirPictureBox->Size.X = 460;
	FlirPictureBox->Size.Y = 160;
	FlirPictureBox->BackgroundColor = 0xFFFFFFFF;

	/*
	 * Create a text box.
	 */
	newTextBox(MainWindow, SensorResultTextbox);
	SensorResultTextboxGlobal = SensorResultTextbox;
	SensorResultTextbox->Position.X = 10;
	SensorResultTextbox->Position.Y = FlirPictureBox->Position.Y + FlirPictureBox->Size.Y + 10;
	SensorResultTextbox->Size.X = 460;
	SensorResultTextbox->Size.Y = 200;
	SensorResultTextbox->Size.ScrollSize = 50;
	SensorResultTextbox->text->setText((string)"This is a sensor result textbox");

	/*
	 * Create a button.
	 */
	newButton(MainWindow, Buton1);
	Buton1->Position.X = 10;
	Buton1->Position.Y = SensorResultTextbox->Position.Y + SensorResultTextbox->Size.Y + 10;
	Buton1->Size.X = 100;
	Buton1->Size.Y = 50;

	/*
	 * Create a progress bar.
	 */
	newProgressBar(MainWindow, ProgressBar1);
	ProgressBar1->MinimValue  = 0;
	ProgressBar1->MaximValue = 100;
	ProgressBar1->Value = 50;
	ProgressBar1->Position.X = 10;
	ProgressBar1->Position.Y = Buton1->Position.Y + Buton1->Size.Y + 10;
	ProgressBar1->Size.X = 460;
	ProgressBar1->Size.Y = 30;

	/*
	 * Create a check box.
	 */
	newCheckBox(MainWindow, CheckBox1);
	CheckBox1->Position.X = 10;
	CheckBox1->Position.Y = ProgressBar1->Position.Y + ProgressBar1->Size.Y + 10;
	CheckBox1->Size.X = 460;
	CheckBox1->Size.Y = 30;

	/*
	 * Create a list box.
	 */
	newListBox(MainWindow, ListBox);
	ListBox->Position.X = 10;
	ListBox->Position.Y = CheckBox1->Position.Y + CheckBox1->Size.Y + 10;
	ListBox->Size.X = 460;
	ListBox->Size.Y = MainWindow->Internals.pDisplay->LcdTimings->Y - (CheckBox1->Position.Y + CheckBox1->Size.Y + 30);
	ListBox->Size.ScrollSize = 50;
	ListBox->Size.ItemSizeY = 30;
	ListBox->Size.MinScrollBtnSize = 30;
	ListBox->Caption->textAlign = alignLeft;
#else /* USE_WINDOW == false */
	/*
	 * No parent window used.
	 */

	/*
	 * Create a picture box.
	 */
	GI::Screen::Gfx::Picturebox *FlirPictureBox = new GI::Screen::Gfx::Picturebox(dev.SCREEN[0]);
	//FlirPictureBox_Global = FlirPictureBox;
	FlirPictureBox->Position.X = 10;
	FlirPictureBox->Position.Y = 10;
	FlirPictureBox->Size.X = 460;
	FlirPictureBox->Size.Y = 160;
	FlirPictureBox->BackgroundColor = 0xFFFFFFFF;

	/*
	 * Create a text box.
	 */
	GI::Screen::Gfx::TextBox *SensorResultTextbox = new GI::Screen::Gfx::TextBox(dev.SCREEN[0]);
	SensorResultTextboxGlobal = SensorResultTextbox;
	SensorResultTextbox->Position.X = 10;
	SensorResultTextbox->Position.Y = FlirPictureBox->Position.Y + FlirPictureBox->Size.Y + 10;
	SensorResultTextbox->Size.X = 460;
	SensorResultTextbox->Size.Y = 200;
	SensorResultTextbox->Size.ScrollSize = 50;
	SensorResultTextbox->text->setText((string)"This is a sensor result textbox");

	/*
	 * Create a button.
	 */
	GI::Screen::Gfx::Button *Buton1 = new GI::Screen::Gfx::Button(dev.SCREEN[0]);
	Buton1->Position.X = 10;
	Buton1->Position.Y = SensorResultTextbox->Position.Y + SensorResultTextbox->Size.Y + 10;
	Buton1->Size.X = 100;
	Buton1->Size.Y = 50;

	/*
	 * Create a progress bar.
	 */
	GI::Screen::Gfx::ProgressBar *ProgressBar1 = new GI::Screen::Gfx::ProgressBar(dev.SCREEN[0]);
	ProgressBar1->MinimValue  = 0;
	ProgressBar1->MaximValue = 100;
	ProgressBar1->Value = 50;
	ProgressBar1->Position.X = 10;
	ProgressBar1->Position.Y = Buton1->Position.Y + Buton1->Size.Y + 10;
	ProgressBar1->Size.X = 460;
	ProgressBar1->Size.Y = 30;

	/*
	 * Create a check box.
	 */
	GI::Screen::Gfx::CheckBox *CheckBox1 = new GI::Screen::Gfx::CheckBox(dev.SCREEN[0]);
	CheckBox1->Position.X = 10;
	CheckBox1->Position.Y = ProgressBar1->Position.Y + ProgressBar1->Size.Y + 10;
	CheckBox1->Size.X = 460;
	CheckBox1->Size.Y = 30;

	/*
	 * Create a list box.
	 */
	GI::Screen::Gfx::ListBox *ListBox = new GI::Screen::Gfx::ListBox(dev.SCREEN[0]);
	ListBox->Position.X = 10;
	ListBox->Position.Y = CheckBox1->Position.Y + CheckBox1->Size.Y + 10;
	ListBox->Size.X = 460;
	ListBox->Size.Y = dev.SCREEN[0]->LcdTimings->Y - (CheckBox1->Position.Y + CheckBox1->Size.Y + 30);
	ListBox->Size.ScrollSize = 50;
	ListBox->Size.ItemSizeY = 30;
	ListBox->Size.MinScrollBtnSize = 30;
	ListBox->Caption->textAlign = alignLeft;
#endif
	/*
	 * Populate list box with 256 items.
	 */
	u32 cnt = 0;
	char listbox_buff[32];
	char buff_tmp[10];
	for(; cnt < 256; cnt++)
	{
		strcpy((string)listbox_buff, "Device ID ");
		utoa(cnt + 1, buff_tmp, 10);
		strcat(listbox_buff, buff_tmp);
		ListBox->add(listbox_buff);
	}


#if(_USE_PASSWORD_PROTECTION == 1)
	newWindowPasswordNumeric(MainWindow, pass, 2, 2);
#endif
289
#endif/*!(USE_SCREEN_GUI == true)*/
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
	/*
	 * Put on parent window caption the IP of ETH interface.
	 */
#if (USE_LWIP == 1)
	GI::String ipAddressStr = GI::String();
	GI::String ip_str_buff = GI::String();
	dev.LWIP[0]->getIp(&ip_str_buff);
	//MainWindow->Caption->setTextF("IP:%s\n\r", ip_str_buff.buff);
	ipAddressStr.set((string)"IP:");
	ipAddressStr.append(ip_str_buff.buff);
	bool old_state_ip_assigned = false;
	//dev._stdout->printF("IP:%s\n\r", ip_str_buff.buff);
#endif

#ifdef _USE_HIH613x
	GI::Device::Sensor::Hih613x hih6130 = GI::Device::Sensor::Hih613x((string)_USE_HIH613x);
#endif
#ifdef _USE_MPU60x0_9150
	GI::Device::Sensor::Mpu60x0_9x50 mpu60x0_9x50 = GI::Device::Sensor::Mpu60x0_9x50((string)_USE_MPU60x0_9150, 0);
#endif
#if defined(_USE_AK8975) && defined(_USE_MPU60x0_9150)
	/*
	 * If AK8975 is inside MPU9150 you need to put this after you initialize the MPU device.
	 */
	GI::Device::Sensor::Ak8975 ak8975_0 = GI::Device::Sensor::Ak8975((string)_USE_AK8975, 0);
#endif
#ifdef _USE_BMP180
	GI::Device::Sensor::Bmp180 bmp180_0 = GI::Device::Sensor::Bmp180((string)_USE_BMP180, 0);
#endif
#ifdef _USE_MPL3115A2
	GI::Device::Sensor::Mpl3115a2 mpl3115a2 = GI::Device::Sensor::Mpl3115a2((string)_USE_MPL3115A2);
#endif
#ifdef _USE_MPR121
	GI::Device::Sensor::Mpr121 mpr121_0 = GI::Device::Sensor::Mpr121((string)_USE_MPR121, (string)"", 0);
#endif
#ifdef _USE_L3GD20
	GI::Device::Sensor::L3gd20 l3gd20_0 = GI::Device::Sensor::L3gd20((string)_USE_L3GD20);
#endif
#ifdef _USE_BMA250
	GI::Device::Sensor::Bma250 bma250_0 = GI::Device::Sensor::Bma250((string)_USE_BMA250);
#endif
#ifdef _USE_LSM9DS1
	GI::Device::Sensor::Lsm9ds1 lsm9ds1_0 = GI::Device::Sensor::Lsm9ds1((string)_USE_LSM9DS1, 1, 1);
#endif
#ifdef _USE_LPS25HB
	GI::Device::Sensor::Lps25hb lps25hb_0 = GI::Device::Sensor::Lps25hb((string)_USE_LPS25HB, 1);
#endif
#ifdef _USE_MCP79410
	GI::Device::Rtc::Mcp79410 mcp79410_0 = GI::Device::Rtc::Mcp79410((string)_USE_MCP79410);
#endif
#ifdef _USE_TCN75A
	GI::Device::Sensor::Tcn75s tcn75a_0 = GI::Device::Sensor::Tcn75s((string)_USE_TCN75A, 0);
#endif
#ifdef _USE_SSD1331
	GI::Device::Display::Ssd1331 *ssd1331_0 = new GI::Device::Display::Ssd1331(_USE_SSD1331);
#endif
346 347 348
#ifdef _USE_SSD1306
	GI::Device::Display::Ssd1306 *ssd1306_0 = new GI::Device::Display::Ssd1306(_USE_SSD1306);
#endif
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366

#if (USE_UART == 1 && USE_TERMINAL == 1)
	term_cmd = new Cmd((string)CONSOLE_UART_IN, (string)CONSOLE_UART_OUT, (string)CONSOLE_UART_ERR);
	//GI::Dev::Uart *uartDev;
	//GI::Dev::DevRequest::request((char *)CONSOLE_UART_IN, &uartDev);
	//uartDev->charReceive_Callback = cmdCharRecCallback;
#endif
	/*GI::Sys::Clock::changeCoreClk(25000000);
	unsigned long baud = 1200;
	terminal.ctl(GI::IO::IO_CTL_SET_SPEED, &baud);*/

#if (SHOW_SENSORS_RESULT_ON_SCREEN == 0)
	GI::IO terminal = GI::IO((string)CONSOLE_UART_OUT);
#endif
	//terminal.write((unsigned char *)buffer, bytesread);
	
#if (USE_SCREEN == true && USE_SCREEN_GUI == false && SCREENS_COUNT > 0)
	/* These functions interact directly with registered driver, the GUI library is not used because the display resolution is too tinny. */
367 368 369 370 371 372 373 374
	dev.SCREEN[0]->drawPixel(3, 1, Color::White);
	dev.SCREEN[0]->drawRectangle(1, 3, 5, 5, true, Color::White);
	dev.SCREEN[0]->drawRectangle(1, 9, 5, 5, false, Color::White);
	dev.SCREEN[0]->drawHLine(1, 16, 16, 1, Color::White);//Optimized linear horizontal line.
	dev.SCREEN[0]->drawVLine(18, 10, 8, 1, Color::White);//Optimized linear verical line.
	dev.SCREEN[0]->drawString((string)"Morgoth CppSDK example application", 16, 0, NULL, true, 0, Color::White);
	dev.SCREEN[0]->drawCircle(32, 23, 8, 1, Color::White);
	dev.SCREEN[0]->drawCircle(50, 23, 8, 0, Color::White);
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
375
#ifndef SmartRf06// The TI CC1310 compiler has an issue with floating point operations that make the uC to generate a fault interrupt, I think that is a stack problem.
376 377
	dev.SCREEN[0]->drawElipse(69, 23, 8, 4, 1, Color::White);
	dev.SCREEN[0]->drawElipse(83, 23, 4, 8, 0, Color::White);
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
378
#endif
379 380
	dev.SCREEN[0]->drawLine(90, 16, 110, 25, 1, Color::White);//Complex inclined line.
	dev.SCREEN[0]->drawLine(98, 16, 118, 25, 3, Color::White);//Complex inclined line.
381
	dev.SCREEN[0]->refresh();
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
#endif
#ifdef _USE_SSD1331
	if(ssd1331_0)/* This display driver is used like an external device (non registered display driver), you can declare more displays in this form, even multiplexed on same SPI interface. */
	{
	    ssd1331_0->clear(Color::Black);
	    ssd1331_0->drawPixel(3, 1, Color::Red);
	    ssd1331_0->drawRectangle(1, 3, 5, 5, true, Color::Blue);
	    ssd1331_0->drawRectangle(1, 9, 5, 5, false, Color::Red);
	    ssd1331_0->drawHLine(1, 16, 16, 1, Color::Blue);//Optimized linear horizontal line.
	    ssd1331_0->drawVLine(18, 10, 8, 1, Color::Red);//Optimized linear verical line.
	    ssd1331_0->drawString((string)"Morgoth CppSDK example application", 16, 0, NULL, true, 0, 0x0000FF00);
	    ssd1331_0->drawCircle(32, 23, 8, 1, Color::Blue);
	    ssd1331_0->drawCircle(50, 23, 8, 0, Color::Red);
#ifndef SmartRf06// The TI CC1310 compiler has an issue with floating point operations that make the uC to generate a fault interrupt, I think that is a stack problem.
	    ssd1331_0->drawElipse(69, 23, 8, 4, 1, Color::Yellow);
	    ssd1331_0->drawElipse(83, 23, 4, 8, 0, Color::Red);
#endif
	    ssd1331_0->drawLine(90, 16, 110, 25, 1, Color::YellowGreen);//Complex inclined line.
	    ssd1331_0->drawLine(98, 16, 118, 25, 3, Color::Red);//Complex inclined line.
401
		ssd1331_0->refresh();
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
402 403
	}
#endif
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
#ifdef _USE_SSD1306
	if(ssd1306_0)/* This display driver is used like an external device (non registered display driver), you can declare more displays in this form, even multiplexed on same SPI interface. */
	{
		ssd1306_0->clear(Color::Black);
		ssd1306_0->drawPixel(3, 1, Color::White);
		ssd1306_0->drawRectangle(1, 3, 5, 5, true, Color::White);
		ssd1306_0->drawRectangle(1, 9, 5, 5, false, Color::White);
		ssd1306_0->drawHLine(1, 16, 16, 1, Color::White);//Optimized linear horizontal line.
		ssd1306_0->drawVLine(18, 10, 8, 1, Color::White);//Optimized linear verical line.
		ssd1306_0->drawString((string)"Morgoth CppSDK example application", 16, 0, NULL, true, Color::Black, Color::White);
		ssd1306_0->drawCircle(32, 23, 8, 1, Color::White);
		ssd1306_0->drawCircle(50, 23, 8, 0, Color::White);
#ifndef SmartRf06// The TI CC1310 compiler has an issue with floating point operations that make the uC to generate a fault interrupt, I think that is a stack problem.
		ssd1306_0->drawElipse(69, 23, 8, 4, 1, Color::White);
		ssd1306_0->drawElipse(83, 23, 4, 8, 0, Color::White);
#endif
		ssd1306_0->drawLine(90, 16, 110, 25, 1, Color::White);//Complex inclined line.
		ssd1306_0->drawLine(98, 16, 118, 25, 3, Color::White);//Complex inclined line.
422
		ssd1306_0->refresh();
423 424
	}
#endif
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549

	while(1)
	{
		//GI::Sys::Clock::sleep();
		dev.idle();
#if (USE_UART == 1 && USE_TERMINAL == 1)
		term_cmd->idle();
#endif
#if (USE_LWIP == 1)
		if(old_state_ip_assigned == false && dev.LWIP[0]->ipAssigned == true)
		{
			old_state_ip_assigned = true;
			/*
			 * Update on parent window caption the IP of ETH interface if is assigned by DHCP.
			 */
			GI::String ip_str_buff = GI::String();
			dev.LWIP[0]->getIp(&ip_str_buff);
			//MainWindow->Caption->setTextF("IP:%s\n\r", ip_str_buff.buff);
			//dev._stdout->printF("IP:%s\n\r", ip_str_buff.buff);
			ipAddressStr.set((string)"IP:");
			ipAddressStr.append(ip_str_buff.buff);
		}
#endif
#if (USE_LWIP == 1)
		if(ipAddressStr.modifyed || dev.SNTP_CLIENT->time_update)
		{
			ipAddressStr.modifyed = 0;
			dev.SNTP_CLIENT->time_update = 0;
			MainWindow->Caption->setTextF(&ipAddressStr);
			/*@todo: "The server does not respond"*/
			//tcp_setup((char *)"google.com",(char *)"GET /");
			if(dev.SNTP_CLIENT->time_str->length)
				MainWindow->Caption->appendF(",Time:%s", dev.SNTP_CLIENT->time_str->buff);
		}
#endif
		/*
		 * Call every 20ms the idle function of touch screen interface
		 * 	and idle function of parent window.
		 */
		if(timer_touch.tick())
		{
#if (USE_SCREEN_GUI == true)
#if (USE_WINDOW == true)
#ifdef USED_TOUCHSCREEN_1
			MainWindow->idle(dev.CURSORCTRL[0]->idle());
#else
			MainWindow->idle(NULL);
#endif
#else /* USE_WINDOW != true */
#ifdef USED_TOUCHSCREEN_1 /* If you don't use a parent window you need to check by your self if a cursor was down inside an item to not be propagated to other items in same location. */
			tControlCommandData *tmpTouch = dev.CURSORCTRL[0]->idle();
			FlirPictureBox->idle(tmpTouch);
			if(FlirPictureBox->Internals.CursorDownInsideBox)
				goto _continue;
			SensorResultTextbox->idle(tmpTouch);
			if(SensorResultTextbox->Internals.CursorDownInsideBox)
				goto _continue;
			Buton1->idle(tmpTouch);
			if(Buton1->Internals.CursorDownInsideBox)
				goto _continue;
			ProgressBar1->idle(tmpTouch);
			if(ProgressBar1->Internals.CursorDownInsideBox)
				goto _continue;
			CheckBox1->idle(tmpTouch);
			if(CheckBox1->Internals.CursorDownInsideBox)
				goto _continue;
			ListBox->idle(tmpTouch);
			if(ListBox->Internals.CursorDownInsideBox)
				goto _continue;
#else /* !USED_TOUCHSCREEN_1 */ /* For future development (Keyboard selection) */
			FlirPictureBox->idle();
			if(FlirPictureBox->Internals.CursorDownInsideBox)
				goto _continue;
			SensorResultTextbox->idle();
			if(SensorResultTextbox->Internals.CursorDownInsideBox)
				goto _continue;
			Buton1->idle();
			if(Buton1->Internals.CursorDownInsideBox)
				goto _continue;
			ProgressBar1->idle();
			if(ProgressBar1->Internals.CursorDownInsideBox)
				goto _continue;
			CheckBox1->idle();
			if(CheckBox1->Internals.CursorDownInsideBox)
				goto _continue;
			ListBox->idle();
			if(ListBox->Internals.CursorDownInsideBox)
				goto _continue;
#endif
#endif
#endif
#if (_USE_PASSWORD_PROTECTION == 1)
			if(pass->idle())
			{
				if(pass->password->equal((string)"1234"))
					pass->internals.windowHandler->Visible = false;
				else
				{
					pass->clearText->set((string)"Wrong password!");
				}
			}
#endif
		}
//#if (USE_SCREEN_GUI == true && USE_SCREEN_GUI == false)
_continue:
//#endif
		if(blink_timer.tick())
		{
			bool state;
			GI::IO::read((string)"led-0", &state);
			if(state)
			{
				if(led_state)
				{
					blink_timer.interval(780);
					led_state = false;
				}
				else
				{
					blink_timer.interval(180);
					led_state = true;
				}
				GI::IO::write((string)"led-0", false);
#ifdef _USE_SSD1331
				ssd1331_0->drawRectangle(1, 32, 5, 5, true, Color::Black);
550
				ssd1331_0->refresh();
551 552 553
#endif
#ifdef _USE_SSD1306
				ssd1306_0->drawRectangle(96, 24, 5, 5, true, Color::Black);
554
				ssd1306_0->refresh();
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
555 556 557 558 559 560 561 562
#endif
			}
			else
			{
				blink_timer.interval(20);
				GI::IO::write((string)"led-0", true);
#ifdef _USE_SSD1331
				ssd1331_0->drawRectangle(1, 32, 5, 5, true, Color::Red);
563
				ssd1331_0->refresh();
564 565 566
#endif
#ifdef _USE_SSD1306
				ssd1306_0->drawRectangle(96, 24, 5, 5, true, Color::White);
567
				ssd1306_0->refresh();
Iulian Gheorghiu's avatar
Iulian Gheorghiu committed
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
#endif
			}
		}
#ifdef _USE_HIH613x
		if(hih613timer.tick())
		{
			unsigned char hih613x_status = 0;;
			float hih613x_hum = 0;
			float hih613x_temp = 0;
			if(!hih6130.get(&hih613x_status, &hih613x_hum, &hih613x_temp))
			{
				switch(hih613x_status)
				{
				case 0:
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
					ListBox->Items[0]->Caption->setTextF((string)"HIH613x: T = %3.2f, H = %2.1f", hih613x_temp, hih613x_hum);
#else
					GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"HIH613x: T = %3.2f, H = %2.1f\r", hih613x_temp, hih613x_hum);
#endif
					break;
				case 1:
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
					ListBox->Items[0]->Caption->setText((string)"HIH613x: stale data");
#else
					GI::IO::write((char *)CONSOLE_UART_OUT, (string)"HIH613x: stale data\r");
#endif
					break;
				case 2:
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
					ListBox->Items[0]->Caption->setText((string)"HIH613x: in command mode");
#else
					GI::IO::write((char *)CONSOLE_UART_OUT, (string)"HIH613x: in command mode\r");
#endif
					break;
				case 3:
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
					ListBox->Items[0]->Caption->setText((string)"HIH613x: diagnostic");
#else
					GI::IO::write((char *)CONSOLE_UART_OUT, (string)"HIH613x: diagnostic\r");
#endif
					break;
				}
			}
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				SensorResultTextbox->text->append((string)"HIH613x:  error reading temperature and humidity");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"HIH613x:  error reading temperature and humidity\r");
#endif
		}
#endif
#ifdef _USE_MPU60x0_9150
		bool mpu60x0_9x50_timer_ticked = false;
		if(mpu60x0_9x50_timer.tick())
		{
			mpu60x0_9x50_timer_ticked = true;
			float mpu60x0_9150_temp = 0.0;
			signed short mpu60x0_9150_gyro_Xg = 0;
			signed short mpu60x0_9150_gyro_Yg = 0;
			signed short mpu60x0_9150_gyro_Zg = 0;
			signed short mpu60x0_9150_accel_Xa = 0;
			signed short mpu60x0_9150_accel_Ya = 0;
			signed short mpu60x0_9150_accel_Za = 0;
			if(!mpu60x0_9x50.getTempData(&mpu60x0_9150_temp))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[1]->Caption->setTextF((string)"MPU60x0: Temp:  %3.2f Gr Celsius", mpu60x0_9150_temp);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"MPU60x0: Temp:  %3.2f Gr Celsius\r", mpu60x0_9150_temp);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[1]->Caption->setText((string)"MPU60x0: error reading temperature");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"MPU60x0: error reading temperature\r");
#endif

			if(!mpu60x0_9x50.getGyroData(&mpu60x0_9150_gyro_Xg, &mpu60x0_9150_gyro_Yg, &mpu60x0_9150_gyro_Zg))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[2]->Caption->setTextF((string)"MPU60x0: Giro:  Xg = %6d, Yg = %6d, Zg = %6d", mpu60x0_9150_gyro_Xg, mpu60x0_9150_gyro_Yg, mpu60x0_9150_gyro_Zg);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"MPU60x0: Giro:  Xg = %6d, Yg = %6d, Zg = %6d\r", mpu60x0_9150_gyro_Xg, mpu60x0_9150_gyro_Yg, mpu60x0_9150_gyro_Zg);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[2]->Caption->setText((string)"MPU60x0: error reading giroscope");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"MPU60x0: error reading giroscope\r");
#endif

			if(!mpu60x0_9x50.getAccelData(&mpu60x0_9150_accel_Xa, &mpu60x0_9150_accel_Ya, &mpu60x0_9150_accel_Za))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[3]->Caption->setTextF((string)"MPU60x0: Accel: Xa = %6d, Ya = %6d, Za = %6d", mpu60x0_9150_accel_Xa, mpu60x0_9150_accel_Ya, mpu60x0_9150_accel_Za);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"MPU60x0: Accel: Xa = %6d, Ya = %6d, Za = %6d\r", mpu60x0_9150_accel_Xa, mpu60x0_9150_accel_Ya, mpu60x0_9150_accel_Za);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[3]->Caption->setText((string)"MPU60x0: error reading accelerometer");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"MPU60x0: error reading accelerometer\r");
#endif
		}
#endif
#if defined(_USE_AK8975) && defined(_USE_MPU60x0_9150)
		if(mpu60x0_9x50_timer_ticked)
		{
			signed short AK8975_X_Axis = 0, AK8975_Y_Axis = 0, AK8975_Z_Axis = 0;
			if(!ak8975_0.getMag(&AK8975_X_Axis, &AK8975_Y_Axis, &AK8975_Z_Axis))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[4]->Caption->setTextF((string)"AK8975: Magne: Xm = %6d, Ym = %6d, Zm = %6d", AK8975_X_Axis, AK8975_Y_Axis, AK8975_Z_Axis);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"AK8975: Magne: Xm = %6d, Ym = %6d, Zm = %6d\r", AK8975_X_Axis, AK8975_Y_Axis, AK8975_Z_Axis);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[4]->Caption->setText((string)"AK8975: error reading magnetometer");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"AK8975: error reading magnetometer\r");
#endif
		}
#endif
#ifdef _USE_BMP180
		if(bmp180_timer.tick())
		{
			float bmp180_temperature = 0.0;
			float bmp180_pressure = 0.0;
			float bmp180_altitude = 0.0;
			if(!bmp180_0.getTemp(&bmp180_temperature) &&
					!bmp180_0.getPressure(&bmp180_pressure, GI::Device::Sensor::Bmp180::BMP180_CTRL_MEAS_OSS_8) &&
						!bmp180_0.getAltitude(&bmp180_altitude, GI::Device::Sensor::Bmp180::BMP180_CTRL_MEAS_OSS_8))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[5]->Caption->setTextF((string)"BMP180: Temp = %3.1f, Press = %4.2f, Alt = %4.2f", bmp180_temperature, bmp180_pressure, bmp180_altitude);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"BMP180: Temp = %3.1f, Press = %4.2f, Alt = %4.2f\r", bmp180_temperature, bmp180_pressure, bmp180_altitude);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[5]->Caption->setText((string)"BMP180: error reading temp, press and altitude");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"BMP180: error reading temp, press and altitude\r");
#endif
		}
#endif
#ifdef _USE_MPL3115A2
		if(mpl3115_timer.tick())
		{
			float mpl3115a2_pressure = 0.0, mpl3115a2_altitude = 0.0, mpl3115a2_temp = 0.0;
			if(!mpl3115a2.getAltTemp(2, &mpl3115a2_pressure, &mpl3115a2_altitude, &mpl3115a2_temp))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[6]->Caption->setTextF((string)"MPL3115A1: T = %3.3f, P = %3.5f, Alt = %4.3f", mpl3115a2_temp, 0.0, mpl3115a2_altitude);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"MPL3115A1: T = %3.3f, P = %3.5f, Alt = %4.3f\r", mpl3115a2_temp, 0.0, mpl3115a2_altitude);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[6]->Caption->setText((string)"MPL3115A1: error reading temp, press and altitude");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"MPL3115A1: error reading temp, press and altitude\r");
#endif
		}
#endif
#ifdef _USE_MPR121
		if(mpr121_timer.tick())
		{
			mpr121_ret_t mpr121_return;
			if(!mpr121_0.idle(&mpr121_return))
			{
				if(mpr121_return.pushed)
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
					ListBox->Items[7]->Caption->setTextF((string)"MPR121: Pushed   - K0=%u, K1=%u, K2=%u, K3=%u, K4=%u, K5=%u, K6=%u, K7=%u, K8=%u, K9=%u, K10=%u, K11=%u",     (unsigned long)mpr121_return.pushed & 0x01,   (unsigned long)(mpr121_return.pushed >> 1) & 0x01,   (unsigned long)(mpr121_return.pushed >> 2) & 0x01,   (unsigned long)(mpr121_return.pushed >> 3) & 0x01,   (unsigned long)(mpr121_return.pushed >> 4) & 0x01,   (unsigned long)(mpr121_return.pushed >> 5) & 0x01,   (unsigned long)(mpr121_return.pushed >> 6) & 0x01,   (unsigned long)(mpr121_return.pushed >> 7) & 0x01,   (unsigned long)(mpr121_return.pushed >> 8) & 0x01,   (unsigned long)(mpr121_return.pushed >> 9) & 0x01,   (unsigned long)(mpr121_return.pushed >> 10) & 0x01,   (unsigned long)(mpr121_return.pushed >> 11) & 0x01);
#else
					GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"MPR121: Pushed   - K0=%u, K1=%u, K2=%u, K3=%u, K4=%u, K5=%u, K6=%u, K7=%u, K8=%u, K9=%u, K10=%u, K11=%u\r",     (unsigned long)mpr121_return.pushed & 0x01,   (unsigned long)(mpr121_return.pushed >> 1) & 0x01,   (unsigned long)(mpr121_return.pushed >> 2) & 0x01,   (unsigned long)(mpr121_return.pushed >> 3) & 0x01,   (unsigned long)(mpr121_return.pushed >> 4) & 0x01,   (unsigned long)(mpr121_return.pushed >> 5) & 0x01,   (unsigned long)(mpr121_return.pushed >> 6) & 0x01,   (unsigned long)(mpr121_return.pushed >> 7) & 0x01,   (unsigned long)(mpr121_return.pushed >> 8) & 0x01,   (unsigned long)(mpr121_return.pushed >> 9) & 0x01,   (unsigned long)(mpr121_return.pushed >> 10) & 0x01,   (unsigned long)(mpr121_return.pushed >> 11) & 0x01);
#endif
				if(mpr121_return.released)
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
					ListBox->Items[7]->Caption->setTextF((string)"MPR121: Released - K0=%u, K1=%u, K2=%u, K3=%u, K4=%u, K5=%u, K6=%u, K7=%u, K8=%u, K9=%u, K10=%u, K11=%u", (unsigned long)mpr121_return.released & 0x01, (unsigned long)(mpr121_return.released >> 1) & 0x01, (unsigned long)(mpr121_return.released >> 2) & 0x01, (unsigned long)(mpr121_return.released >> 3) & 0x01, (unsigned long)(mpr121_return.released >> 4) & 0x01, (unsigned long)(mpr121_return.released >> 5) & 0x01, (unsigned long)(mpr121_return.released >> 6) & 0x01, (unsigned long)(mpr121_return.released >> 7) & 0x01, (unsigned long)(mpr121_return.released >> 8) & 0x01, (unsigned long)(mpr121_return.released >> 9) & 0x01, (unsigned long)(mpr121_return.released >> 10) & 0x01, (unsigned long)(mpr121_return.released >> 11) & 0x01);
#else
					GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"MPR121: Released - K0=%u, K1=%u, K2=%u, K3=%u, K4=%u, K5=%u, K6=%u, K7=%u, K8=%u, K9=%u, K10=%u, K11=%u\r", (unsigned long)mpr121_return.released & 0x01, (unsigned long)(mpr121_return.released >> 1) & 0x01, (unsigned long)(mpr121_return.released >> 2) & 0x01, (unsigned long)(mpr121_return.released >> 3) & 0x01, (unsigned long)(mpr121_return.released >> 4) & 0x01, (unsigned long)(mpr121_return.released >> 5) & 0x01, (unsigned long)(mpr121_return.released >> 6) & 0x01, (unsigned long)(mpr121_return.released >> 7) & 0x01, (unsigned long)(mpr121_return.released >> 8) & 0x01, (unsigned long)(mpr121_return.released >> 9) & 0x01, (unsigned long)(mpr121_return.released >> 10) & 0x01, (unsigned long)(mpr121_return.released >> 11) & 0x01);
#endif
			}
		}
#endif
#ifdef _USE_L3GD20
		if(l3gd20_timer.tick())
		{
			float l3gd20_Xg = 0;
			float l3gd20_Yg = 0;
			float l3gd20_Zg = 0;
			if(!l3gd20_0.read(&l3gd20_Xg, &l3gd20_Yg, &l3gd20_Zg))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[8]->Caption->setTextF((string)"L3GD20: Giro:  Xg = %6.4f, Yg = %6.4f, Zg = %6.4f", l3gd20_Xg, l3gd20_Yg, l3gd20_Zg);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"L3GD20: Giro:  Xg = %6.4f, Yg = %6.4f, Zg = %6.4f\r", l3gd20_Xg, l3gd20_Yg, l3gd20_Zg);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[8]->Caption->setText((string)"L3GD20: error reading giroscope");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"L3GD20: error reading giroscope\r");
#endif
		}
#endif
#ifdef _USE_BMA250
		if(bma250_timer.tick())
		{
			signed short bma250_Xg = 0;
			signed short bma250_Yg = 0;
			signed short bma250_Zg = 0;
			if(!bma250_0.read(&bma250_Xg, &bma250_Yg, &bma250_Zg))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[9]->Caption->setTextF((string)"BMA250: Accel:  Xa = %6d, Ya = %6d, Za = %6d", bma250_Xg, bma250_Yg, bma250_Zg);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"BMA250: Accel:  Xa = %6d, Ya = %6d, Za = %6d\r", bma250_Xg, bma250_Yg, bma250_Zg);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[9]->Caption->setText((string)"BMA250: error reading accelerometer");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"BMA250: error reading accelerometer\r");
#endif
			float bma250_temp = 0.0;
			if(!bma250_0.read(&bma250_temp))
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[10]->Caption->setTextF((string)"BMA250: Temp:  %3.2f Gr Celsius", bma250_temp);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"BMA250: Temp:  %3.2f Gr Celsius\r", bma250_temp);
#endif
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[10]->Caption->setText((string)"BMA250: error reading temperature");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"BMA250: error reading temperature\r");
#endif
		}
#endif
#ifdef _USE_LSM9DS1
		if(lsm9ds1_timer.tick())
		{
			float lsm9ds1_Temp = 0.0;
			if(!lsm9ds1_0.readTemp(&lsm9ds1_Temp))
			{
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[11]->Caption->setTextF((string)"LSM9DS1: Temp:  %3.2f Gr Celsius", lsm9ds1_Temp);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"LSM9DS1: Temp:  %3.2f Gr Celsius\r", lsm9ds1_Temp);
#endif
			}
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[11]->Caption->setText((string)"LSM9DS1: error reading temperature");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"LSM9DS1: error reading temperature\r");
#endif
			signed short lsm9ds1_Xa = 0;
			signed short lsm9ds1_Ya = 0;
			signed short lsm9ds1_Za = 0;
			if(!lsm9ds1_0.readAccel(&lsm9ds1_Xa, &lsm9ds1_Ya, &lsm9ds1_Za))
			{
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[12]->Caption->setTextF((string)"LSM9DS1: Accel:  Xa = %6d, Ya = %6d, Za = %6d", lsm9ds1_Xa, lsm9ds1_Ya, lsm9ds1_Za);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"LSM9DS1: Accel:  Xa = %6d, Ya = %6d, Za = %6d\r", lsm9ds1_Xa, lsm9ds1_Ya, lsm9ds1_Za);
#endif
			}
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[12]->Caption->setText((string)"LSM9DS1: error reading accelerometer");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"LSM9DS1: error reading accelerometer\r");
#endif
			signed short lsm9ds1_Xg = 0;
			signed short lsm9ds1_Yg = 0;
			signed short lsm9ds1_Zg = 0;
			if(!lsm9ds1_0.readGyro(&lsm9ds1_Xg, &lsm9ds1_Yg, &lsm9ds1_Zg))
			{
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[13]->Caption->setTextF((string)"LSM9DS1: Gyro:  Xg = %6d, Yg = %6d, Zg = %6d", lsm9ds1_Xg, lsm9ds1_Yg, lsm9ds1_Zg);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"LSM9DS1: Gyro:  Xg = %6d, Yg = %6d, Zg = %6d\r", lsm9ds1_Xg, lsm9ds1_Yg, lsm9ds1_Zg);
#endif
			}
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[13]->Caption->setText((string)"LSM9DS1: error reading gyroscope");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"LSM9DS1: error reading gyroscope\r");
#endif
			signed short lsm9ds1_Xm = 0;
			signed short lsm9ds1_Ym = 0;
			signed short lsm9ds1_Zm = 0;
			if(!lsm9ds1_0.readMag(&lsm9ds1_Xm, &lsm9ds1_Ym, &lsm9ds1_Zm))
			{
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[14]->Caption->setTextF((string)"LSM9DS1: Mag:  Xm = %6d, Ym = %6d, Zm = %6d", lsm9ds1_Xm, lsm9ds1_Ym, lsm9ds1_Zm);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"LSM9DS1: Mag:  Xm = %6d, Ym = %6d, Zm = %6d\r", lsm9ds1_Xm, lsm9ds1_Ym, lsm9ds1_Zm);
#endif
			}
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[14]->Caption->setText((string)"LSM9DS1: error reading magnetometer");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"LSM9DS1: error reading magnetometer\r");
#endif
		}
#endif
#ifdef _USE_LPS25HB
		if(lps25hb_timer.tick())
		{
			float lps25hb_Temp = 0.0;
			if(!lps25hb_0.readTemp(&lps25hb_Temp))
			{
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[15]->Caption->setTextF((string)"LPS25HB: Temp:  %3.2f Gr Celsius", lps25hb_Temp);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"LPS25HB: Temp:  %3.2f Gr Celsius\r", lps25hb_Temp);
#endif
			}
			/*else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[15]->Caption->setText((string)"LPS25HB: error reading temperature");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"LPS25HB: error reading temperature\r");
#endif*/
			float lps25hb_Press = 0.0;
			if(!lps25hb_0.readPress(&lps25hb_Press))
			{
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[16]->Caption->setTextF((string)"LPS25HB: Press:  %4.2f", lps25hb_Press);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"LPS25HB: Press:  %4.2f\r", lps25hb_Press);
#endif
			}
			/*else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[16]->Caption->setText((string)"LPS25HB: error reading pressure");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"LPS25HB: error reading pressure\r");
#endif*/
		}
#endif
#ifdef _USE_MCP79410
		if(mcp79410_timer.tick())
		{
			GI::String *time = mcp79410_0.readTime(NULL);
			if(time && time->length)
			{
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[17]->Caption->setTextF((string)"MCP79410: Time:  %s", time->buff);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"MCP79410: Time:  %s\r", time->buff);
#endif
			}
			else
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[17]->Caption->setText((string)"MCP79410: error reading time");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"MCP79410: error reading time\r");
#endif
		}
#endif
#ifdef _USE_TCN75A// Non blocking procedure because a temperature conversion will eat from 30 to 240ms
		if(tcn75a_timer.tick())
		{
			if(tcn75a_0.startOneShot())
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[18]->Caption->setText((string)"TCN75A: error reading temperature");
#else
				GI::IO::write((char *)CONSOLE_UART_OUT, (string)"TCN75A: error reading temperature\r");
#endif
		}
		if(tcn75a_timer_ready.tick())
		{
			float tcn75a_Temp = 0.0;
			if(!tcn75a_0.readTemp(&tcn75a_Temp))
			{
#if (SHOW_SENSORS_RESULT_ON_SCREEN == 1)
				ListBox->Items[18]->Caption->setTextF((string)"TCN75A: Temp:  %3.3f Gr Celsius", tcn75a_Temp);
#else
				GI::IO::writeF((char *)CONSOLE_UART_OUT, (string)"TCN75A: Temp:  %3.3f Gr Celsius\r", tcn75a_Temp);
#endif
			}
		}
#endif
	}
}