Author: Paul_R
Date: 2008-09-17 17:06:17 +0200 (Wed, 17 Sep 2008)
New Revision: 1881
Modified:
firmware/tuxup/win/trunk/main.c
Log:
* Added color and other "graphical" stuff in the terminal.
Now, the terminal output is the same as the linux version.
Modified: firmware/tuxup/win/trunk/main.c
===================================================================
--- firmware/tuxup/win/trunk/main.c 2008-09-17 14:29:46 UTC (rev 1880)
+++ firmware/tuxup/win/trunk/main.c 2008-09-17 15:06:17 UTC (rev 1881)
@@ -40,6 +40,14 @@
#define PATH_MAX 100
+static HANDLE hConsole;
+static CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
+static void display_FAIL(void);
+static void display_OK(void);
+static void display_FLASH(void);
+static void display_EEPROM(void);
+
+
/* Messages. */
static char const *msg_old_fuxusb =
"\nERROR: Your dongle firmware is too old to use this version of Tuxup"
@@ -272,19 +280,21 @@
}
log_notice("Version %d.%d.%d\n", version.ver_major, version.ver_minor,
version.ver_update);
+ display_FLASH();
if (pretend)
return E_TUXUP_NOERROR;
if (bootload(cpu_i2c_addr, FLASH, filename))
{
- printf(" OK \n");
+ display_OK();
+
return E_TUXUP_NOERROR;
}
else
{
- log_notice(" FAIL \n");
+ display_FAIL();
+ return E_TUXUP_PROGRAMMINGFAILED;
}
- return E_TUXUP_PROGRAMMINGFAILED;
}
static int prog_eeprom(uint8_t cpu_nbr, char const *filename)
@@ -316,19 +326,19 @@
log_error("Wrong CPU number specified for the eeprom.\n");
return E_TUXUP_BADPROGFILE;
}
+ display_EEPROM();
if (pretend)
return E_TUXUP_NOERROR;
if (bootload(cpu_i2c_addr, EEPROM, filename))
{
- printf(" OK\n");
+ display_OK();
return E_TUXUP_NOERROR;
}
else
{
- log_notice(" FAIL \n");
+ return E_TUXUP_PROGRAMMINGFAILED;
}
- return E_TUXUP_PROGRAMMINGFAILED;
}
static int prog_usb(char const *filename)
@@ -407,7 +417,7 @@
if (ret)
{
log_error("Erasing the USB CPU failed.\n");
- log_notice("\033[2C[\033[01;31mFAIL\033[00m]\n");
+ display_FAIL();
return E_TUXUP_PROGRAMMINGFAILED;
}
sprintf(command_str, "dfu-programmer at89c5130 flash %s %s", filename,
quiet ?
@@ -417,7 +427,7 @@
if (ret)
{
log_error("Flashing the USB CPU failed.\n");
- log_notice("\033[2C[\033[01;31mFAIL\033[00m]\n");
+ display_FAIL();
return E_TUXUP_PROGRAMMINGFAILED;
}
sprintf(command_str, "dfu-programmer at89c5130 configure HSB 0x7b %s",
quiet ?
@@ -427,7 +437,7 @@
if (ret)
{
log_error("Configuring the USB CPU failed.");
- log_notice("\033[2C[\033[01;31mFAIL\033[00m]\n");
+ display_FAIL();
return E_TUXUP_PROGRAMMINGFAILED;
}
@@ -435,8 +445,7 @@
: "");
log_info(command_str);
ret = system(command_str);
- log_notice("\033[2C[ \033[01;32mOK\033[00m ]\n");
-
+ display_OK();
fux_disconnect();
/* Windows needs more time than linux to enumerate the device */
/*sleep(5);*/
@@ -696,3 +705,56 @@
log_notice("Time elapsed: %2.0f seconds.", difftime(end_time,
start_time));
return ret;
}
+
+static void display_OK(void)
+{
+ hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+ GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
+ bufferInfo.dwCursorPosition.X += 2;
+ SetConsoleCursorPosition(hConsole, bufferInfo.dwCursorPosition);
+ printf("[");
+ GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
+ SetConsoleTextAttribute(hConsole, 2);
+ printf(" OK ");
+ SetConsoleTextAttribute(hConsole, bufferInfo.wAttributes);
+ printf("]\n");
+}
+
+static void display_FAIL(void)
+{
+ hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+ GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
+ bufferInfo.dwCursorPosition.X += 2;
+ SetConsoleCursorPosition(hConsole, bufferInfo.dwCursorPosition);
+ printf("[");
+ GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
+ SetConsoleTextAttribute(hConsole, 3);
+ printf("FAIL");
+ SetConsoleTextAttribute(hConsole, bufferInfo.wAttributes);
+ printf("]\n");
+}
+
+static void display_FLASH(void)
+{
+ printf("FLASH [");
+ hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+ GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
+ bufferInfo.dwCursorPosition.X += 61;
+ SetConsoleCursorPosition(hConsole, bufferInfo.dwCursorPosition);
+ bufferInfo.dwCursorPosition.X -= 61;
+ printf("]");
+ SetConsoleCursorPosition(hConsole, bufferInfo.dwCursorPosition);
+}
+
+
+static void display_EEPROM(void)
+{
+ printf("EEPROM [");
+ hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+ GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
+ bufferInfo.dwCursorPosition.X += 61;
+ SetConsoleCursorPosition(hConsole, bufferInfo.dwCursorPosition);
+ bufferInfo.dwCursorPosition.X -= 61;
+ printf("]");
+ SetConsoleCursorPosition(hConsole, bufferInfo.dwCursorPosition);
+}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn