從掃描器按鈕觸發操作

行動位於/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