Source

midi / iambic.c

Diff from to

File iambic.c

 	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);
-	}
-}
-
-