Trammell Hudson avatar Trammell Hudson committed 516db66

Improve delay during inter-char space

Comments (0)

Files changed (1)

 	TCCR0B = 0x04; // Clk/256
 	led_on();
 	print("!!!\n");
-	_delay_ms(20);
+	_delay_ms(40);
 	led_off();
 
 	// Restore the old timer
 	// This is pretty close to 16 ticks/ms.  The output compare
 	// sets OCF flag on match
 	TCCR1B = 5; // clk/1024
-	const uint8_t cpm = 10;
+	const uint8_t cpm = 15;
 	const uint16_t dit_time = (1600 / cpm) * 16;
 	const uint16_t button_threshold = 16384; // dit_time * 1024 * 4;
 
 		// Neither key is held down and the single space time
 		// has elapsed (since wait_delay is blocking).
 
-		// \todo Delay one more cycle to be sure
-		dit_count = dah_count = 0;
-		busy_wait(dit_time);
-		if (dah_count > button_threshold)
-			goto start_dah_bit;
-		if (dit_count > button_threshold)
-			goto start_dit_bit;
+		// Delay one more cycle to be sure, abort the delay
+		// as soon as a button is pressed
+		OCR1A = TCNT1 + dit_time * 2;
+		TIFR1 |= (1 << OCF1A);
+
+		while (bit_is_clear(TIFR1, OCF1A))
+		{
+			const uint8_t port = PINB;
+			if (is_dah(port))
+				goto start_dah_bit;
+			if (is_dit(port))
+				goto start_dit_bit;
+		}
 
 		// Timeout has passed; check to see if the
 		// value exist in the map
 		value = 1;
 	}
 }
-
-// This interrupt routine is run approx 61 times per second.
-// A very simple inactivity timeout is implemented, where we
-// will send a space character and print a message to the
-// hid_listen debug message window.
-ISR(TIMER0_OVF_vect)
-{
-	idle_count++;
-	if (idle_count > 61 * 8) {
-		idle_count = 0;
-		print("Timer Event :)\n");
-		usb_keyboard_press(KEY_SPACE, 0);
-	}
-}
-
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.