从扫描仪按钮触发操作

行动位于/usr/local/etc/scanbd/scanbd.conf。我有 4 个按钮,分别是扫描复印电子邮件文件

默认配置文件不包括默认情况下的所有操作,你可能必须手动添加块。根据你的扫描仪型号,你可以拥有更少或更多的按钮。

对于每个操作,我们将为脚本选项设置自定义路径。

action scan {
    filter = "^scan.*"
    numerical-trigger {
            from-value = 1
            to-value   = 0
    }
    desc   = "Scan to file"
    # script must be an relative path starting from scriptdir (see above), 
    # or an absolute pathname. 
    # It must contain the path to the action script without arguments
    # Absolute path example: script = "/some/path/foo.script 
    script = "/home/pi/scan.sh"
}

不要忘记在 scanbd.conf 末尾注释任何其他默认操作:

# devices 
# each device can have actions and functions, you can disable not relevant devices
#include(scanner.d/avision.conf)
#include(scanner.d/fujitsu.conf)
#include(scanner.d/hp.conf)
#include(scanner.d/pixma.conf)
#include(scanner.d/snapscan.conf)
#include(scanner.d/canon.conf)

你现在可以创建自定义脚本来处理每个操作:

相对于/sys/class/leds/led0/trigger 的每条线用于控制 LED 以监控正在发生的事情。你可以做任何你想做的事,cat /sys/class/leds/led0/trigger 为你提供所有不同的灯光模式。

/home/pi/scan.sh

#!/bin/bash

# don't forget to create the folder
scan_dir=/home/pi/scanned-files
datetime=`date +%F_%H%M%S`

echo none >/sys/class/leds/led0/trigger

case $SCANBD_ACTION in
  scan)
    filename=file-$datetime
    logger -t "scanbd: $0" "$SCANBD_DEVICE $SCANBD_ACTION - scanning --resolution 150 --mode Color --depth 8 --format=tiff to $scan_dir/$filename.jpg"
    echo timer >/sys/class/leds/led0/trigger
    scanimage -d $SCANBD_DEVICE --resolution 150 --mode Color --depth 8 --format=tiff  --brightness 5 --contrast 20 | convert tiff:- -compress jpeg $scan_dir/$filename.pdf
    echo none >/sys/class/leds/led0/trigger
    logger -t "scanbd: $0" "Finished scanning"
    ;;
    
  email)
    logger -t "scanbd: $0" "Emailing $scan_dir/file-*pdf"
    echo heartbeat >/sys/class/leds/led0/trigger
    # here are the lines to send the file
    echo none >/sys/class/leds/led0/trigger

esac