AutoPowerDown

Availability All terminals
Description The OPN-2500 and OPN-6000 have 4 power states: active, idle, sleep (power down) and power off. This function controls the sleep (power down) and power off time. Every time when the user presses a key, or when the communications port receives data, the count down for automatic power down is reset.
Syntax void AutoPowerDown(int command, unsigned long time);
Arguments
int command
The action that AutoPowerDown() must perform. One of the following values:
OFF Disables the AutoPowerDown feature. The time parameter is ignored and the previously configured time is lost.
ON Enables the AutoPowerDown() feature, and sets the 'on' time, specified by time in steps of 20 milliseconds. The 'on' time is the specified value * 20 milliseconds. E.g. time = 3000, means 20ms*3000 = 60 seconds.
ADP_RESET Resets the countdown for automatic power down. The time parameter is ignored. Note that the countdown for automatic power down is also reset when a key is pressed, or when data is received via the serial port.
ADP_NOW Causes the scanner to power down immediately. The time parameter is ignored.
ADP_SUSPEND Suspends the AutoPowerDown timer until this function is called again with ADP_RESUME, ON or NOW. The time parameter is ignored.
ADP_RESUME Resumes the AutoPowerDown timer, if it was suspended earlier by this function using ADP_SUSPEND. The time parameter is ignored.
APD_SHUTDOWN_ON Completely shutdown the device. The application will restart on pressing a key or connecting to USB. Note: be sure that there is no open file. Use the shutdown callback API call for this purpose.
APD_SHUTDOWN_OFF Completely shutdown disabled
unsigned long time
The time before the terminal powers down automatically.
Returns None
Remarks time is an unsigned long. The maximum value is 4294967295, approx. 2.5 years. The minimum value is theoretically zero, but the power down time is limited to 1 second.
The default power down and off times are different for the various terminals, and are shown below:
Device Sleep (Power down) Power off
OPN-2500 1 second 2 seconds
OPN-6000 2 seconds 10 minutes
When turning a device off after a certain time the power consumption is reduced to almost 0, which will greatly extend the battery life
Be very sure that when you use the APD_SHUTDOWN_ON, to never leave files open before the system shuts down.
To make sure that no files are left open, use the new API-function 'Application_ShutdownCallback' which installs a call back function, which is called before the device powers off (when idle or forced due to a low battery) and when the USB cable is connected in USB-MSD mode.
Example
#include <stdio.h>
#include "lib.h"

void main(void)
{
    AutoPowerDown(ON, 1*50); // 1 second
    AutoPowerDown(APD_SHUTDOWN_ON, 20*50); // 20 seconds

    if (IsColdBoot())
        Sound(TSTANDARD, VHIGH, SLOW, SMEDIUM, SHIGH, SLOW, SMEDIUM, SHIGH, 0); // 6 tones: Start-up beep
    else
        Sound(TSTANDARD, VHIGH, SHIGH, SMEDIUM, SHIGH, 0); // 3 tones: was powered off beep
        
    PoweredDown();   // Reset the sleep flag on start-up

    for(;;)
    {
        if(getchar() == TRIGGER_KEY)
        {
            if(PoweredDown())
                Sound(TSTANDARD, VHIGH, SMEDIUM, SHIGH, 0); // 2 tones: Device has slept
        }

        Idle(); // Important to lower power consumption while awake
    }
}