Advertisements

Kenmore 158: Power Switch Timing

The crash test dummy sewing machine now has a cheerful red momentary pushbutton in the same spot the original machine sported a 120 VAC push-on/push-off power switch:

Kenmore 158 - Digital Power Switch

Kenmore 158 – Digital Power Switch

It’s held in place by a dab of epoxy on the bottom. The threads aren’t quite long enough to engage the ring, so another dab of epoxy holds that in place. In the unlikely event I must replace the button, I’ll deploy a punch and hammer it out from the top; the slick paint on the sides of the straight-sided hole doesn’t provide much griptivity.

The button connects in parallel with the GX270’s front-panel button and the one on the Low Voltage Interface Board, so it operates exactly the same way. My original code didn’t include a delay before turning the power off, which meant that brushing the switch while doing something else would kill the power.

This is not to be tolerated…

You (well, I) must now hold the button down for one second to turn the power off. Releasing it before the deadline has no effect, other than blinking the green power LED on the front panel a few times.

The routine maintains a timer that allows it to yield control to the mainline code, rather than depend on a blocking timer that would screw up anything else that’s in progress:

//------------------
// Handle shutdown timing when power button closes
// Called every time around the main loop

void TestShutdown(void) {
	
	if (LOW == digitalRead(PIN_BUTTON_SENSE)) {			// power button pressed?
		if (ShutdownPending) {
			if (1000ul < (millis() - ShutdownPending)) {
				printf("Power going off!\r\n");
				digitalWrite(PIN_ENABLE_AC,LOW);
				digitalWrite(PIN_ENABLE_ATX,LOW);
				while(true) {
					delay(20);
					TogglePin(PIN_PWR_G);				// show we have shut down
				}
			}
		}
		else {
			ShutdownPending = millis();					// record button press time
			printf("Shutdown pending...\r\n");
		}
	}
	else {
		if (ShutdownPending) {
			ShutdownPending = 0ul;						// glitch or button released
			printf("Shutdown cancelled\r\n");
		}
	}
}

The normal Arduino bootloader imposes a similar delay while turning the power on, which means that you can’t accidentally light the machine up by bumping the switch. All in all, it’s much more user-friendly this way.

Advertisements

, ,