package com.seuic.scan;

import com.seuic.scanner.Scanner;
import com.seuic.scanner.ScannerKey;

public class SeuicScanKeyEventRunnable implements Runnable {
	private Scanner mScanner;
	public boolean isrun = true;

	// 需要调用ScannerKey去实现扫描按键控制扫描灯的亮和灭（需要在子线程中执行）
	public SeuicScanKeyEventRunnable(Scanner mScanner) {
		this.mScanner = mScanner;
	}

	public void run() {
		int ret1 = ScannerKey.open();
		if (ret1 > -1) {
			while (isrun) {
				int ret = ScannerKey.getKeyEvent();
				if (ret > -1) {
					// while (isrun) {
					// try {
					// mScanner.startScan();
					// Thread.sleep(300);
					// mScanner.stopScan();
					// Thread.sleep(300);
					// } catch (InterruptedException e) {
					//
					// }
					// }
					switch (ret) {
					case ScannerKey.KEY_DOWN:
						mScanner.startScan();
						break;
					case ScannerKey.KEY_UP:
						mScanner.stopScan();
						break;
					}
				}
			}
		}
	}

}
