Phil Dibowitz wrote:
> You missed this email in response to your sample output

Phil, this updated patch (based again on CVS 0.20) should include 
your lost comments:

----------------------------------------------
Concordance 0.20+CVS
Copyright 2007 Kevin Timmerman and Phil Dibowitz
This software is distributed under the GPLv3.

Requesting Identity: 100%                 done
Received file contains 6 key names to be learned.

Key name : <0> :
[L]earn, [N]ext, [P]revious, [Q]uit (L)?

press corresponding key on original remote within 4 sec:
Learning IR signal:  100%                 done
[U]pload new code, [R]etry same key, [N]ext key, [Q]uit (U)?

Upload to website:   100%                 done

Key name : <1> :
[L]earn, [N]ext, [P]revious, [Q]uit (L)?n

Key name : <2> :
[L]earn, [N]ext, [P]revious, [Q]uit (L)?n

Key name : <3> :
[L]earn, [N]ext, [P]revious, [Q]uit (L)?q
Success!
------------------------------------------------

Index: concordance/concordance.1
===================================================================
RCS file: /cvsroot/concordance/concordance/concordance/concordance.1,v
retrieving revision 1.9
diff -u -3 -p -u -p -r1.9 concordance.1
--- concordance/concordance.1	15 Apr 2008 02:32:32 -0000	1.9
+++ concordance/concordance.1	6 Jul 2008 09:58:06 -0000
@@ -60,7 +60,7 @@ Get time from the remote
 Set the time on the remote
 .TP
 .B \-l, \-\-learn-ir <filename>
-Learn IR from other remotes. Use <filename>.
+Learn IR from other remotes. Use <filename>. Supports also files with multiple key names, i.e. when you checked multiple commands on the Logitech website. For each command, you have the choice to skip to the next or previous command or to learn the IR code from the original remote.
 .TP
 .B \-r, \-\-reset
 Reset (power-cycle) the remote control
@@ -90,6 +90,7 @@ Enable verbose output.
 .TP
 .B \-w, \-\-no\-web
 Do not attempt to talk to the website. This is useful for re-programming the remote from a saved file, or for debugging.
+.TP
 .SH BUGS
 None known at time of release, but check the website.
 .SH BUG REPORTS
Index: concordance/concordance.c
===================================================================
RCS file: /cvsroot/concordance/concordance/concordance/concordance.c,v
retrieving revision 1.32
diff -u -3 -p -u -p -r1.32 concordance.c
--- concordance/concordance.c	15 Apr 2008 06:17:02 -0000	1.32
+++ concordance/concordance.c	6 Jul 2008 09:58:07 -0000
@@ -37,6 +37,7 @@
 #define strcasecmp stricmp
 #define strncasecmp strnicmp
 #define sleep(x) Sleep((x) * 1000)
+#define strdup _strdup
 
 /*
  * Windows, in it's infinite awesomeness doesn't include POSIX things
@@ -52,6 +53,15 @@ char* basename(char* file_name)
 
 HANDLE con;
 
+/* Windows does not need this - make it empty */
+int set_canon(int flag)
+{
+	return(1);
+}
+
+#define read_key _getch
+#define USE_DEFAULT '\r'
+
 #else
 /* NON-Windows */
 
@@ -59,6 +69,23 @@ HANDLE con;
 #include <strings.h>
 #include <libgen.h>
 #include <unistd.h>
+#include <termios.h>
+
+int set_canon(int flag)
+{
+	struct termios t;
+
+	tcgetattr(0, &t);
+	if( flag) {
+		t.c_lflag |= ICANON;
+	} else {
+		t.c_lflag &= ~ICANON;
+	}
+	tcsetattr(0, TCSANOW, &t); 
+	return(1);
+}
+#define read_key getchar
+#define USE_DEFAULT '\n'
 
 #endif
 
@@ -140,6 +167,197 @@ void cb_print_percent_status(uint32_t co
 	fflush(stdout);
 }
 
+void _printburst(uint32_t length)
+{
+	if (length < 250) {
+		printf("|");
+	} else if (length < 1000) {
+		printf("#");
+	} else {
+		printf("##");
+	}
+}
+
+void _printspace(uint32_t length)
+{
+	if (length < 250) {
+		printf(".");
+	} else if (length < 1000) {
+		printf("_");
+	} else if (length < 10000) {
+		printf("__");
+	} else {
+		printf("\n");
+	}
+}
+
+void _dump_new_code(uint32_t carrier_clock, uint32_t *ir_signal, 
+	uint32_t ir_signal_length, struct options_t *options)
+{
+	uint32_t index;
+	printf("\nASCII-graph of received IR signal:\n");
+	for (index=0; index < ir_signal_length; index += 2){
+		_printburst(ir_signal[index]);
+		_printspace(ir_signal[index+1]);
+	}
+	printf("\n");
+	printf("Carrier clock          : %u Hz\n", carrier_clock);
+	printf("Total mark/space pairs : %u\n\n", ir_signal_length/2);
+#ifdef _DEBUG
+	/*
+		* full dump of new IR signal:
+		*/
+	for (index=0; index < ir_signal_length; index += 2){
+		printf("\tP:%6u\tS:%6u\n", ir_signal[index],
+			ir_signal[index+1]);
+	}
+#endif
+}
+
+char _get_cmd(char *prompt, char *allowed, char def) {
+	char result = 0;
+	char got_key;
+	uint32_t index;
+	set_canon(0);
+	while ( result == 0 ) {
+		printf("%s (%c)?", prompt, def);
+		got_key = read_key();
+		printf("\n");
+		if (got_key == USE_DEFAULT) {
+			result = def;
+		} else {
+			for (index = 0; index < strlen(allowed); index++) {
+				if (allowed[index] == got_key) {
+					result = got_key;
+					break;
+				}
+			}
+		}
+	}
+	set_canon(1);
+	return result;
+}	
+
+int _learn_ir_commands(uint8_t *data, uint32_t size, struct options_t *options)
+{
+	int err = 0;
+	uint32_t carrier_clock = 0;
+	uint32_t *ir_signal = NULL;
+	uint32_t ir_signal_length = 0;
+	uint32_t index = 0;
+	char **key_names;
+	uint32_t key_names_length = 0;
+	char *post_string = NULL;
+	char user_cmd;
+
+	err = get_key_names(data, size, &key_names, &key_names_length);
+	if ((err != 0) || (key_names_length == 0)) { return err; }
+	
+	printf("Received file contains %u key names to be learned.\n",
+		key_names_length);
+	
+	while (1) {
+		if (index >= key_names_length) {
+			user_cmd = _get_cmd(
+				"No more keys : [P]revious, [Q]uit",
+				"PpQq", 'Q');
+		} else {
+			printf("\nKey name : <%s> : \n", key_names[index]);
+			user_cmd = _get_cmd(
+				"[L]earn, [N]ext, [P]revious, [Q]uit",
+				"LlHhNnPpQq", 'L');
+		}				
+		index++;
+		err = 1; /* have no code yet */
+		switch (user_cmd) {
+			case 'L':
+			case 'l': /* learn from remote: */
+				printf("press corresponding ");
+				printf("key on original remote within 4 sec:\n");
+				printf("Learning IR signal:  ");
+				cb_print_percent_status(0, 0, 1, NULL);
+				err = learn_from_remote(&carrier_clock, &ir_signal,
+					&ir_signal_length);
+				if (err == 0) {
+					cb_print_percent_status(1, 1, 1, NULL);
+					printf("       done\n");
+				} else {
+					printf("       failed, try again!\n");
+					index--;
+				}
+				break;
+			case 'P':
+			case 'p':
+				if (index > 1) {
+					index -= 2;
+				} else {
+					printf("First key already reached!\n");
+					index = 0;
+				}
+				break;
+			default:
+				break;
+		}				
+		if ( err == 0 ) {   /* have new IR code: */
+			if ((*options).verbose) {
+				_dump_new_code(carrier_clock, 
+					ir_signal, ir_signal_length, options);
+			}
+			err = encode_for_posting(carrier_clock, ir_signal,
+					ir_signal_length, &post_string);
+			
+			if ( err == 0 ) {
+#ifdef _DEBUG				
+				if ((*options).verbose) {
+					printf("%s\n\n", post_string );
+				}
+#endif
+				if (!(*options).noweb) {
+					user_cmd = _get_cmd(
+						"[U]pload new code, [R]etry same key, [N]ext key, [Q]uit",
+						"UuRrNnQq", 'U');
+				} else {
+					user_cmd = _get_cmd(
+						"[R]etry same key, [N]ext key, [Q]uit",
+						"RrNnQq", 'N');
+				}
+				switch (user_cmd) {
+					case 'U':
+					case 'u':
+						printf("Upload to website:   ");
+						cb_print_percent_status(0, 0, 1, NULL);
+						err = post_new_code(data, size, 
+							key_names[index], post_string);
+						if ( err == 0 ) {
+							cb_print_percent_status(1, 1, 1, NULL);
+							printf("       done\n");
+						} else {
+							printf("       failed\n");
+						}
+						break;
+					case 'R':
+					case 'r':
+						index--;
+						break;
+					default:
+						break;
+				}
+				delete_encoded_signal(post_string);    /* done, free memory */
+			} else {
+				printf("??? Failed to convert - bad code? try again!\n");
+				index--;
+			}
+			delete_ir_signal(ir_signal);    /* done, free memory */
+		}
+				
+		if (user_cmd == 'Q' || user_cmd == 'q') {
+			break;
+		}
+	}
+	delete_key_names(key_names, key_names_length); /* done, free memory */
+	return 0; /* considering always kind of success */
+}
+
 /*
  * Start helper functions
  */
@@ -1032,7 +1250,7 @@ int main(int argc, char *argv[])
 			break;
 
 		case MODE_LEARN_IR:
-			err = learn_ir_commands(data, size, !options.noweb);
+			err = _learn_ir_commands(data, size, &options);
 			break;
 
 		case MODE_GET_TIME:
Index: concordance/concordance.1
===================================================================
+Learn IR from other remotes. Use <filename>. Supports also files with multiple 
key names, i.e. when you checked multiple commands on the Logitech website. 
For each command, you have the choice to skip to the next or previous command 
or to learn the IR code from the original remote.

> added remark about changed IR learning

Index: concordance.c
===================================================================
+#define strdup _strdup
 
> fixed VC++ warning

+/* Windows does not need this - make it empty */
+int set_canon(int flag)

> set canon(0/1) changes mode for stdin in LINUX to pass single
> keystrokes, so you just have to press a letter key (without <RET>),
> in the menus to start an action. In Windows, you can use getch
> instead, and set_canon doesn't need to do anything.

+#define USE_DEFAULT '\r'

> Pressing the <RET> key seems to give '\r' in Windows, and '\n' in LINUX.

+void _dump_new_code(uint32_t carrier_clock, uint32_t *ir_signal, 
+	uint32_t ir_signal_length, struct options_t *options)

> 'plot' received IR code as ASCII-art to identify bad IR signals

+int _learn_ir_commands(uint8_t *data, uint32_t size, struct options_t *options)

> adapt to changed libconcord API; added code to navigate through list
> with multiple keys to be learned and to accept/reject learned IR signal.

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
concordance-devel mailing list
concordance-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/concordance-devel

Reply via email to