public static void On()
        {
            // Disable all  other buttons and set flag for DISPENSING
            BUTTON = false;
            DISPENSING = false;
            MExceptions mcode = MExceptions.none;

            // Select position and read bottle data
            int pos = position.Position;
            Bottle btl = new Bottle();
            btl.Read(pos);

            // select choice
            int choice = (position.Volume == Choice.large) ? 3 : (int)position.Volume;

            // send request if can dispense
            Ethernet.Request("sn=" + settings.sn.ToString() + "&event=221" + "&time=" + DateTime.Now.Ticks +
                    "&card=" + card.Id + "&bill=" + dispensing.Invoice.ToString() +
                    "&pos=" + pos.ToString() + "&choice=" + choice.ToString() + "&res=" + bottleData.Residue);


            string residue = bottleData.Residue;

            // clear bottle data (for sure)
            bottleData.Clear();

            if (DISPENSING)
            {
                // read calibration and disable flag for DISPENSING
                new Calibration().Read(pos);

                DISPENSING = false;

                // calculate dispensing time
                int onTime = httpData.dosevolume * calibData.timeToMl;

                if (onTime > 0 && onTime < 2000 && TagDetect.IsPresent())
                {
                    Buttons.Write(pos, Screen.blank);
                    Buttons.Write(pos, Cmd.Print, 10, 17, 0, 1, "   Dispensing");
                    if (card.Discount != 0) Buttons.Write(pos, Cmd.Print, 10, 33, 0, 1, "Discount " + card.Discount.ToString() + " %");

                    // starts ventil
                    Buttons.VentilsOnTime(pos, onTime, false);

                    // calculate pricing
                    int price = httpData.doseprice;
                    card.Credit -= price;
                    dispensing.Purchase += price;

                    // calculate wait od program and tarst sleep
                    onTime = ((onTime * 10) + 100);
                    Thread.Sleep(onTime);

                    // show wait please ... because of waiting UniqueId method done 
                    Buttons.Write(pos, Cmd.Refresh);
                    Buttons.Write(pos, Cmd.Print, 10, 17, 0, 1, "   Wait please");

                    // save new data to bottle
                    btl.Read(pos);
                    bottleData.residue -= httpData.dosevolume;
                    btl.Save(pos);
                }
                else
                {
                    if (onTime > 0 && onTime < 2000)
                    {
                        mcode = MExceptions.cardRemoved;
                    }
                    else
                    {
                        mcode = MExceptions.calibration;
                    }
                }

                // confirm unique ID of last request
                Ethernet.UniqueId();

                btl.Read(pos);
                // Send confirmDispense or error
                Ethernet.Request("sn=" + settings.sn.ToString() + "&event=201" + "&time=" + DateTime.Now.Ticks +
                        "&card=" + card.Id + "&bill=" + dispensing.Invoice.ToString() +
                        "&pos=" + pos.ToString() + "&choice=" + choice.ToString() + "&res=" + residue + (string)((mcode != MExceptions.none) ? "&mcode=" + mcode.ToString() : String.Empty));

                // confirm unique ID of last request
                Ethernet.UniqueId();

                // write new credit and purchase to alll buttons
                Buttons.CrePurch(ALL, (int)card.Credit, dispensing.Purchase);
                if (TagDetect.IsPresent())
                {
                    PosStates(Screen.credit, true);
                }
                else
                {
                    PosStates(Screen.prices);
                }

            }
            else if (!DISPENSING && httpData.exception != String.Empty)
            {
                int[] displayed = PosStates(Screen.credit, true, true);
                if(displayed[pos] == 1)
                {
                    Buttons.Write(pos, Screen.blank);
                }else
                {
                    Buttons.Write(pos, Cmd.Refresh);
                }

                ExceptionToDisp(httpData.errcode, pos);

                PosStates(Screen.credit, true);

                httpData.Clear();
            }

            BUTTON = true;
        }
Exemplo n.º 2
0
        public void Pointer(Choice choice, int pos, bool refresh = true)
        {
            for (int p = 1; p <= settings.positions; p++)
            {
                if (pos != ALL && pos != p)
                {
                    continue;
                }

                switch (posScreen[p])
                {
                    case MenuScreen.SELMENU:
                        if (p == settings.positions)
                        {
                            switch (choice)
                            {
                                case Choice.small:
                                case Choice.medium:
                                    ActualPosPointer(p, 2);
                                    Buttons.Write(p, Cmd.Print, 0, 1, 1, (posPointer[p] == 0) ? 0 : 1, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 17, 1, (posPointer[p] == 1) ? 0 : 1, " ");
                                    break;
                                case Choice.large:
                                    switch (posPointer[p])
                                    {
                                        case 0: // Service menu
                                            for (int i = 0; i <= settings.positions; i++)
                                            {
                                                posScreen[i] = MenuScreen.SERVICE;
                                                posPointer[i] = 0;
                                            }
                                            Buttons.Write(settings.positions, Cmd.Refresh);
                                            Pointer(Choice.none, ALL, false);
                                            break;
                                        case 1: // System menu                                        
                                            posPointer[p] = 0;
                                            posScreen[p] = MenuScreen.SYSTEM;
                                            Pointer(Choice.none, p);
                                            break;
                                    }
                                    break;
                                default:
                                    if (!refresh)
                                    {
                                        Buttons.Write(p, Screen.blank);
                                    }
                                    else
                                    {
                                        Buttons.Write(p, Cmd.Refresh);
                                    }

                                    Buttons.Write(p, Cmd.Print, 0, 1, 1, (posPointer[p] == 0) ? 0 : 1, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 17, 1, (posPointer[p] == 1) ? 0 : 1, " ");
                                    Buttons.Write(p, Cmd.Print, 10, 1, 0, 1, MenuSel[0]);
                                    Buttons.Write(p, Cmd.Print, 10, 17, 0, 1, MenuSel[1]);
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, "  list           ok");
                                    break;
                            }
                        }
                        break;

                    case MenuScreen.SERVICE: // service menu 
                        switch (choice)
                        {
                            case Choice.small: // list       
                                    ActualPosPointer(p, 3);
                                    Buttons.Write(p, Cmd.Print, 0, 1, 1, (posPointer[p] == 0) ? 0 : 1, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 17, 1, (posPointer[p] == 1) ? 0 : 1, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 33, 1, (posPointer[p] == 2) ? 0 : 1, " ");
                                break;
                            case Choice.medium:
                                if (card.Role == CardRole.Master)
                                {
                                    ResetMenu();
                                    MENUSHOWED = true;
                                    posScreen[settings.positions] = MenuScreen.SELMENU;
                                    Buttons.Write(ALL, Screen.service);
                                    Pointer(Choice.none, settings.positions, false);
                                }
                                break;
                            case Choice.large: // ok                               
                                switch (posPointer[p])
                                {
                                    case 0: // BTL change
                                        posScreen[p] = MenuScreen.BTL;
                                        break;
                                    case 1: // calibration
                                        posScreen[p] = MenuScreen.CAL;
                                        break;
                                    case 2: // cleaning              
                                        Cleaning[p] = STATE.Off;
                                        posScreen[p] = MenuScreen.CLEAN;
                                        break;
                                }
                                posPointer[p] = 0;
                                Pointer(Choice.none, p);
                                break;

                            default:
                                if (!refresh)
                                {
                                    Buttons.Write(p, Screen.blank);
                                }
                                else
                                {
                                    Buttons.Write(p, Cmd.Refresh);
                                }

                                Buttons.Write(p, Cmd.Print, 0, 1, 1, 0, " ");
                                Buttons.Write(p, Cmd.Print, 0, 17, 1, 1, " ");
                                Buttons.Write(p, Cmd.Print, 0, 33, 1, 1, " ");
                                Buttons.Write(p, Cmd.Print, 10, 1, 0, 1, main[0]);
                                Buttons.Write(p, Cmd.Print, 10, 17, 0, 1, main[1]);
                                Buttons.Write(p, Cmd.Print, 10, 33, 0, 1, main[2]);
                                if (card.Role == CardRole.Master)
                                {                                    
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, "  list   back    ok");
                                }
                                else
                                {
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, "  list            ok");
                                }
                                break;
                        }
                        break;

                    case MenuScreen.SYSTEM: // system menu
                        if (p == settings.positions)
                        {
                            switch (choice)
                            {
                                case Choice.small: // list
                                    ActualPosPointer(p, 3);
                                    Buttons.Write(p, Cmd.Print, 0, 1, 1, (posPointer[p] == 0) ? 0 : 1, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 17, 1, (posPointer[p] == 1) ? 0 : 1, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 33, 1, (posPointer[p] == 2) ? 0 : 1, " ");
                                    break;
                                case Choice.medium: // BACK TO SELECTION MENU
                                    posPointer[p] = 0;
                                    posScreen[p] = MenuScreen.SELMENU;
                                    Pointer(Choice.none, p);
                                    break;
                                case Choice.large: // ok    
                                    switch (posPointer[p])
                                    {
                                        case 0: // Date                                        
                                            posScreen[p] = MenuScreen.DATE;
                                            break;
                                        case 1: // time                    
                                            posScreen[p] = MenuScreen.TIME;
                                            break;
                                        case 2: // info 1                    
                                            posScreen[p] = MenuScreen.INFO1;
                                            break;
                                    }
                                    posPointer[p] = 0;
                                    Pointer(Choice.none, p);
                                    break;
                                default:
                                    Buttons.Write(p, Cmd.Refresh);
                                    Buttons.Write(p, Cmd.Print, 0, 1, 1, 0, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 17, 1, 1, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 33, 1, 1, " ");
                                    Buttons.Write(p, Cmd.Print, 10, 1, 0, 1, main[3]);
                                    Buttons.Write(p, Cmd.Print, 10, 17, 0, 1, main[4]);
                                    Buttons.Write(p, Cmd.Print, 10, 33, 0, 1, main[5]);
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, "  list   back   ok");
                                    break;
                            }
                        }
                        break;

                    case MenuScreen.BTL:
                        switch (choice)
                        {
                            case Choice.small:
                                ActualPosPointer(p, 2);
                                Buttons.Write(p, Cmd.Refresh);
                                Buttons.Write(p, Cmd.Print, 0, 1, 1, (posPointer[p] == 0) ? 0 : 1, " ");
                                Buttons.Write(p, Cmd.Print, 0, 17, 1, (posPointer[p] == 1) ? 0 : 1, " ");
                                Buttons.Write(p, Cmd.Print, 10, 1, 0, 1, bottleData.Residue + " -> " + bottleData.Volume + " ml");
                                Buttons.Write(p, Cmd.Print, 10, 17, 0, 1, bottleData.Residue + " -> ? ml");
                                if (posPointer[p] == 0)
                                {
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, " list  change  back");
                                }
                                else if (posPointer[p] == 1)
                                {
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, " list  select  back");
                                }
                                break;
                            case Choice.medium:
                                if (posPointer[p] == 0)
                                {
                                    Buttons.Write(p, Cmd.Refresh);
                                    Buttons.Write(pos, Cmd.Print, 10, 17, 0, 1, "   Wait please");
                                    BUTTON = false;

                                    Bottle btl = new Bottle();
                                    btl.Read(pos);
                                    bottleData.residue = bottleData.volume;
                                    bottleData.isclosed = 0;
                                    btl.Save(pos);

                                    new Log().WriteLogg("t=" + DateTime.Now.ToString("HH:mm:ss") + "&c=" + card.Id + "&ev=102" + "&b=" + pos + "&v=" + bottleData.Residue);
                                    
                                    bottleData.Clear();
                                                          
                                    Pointer(Choice.none, p);
                                    
                                    BUTTON = true;
                                }
                                else if (posPointer[p] == 1)
                                {
                                    posPointer[p] = 0;
                                    posScreen[p] = MenuScreen.BTLOWN;
                                    oresidue = bottleData.residue;
                                    bottleData.residue = bottleData.volume;
                                    Pointer(Choice.none, p);
                                }
                                break;
                            case Choice.large:
                                posPointer[p] = 0;
                                posScreen[p] = MenuScreen.SERVICE;
                                Pointer(Choice.none, p);
                                BTLMENU = 0;
                                bottleData.Clear();
                                break;
                            default:
                                if (BTLMENU == 0 || BTLMENU == p) // Není manipulováno s jinou pozicí v rámci bottleData nebo calibData lze manipulovat jenom s jednou lahví naráz
                                {
                                    BTLMENU = p;
                                    new Bottle().Read(p);

                                    Buttons.Write(p, Cmd.Refresh);
                                    Buttons.Write(p, Cmd.Print, 0, 1, 1, 0, " ");
                                    Buttons.Write(p, Cmd.Print, 0, 17, 1, 1, " ");
                                    Buttons.Write(p, Cmd.Print, 10, 1, 0, 1, bottleData.Residue + " -> " + bottleData.Volume + " ml");
                                    Buttons.Write(p, Cmd.Print, 10, 17, 0, 1, bottleData.Residue + " -> ? ml");
                                    if (posPointer[p] == 0)
                                    {
                                        Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, " list  change  back");
                                    }
                                    else if (posPointer[p] == 1)
                                    {
                                        Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, " list  select  back");
                                    }
                                }
                                else
                                {
                                    posScreen[p] = MenuScreen.SERVICE;
                                }
                                break;
                        }
                        break;

                    case MenuScreen.BTLOWN:
                        switch (choice)
                        {
                            case Choice.small:
                                if (submenu)
                                {
                                    // Plus
                                    bottleData.residue = bottleData.residue.AddTo(posPointer[p], 4, 1, bottleData.volume);
                                    writeResidue(p);
                                }
                                else
                                {
                                    // List
                                    AddToPointer(p, 4);
                                    writeResidue(p);
                                }
                                break;
                            case Choice.medium:
                                if (submenu)
                                {
                                    // Minus
                                    bottleData.residue = bottleData.residue.AddTo(posPointer[p], 4, -1, bottleData.volume);
                                    writeResidue(p);
                                }
                                else
                                {
                                    // To submenu
                                    submenu = true;
                                    writeResidue(p);
                                }
                                break;
                            case Choice.large:
                                if (submenu)
                                {
                                    submenu = false;
                                    writeResidue(p);
                                }
                                else
                                {
                                    Buttons.Write(p, Cmd.Refresh);
                                    Buttons.Write(p, Cmd.Print, 10, 17, 0, 1, "   Wait please");
                                    BUTTON = false;

                                    bottleData.isclosed = 0;
                                    new Bottle().Save(pos);

                                    new Log().WriteLogg("t=" + DateTime.Now.ToString("HH:mm:ss") + "&c=" + card.Id + "&ev=102" + "&b=" + pos + "&v=" + bottleData.Residue);

                                    bottleData.Clear();

                                    submenu = false;
                                        posScreen[p] = MenuScreen.BTL;
                                        posPointer[p] = 0;
                                        BTLMENU = 0;
                                        Pointer(Choice.none, p);
                                    
                                    BUTTON = true;
                                }
                                break;
                            default:
                                writeResidue(p);
                                break;
                        }
                        break;

                    case MenuScreen.CAL:
                        switch (choice)
                        {
                            case Choice.small:
                                if (DISPENDING)
                                {
                                    Buttons.VentilsOnTime(p, 10); // 10 sec výdej
                                    Thread.Sleep(10500);
                                    DISPENDING = false;
                                    submenu = false;
                                    writeCalib(p);
                                }
                                else
                                {
                                    if (submenu)
                                    {
                                        // Plus
                                        calibData.mlFor10sec = calibData.mlFor10sec.AddTo(posPointer[p], 3, 1, calibData.maxValue);
                                        writeCalib(p);
                                    }
                                    else
                                    {
                                        // List
                                        AddToPointer(p, 3);
                                        writeCalib(p);
                                    }
                                }
                                break;
                            case Choice.medium:
                                if (!DISPENDING)
                                {
                                    if (submenu)
                                    {
                                        // Minus
                                        calibData.mlFor10sec = calibData.mlFor10sec.AddTo(posPointer[p], 3, -1, calibData.maxValue);
                                        writeCalib(p);
                                    }
                                    else
                                    {
                                        // To submenu
                                        submenu = true;
                                        writeCalib(p);
                                    }
                                }
                                else
                                {
                                    DISPENDING = false;
                                    submenu = false;
                                    writeCalib(p);
                                }
                                break;
                            case Choice.large:
                                if (!DISPENDING)
                                {
                                    if (submenu)
                                    {
                                        submenu = false;
                                        writeCalib(p);
                                    }
                                    else
                                    {
                                        calibData.SetTime();
                                        new Calibration().Save(p);
                                        posPointer[p] = 0;
                                        posScreen[p] = MenuScreen.SERVICE;
                                        Pointer(Choice.none, p);
                                        BTLMENU = 0;
                                        submenu = false;

                                        new Log().WriteLogg("t=" + DateTime.Now.ToString("HH:mm:ss") + "&c=" + card.Id + "&ev=103" + "&b=" + p +
                                            "&ch=123&ms=" + calibData.timeToMl.ToString("F3"));

                                        calibData.Clear();
                                    }
                                }                               
                                break;
                            default:
                                if (BTLMENU == 0 || BTLMENU == p) // Není manipulováno s jinou pozicí v rámci bottleData nebo calibData lze manipulovat jenom s jednou lahví naráz
                                {
                                    BTLMENU = p;
                                    new Calibration().Read(p);
                                    DISPENDING = true;
                                    writeCalib(p);
                                }
                                else
                                {
                                    posScreen[p] = MenuScreen.SERVICE;
                                }
                                break;
                        }
                        break;

                    case MenuScreen.CLEAN:
                        switch (choice)
                        {
                            case Choice.small:
                                if (onVentils < 5)
                                {
                                    Buttons.VentilsOnOff(p, STATE.On);
                                    onVentils++;
                                    Cleaning[p] = STATE.On;
                                    Pointer(Choice.none, p);
                                }
                                break;
                            case Choice.medium:
                                break;
                            case Choice.large:
                                if (Cleaning[p] == STATE.On)
                                {
                                    Buttons.VentilsOnOff(p, STATE.Off);
                                    Cleaning[p] = STATE.Off;
                                    Pointer(Choice.none, p);
                                    onVentils--;
                                }
                                else
                                {
                                    posScreen[p] = MenuScreen.SERVICE;
                                    Pointer(Choice.none, p);
                                    Cleaning[p] = STATE.Off;
                                }
                                break;
                            default:
                                if (refresh)
                                {
                                    Buttons.Write(p, Cmd.Refresh);
                                }

                                if (Cleaning[p] == STATE.Off)
                                {
                                    Buttons.Write(p, Cmd.Print, 25, 1, 0, 1, "Press start");
                                    Buttons.Write(p, Cmd.Print, 15, 17, 0, 1, "for dispensing");                                    
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, "  start        back");
                                    
                                }
                                else
                                {
                                    Buttons.Write(p, Cmd.Print, 25, 1, 0, 1, "Press stop");
                                    Buttons.Write(p, Cmd.Print, 30, 17, 0, 1, "for end");
                                    Buttons.Write(p, Cmd.Print, 20, 33, 0, 1, "dispensing");
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, "----------- stop");
                                }
                                break;
                        }
                        break;

                    case MenuScreen.DATE: // date
                        if (p == settings.positions)
                        {
                            switch (choice)
                            {
                                case Choice.small:
                                    if (submenu)
                                    {
                                        // Plus
                                        SelectedDate = SelectedDate.AddTo(posPointer[p], 8, 1, 31122099);
                                        writeDate(false);
                                    }
                                    else
                                    {
                                        // List
                                        AddToPointer(settings.positions, 8, 3, 2);
                                        writeDate(true);
                                    }
                                    break;
                                case Choice.medium:
                                    if (submenu)
                                    {
                                        // Minus
                                        SelectedDate = SelectedDate.AddTo(posPointer[p], 8, -1, 31122099);
                                        writeDate(false);
                                    }
                                    else
                                    {
                                        // To submenu
                                        submenu = true;
                                        writeDate(false);
                                    }
                                    break;
                                case Choice.large:
                                    if (submenu)
                                    {
                                        // Back
                                        submenu = false;
                                        writeDate(false);
                                    }
                                    else
                                    {
                                        // Save
                                        submenu = false;
                                        SelectedTime = int.Parse(DateTime.Now.ToString("HHmmss"));
                                        if (saveDateTime())
                                        {
                                            posScreen[p] = MenuScreen.SELMENU;
                                            posPointer[p] = 1;
                                            Pointer(Choice.large, p);
                                        }
                                        else
                                        {
                                            Buttons.Write(p, Cmd.Refresh);
                                            Buttons.Write(p, Cmd.Print, 28, 17, 1, 1, "Wrong date");
                                            Thread.Sleep(2000);
                                            Pointer(Choice.none, p);
                                        }
                                    }
                                    break;
                                default:
                                    SelectedDate = int.Parse(DateTime.Now.ToString("ddMMyyyy"));
                                    datePointer = -1;
                                    writeDate(true);
                                    break;
                            }
                        }
                        break;
                    case MenuScreen.TIME: // time
                        if (p == settings.positions)
                        {
                            switch (choice)
                            {
                                case Choice.small:
                                    if (submenu)
                                    {
                                        // Plus
                                        SelectedTime = SelectedTime.AddTo(posPointer[pos], 6, 1, 235959);
                                        writeTime(false);
                                    }
                                    else
                                    {
                                        // List    
                                        AddToPointer(settings.positions, 6);
                                        writeTime(true);
                                    }
                                    break;
                                case Choice.medium:
                                    if (submenu)
                                    {
                                        // Minus
                                        SelectedTime = SelectedTime.AddTo(posPointer[pos], 6, -1, 235959);
                                        writeTime(false);
                                    }
                                    else
                                    {
                                        // To submenu
                                        submenu = true;
                                        writeTime(false);
                                    }
                                    break;
                                case Choice.large: // ok
                                    if (submenu)
                                    {
                                        submenu = false;
                                        writeTime(false);
                                    }
                                    else
                                    {
                                        submenu = false;
                                        SelectedDate = int.Parse(DateTime.Now.ToString("ddMMyyyy"));
                                        saveDateTime();
                                        posScreen[p] = MenuScreen.SELMENU;
                                        posPointer[p] = 1;
                                        Pointer(Choice.large, p);
                                    }
                                    break;
                                default:
                                    SelectedTime = int.Parse(DateTime.Now.ToString("HHmmss"));
                                    timePointer = -1;
                                    writeTime(true);
                                    break;
                            }
                        }
                        break;
                    case MenuScreen.INFO1: // info 1
                        if (p == settings.positions)
                        {
                            switch (choice)
                            {
                                case Choice.small:
                                    posPointer[p] = 0;
                                    posScreen[p] = MenuScreen.INFO2;
                                    Pointer(Choice.none, p);
                                    break;
                                case Choice.large:
                                    posScreen[p] = 0;
                                    posPointer[p] = 1;
                                    Pointer(Choice.large, p);
                                    break;
                                default:
                                    Buttons.Write(p, Cmd.Refresh);
                                    Buttons.Write(p, Cmd.Print, 0, 1, 0, 1, "Serial: " + settings.sn.ToString());
                                    Thread.Sleep(10);
                                    Buttons.Write(p, Cmd.Print, 0, 17, 0, 1, "Company: " + settings.company.ToString());
                                    Thread.Sleep(10);
                                    Buttons.Write(p, Cmd.Print, 0, 33, 0, 1, "Firmware: " + ver);
                                    Thread.Sleep(10);
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, "  next            ok");
                                    break;
                            }
                        }
                        break;
                    case MenuScreen.INFO2: // info 2
                        if (p == settings.positions)
                        {
                            switch (choice)
                            {
                                case Choice.small:
                                    posScreen[p] = MenuScreen.SYSTEM;
                                    posPointer[p] = 2;
                                    Pointer(Choice.large, p);
                                    break;
                                case Choice.large:
                                    posScreen[p] = MenuScreen.SELMENU;
                                    posPointer[p] = 1;
                                    Pointer(Choice.large, p);
                                    break;
                                default:
                                    Buttons.Write(p, Cmd.Refresh);
                                    Buttons.Write(p, Cmd.Print, 0, 1, 0, 1, "Reader: " + ReaderFw);
                                    Thread.Sleep(10);
                                    Buttons.Write(p, Cmd.Print, 0, 49, 0, 1, "  back            ok");
                                    break;
                            }
                        }
                        break;
                }
            }
        }
        public static void On()
        {
            // Disable all  other buttons
            BUTTON = false;

            // Select position and read bottle data
            int pos = position.Position;
            Bottle btl = new Bottle();
            btl.Read(pos);

            // Exception handle
            ExceptionCode exception = ExceptionCode.None;

            // select choice                        
            int dosevolume = bottleData.GetVolume(position.Volume);
            int price = bottleData.GetPrice(position.Volume);

            // read calibration and disable flag for DISPENSING
            new Calibration().Read(pos);
            
            // calculate dispensing time
            int onTime = dosevolume * calibData.timeToMl;

            if ((bottleData.residue - dosevolume) >= bottleData.minRes)
            {
                if (TagDetect.IsPresent())
                {
                    if (onTime > 0 && onTime < 2000)
                    {
                        if ((card.Credit - price) >= 0)
                        {
                            Buttons.Write(pos, Screen.blank);
                            Buttons.Write(pos, Cmd.Print, 10, 17, 0, 1, "   Dispensing");
                            if (card.Discount != 0) Buttons.Write(pos, Cmd.Print, 10, 33, 0, 1, "Discount " + card.Discount.ToString() + " %");

                            // starts ventil
                            Buttons.VentilsOnTime(pos, onTime, false);

                            // calculate pricing
                            card.Credit -= price;
                            dispensing.Purchase += price;

                            Reader.WriteCredit(card.Credit);

                            // calculate wait od program and tarst sleep
                            onTime = ((onTime * 10) + 100);
                            Thread.Sleep(onTime);

                            // show wait please ... because of waiting UniqueId method done 
                            Buttons.Write(pos, Cmd.Refresh);
                            Buttons.Write(pos, Cmd.Print, 10, 17, 0, 1, "   Wait please");

                            // save new data to bottle
                            btl.Read(pos);
                            bottleData.residue -= dosevolume;
                            btl.Save(pos);

                            bottleData.Clear();

                            // write new credit and purchase to alll buttons
                            Buttons.CrePurch(ALL, (int)card.Credit, dispensing.Purchase);
                            //Buttons.Write(ALL, Cmd.Refresh);


                            // zapsat do Logu
                            new Log().WriteLogg("t=" + DateTime.Now.ToString("HH:mm:ss") + "&c=" + card.Id + "&ev=101" +
                                "&b=" + pos + "&r=" + bottleData.Residue + "&ch=" + ((position.Volume != Choice.large) ? (int)position.Volume : 3).ToString() + "&p=" + price);
                                                        
                            if (TagDetect.IsPresent())
                            {
                                PosStates(Screen.credit, true);
                            }
                            else
                            {
                                PosStates(Screen.prices);
                            }
                        }else
                        {
                            exception = ExceptionCode.CreditInsufficient;
                        }
                    }
                    else
                    {
                        exception = ExceptionCode.WrongCalibration;
                    }
                }else
                {
                    exception = ExceptionCode.CardMissing;
                }
            }else
            {
                exception = ExceptionCode.ResidueLow;
            }

            if (exception > ExceptionCode.None)
            {
                int[] displayed = PosStates(Screen.credit, true, true);
                if (displayed[pos] == 1)
                {
                    Buttons.Write(pos, Screen.blank);
                }
                else
                {
                    Buttons.Write(pos, Cmd.Refresh);
                }

                ExceptionToDisp(exception, pos);

                PosStates(Screen.credit, true);
                
            }

            BUTTON = true;
        }
Exemplo n.º 4
0
        public static bool HW_Init()
        {
            // LEDS
            OutPorts = new OutputPort[6];

            OutPorts[(int)PINS.led_A] = new OutputPort(Pins.GPIO_PIN_A0, false); // Buttons RS485
            OutPorts[(int)PINS.led_B] = new OutputPort(Pins.GPIO_PIN_A1, false); // WatchDog
            OutPorts[(int)PINS.led_C] = new OutputPort(Pins.GPIO_PIN_A2, false); // Ethernet
            OutPorts[(int)PINS.led_D] = new OutputPort(Pins.GPIO_PIN_A3, false); // Reader
            OutPorts[(int)PINS.Out_D9] = new OutputPort(Pins.GPIO_PIN_D9, true); //
            OutPorts[(int)PINS.RxTx] = new OutputPort(Pins.GPIO_PIN_D4, false); //

            DebugPrint("PINS SETTINGS ...... inicialized");

            // RTC
            try
            {
                rtc = new DS1307();
                rtc.Synchronize();
                Program.start = DateTime.Now;
                DebugPrint("RTC ................ inicialized, date and time: " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"));
            }
            catch
            {
                DebugPrint("RTC ................ failed");
            }

            // WatchDog
            wdt = new WatchDog();

            // Reader
            Reader.Init();
            ReaderFw = Reader.GetFirmware();
            DebugPrint("RFID ............... " + ReaderFw);

            // SD card
            SecureDigital.TreeCheck();
            DebugPrint("SECURE DIGITAL ..... inicialized");

            // RS485
            if (Buttons.Init())
            {
                Buttons.Write(ALL, Screen.main);
                DebugPrint("RS485 .............. inicialized");
            }
            else
            {
                DebugPrint("RS485 .............. failed");
            }

            DebugPrint("LOADING SETTINGS ... waiting");

            // Read data from SD card
            new Settings().Read();

            DebugPrint("LOADING SETTINGS ... loaded");

            // Check for files
            for (int i = 1; i <= settings.positions; i++)
            {
                SecureDigital.FileExists(@"SD\bottles\", "btl_" + i.ToString());
                SecureDigital.FileExists(@"SD\calibration\", "cal_" + i.ToString());
            }

            // Check buttons present
            for (int i = 1; i <= settings.positions; i++)
            {
                string result = String.Empty;
                bool res = (Buttons.Write(i));
                allbuttons = (!allbuttons) ? false : res;
                result = (res) ? " respond" : " not respond";
                DebugPrint("Position " + i.ToString() + result);
            }

            DebugPrint("LOADING BOTTLES .... waiting");
            // Posílám dotaz nanastavení 5x
            for (int i = 1; i <= settings.positions; i++)
            {
                bottleData.Clear();
                Bottle btl = new Bottle();
                btl.Read(i);
                bottleData.position = i;
                Buttons.SendSettings();
                bottleData.Clear();
            }
            DebugPrint("LOADING BOTTLES .... loaded");

            return true;

        }