Commits

Trammell Hudson committed fc173f1

add case folding, auto-off and power on

  • Participants
  • Parent commits 103e428

Comments (0)

Files changed (1)

 /**
  * \file 110 current loop interface for an ASR33
  *
+ * Can also turn off the teletype with a powerswitch tail on D0
+ * and a wakeup switch on D1.
+ *
  * ASR33 Wiring:   Teensy Wiring
  * TX+ == Green    Vcc
  * TX- == Red      PD2 (RXD1), tie to ground via 330 Ohm
 #include "usb_serial.h"
 #include "bits.h"
 
+#define CONFIG_FOLD_CASE
 
 // Send a string to the USB serial port.  The string must be in
 // flash memory, using PSTR
 	ddr(TTY_TX, 1);
 	out(TTY_TX, 0); // pull down
 
+// About 1 minute = 4000000
+#define POWER_OFF_DELAY (1000000)
+#define POWER_RELAY 0xD0
+#define POWER_SWITCH 0xD1
+
+	ddr(POWER_SWITCH, 0); // input
+	out(POWER_SWITCH, 1); // pull up
+
+	// be sure TX has reached a steady state
+	_delay_ms(100);
+	ddr(POWER_RELAY, 1); // output
+	out(POWER_RELAY, 1); // high
+	uint8_t power = 1;
+
+
 	// D2 is used for input (since it is also a UART)
 	// it has an external pull up resistor to +5v
 	ddr(TTY_RX, 0);
 	ddr(0xD6, 1); // LED
 
 	int status = 0;
+	uint32_t loop_count = 0;
 
 	while (1)
 	{
+		if (in(POWER_SWITCH) == 0)
+		{
+			loop_count = 0;
+			power = 1;
+			out(POWER_RELAY, 1);
+		}
+
+		if (loop_count == POWER_OFF_DELAY)
+		{
+			loop_count = 0;
+			out(POWER_RELAY, 0);
+			power = 0;
+		} else {
+			loop_count++;
+		}
+
 		int c = usb_serial_getchar();
 		if (c != -1)
 		{
+			loop_count = 0;
+			if (!power)
+			{
+				out(POWER_RELAY, 1);
+				power = 1;
+				_delay_ms(1000);
+			}
+
 			out(0xD6, 1);
 			tty_out(c);
 			out(0xD6, 0);
 			continue;
 
 		uint8_t ch = UDR1;
+#ifdef CONFIG_FOLD_CASE
+		if ('A' <= ch && ch <= 'Z')
+			ch += 'a' - 'A';
+#endif
+
+		loop_count = 0;
 		usb_serial_putchar(ch);
 #endif
 	}