using System;
using System.Runtime.InteropServices;

namespace AsyncCSharp
{

    /************************************************************
     * 
     * Interopt declarations for some of the commands for the
     * ScanPrint scanner. For more options and documentation on the
     * commands check the CyberSc.h file
     *
     ************************************************************/
     

    // Used with ScSCalibrate to control most of the scanners behaviour.
    // Please check the CyberSc.h header for more options and detailed descriptions.
    public enum ConfigSettings : int
    {
        CV_CAL_STOPSCAN = 0,  // Stop the scanner accepting paper.
        CV_CAL_SET_RESO = 4, // Set the scanner to BW or colour.
        CV_CAL_STARTSCAN = 6,  // Have the scanner accept paper.
        CV_CAL_SET_LIGHT = 8, // Enable the scanners internal light.
        CV_CAL_SET_DEV = 10, // Set the scanner type.
        CV_CAL_FORCESCAN = 11, // Start scanning as soon as paper is detected.
        CV_CAL_PAPER = 24 // Get the status of the paper detectors.
    }

    public enum Resolutions : int
    {
        EACRmFULL2 = 2,    //Full res in black and white.
        EACRmFULL256 = 0,  //Full res in greyscale
        FullColour = EACRmFULL256 | (3 << 5) //Full res in 24bit colour.
    }

    public enum DeviceCode
    {
        EDEV200A4_1728 = 1, 
    }

    public enum ErrorCodes : int
    {
        CV_SCANNER_NOT_CONNECTED = 0,
        CV_SCANNER_ERROR_CALIB = 1,
        CV_PRINTER_ERROR = 2,
        CV_PRINTER_OFFLINE = 3,
        CV_PRINTER_PAPER_ERROR = 4,
        CV_BARCODE = 5,
        CV_DEBUG = 6,
        CV_PRINTER_COVER_ERROR = 7,
        CV_PRINTER_HEAD_UNLOAD = 8,
        CV_PIPE_BROKEN = 9,
        CV_PRINTER_NEARLY_OUT = 10,
        CV_BARCODE_CHECKSUM_BAD	= 11,
        CV_OCR = 12,
        CV_SCAN_ABORTED = 13
    }

    public struct CyberImg
    {
        public IntPtr pIm;
        public IntPtr pCoef;
        public IntPtr pGamma;
        public IntPtr pTDens;
        public IntPtr pTSwap;
        //public IntPtr WinBITMAP;
        //public IntPtr WinHDC;
        public int lTime;
        public short wWidBy;
        public short wWid;
        public short wHei;
        public short wNoClr;
        public byte bPlanes;
        public byte bType;
        public byte bRet;
    }

    class CyberCs
    {

        
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void ScanDataCallback(ref CyberImg data);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void ErrorReportCallback(int error, int type);

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ScInit(ScanDataCallback fpFinScanning, 
            ErrorReportCallback fpError);

        [DllImport("CyberSc.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ScSCalibrate(ConfigSettings step, int param);


    }
}
