Пример #1
0
        private void MakeVal()
        {
            int xxx = 0, yyy = 0;

            uint Len_L, Len_R;
            int  delta_move, rmd;

            int  pressure;
            int  SMPenFlag, SMPenState;
            int  PenStatus;
            bool bClicked     = false;
            bool bFuncClicked = false;

            for (int i = 0; i < 2; i++)
            {
                pressure = 100;
                if (i == 0)
                {
                    Len_R        = MAKEWORD(rxdata[1], (byte)(0x3F & rxdata[2]));
                    Len_L        = MAKEWORD(rxdata[3], (byte)(0x3F & rxdata[4]));
                    SMPenFlag    = rxdata[5];
                    SMPenState   = rxdata[6];
                    bFuncClicked = ((0x02 & rxdata[5]) == 0x02) ? true : false;
                }
                else
                {
                    Len_R        = MAKEWORD(rxdata[7], (byte)(0x3F & rxdata[8]));
                    Len_L        = MAKEWORD(rxdata[9], (byte)(0x3F & rxdata[10]));
                    SMPenFlag    = rxdata[11];
                    SMPenState   = rxdata[12];
                    bFuncClicked = ((0x02 & rxdata[11]) == 0x02) ? true : false;
                }

                switch (SMPenFlag)
                {
                case 0x81:
                case 0x82:
                    bClicked = true;
                    break;

                case 0x80:
                    bClicked = false;
                    break;

                default:
                    continue;
                }


                bool forceUp = false;

                pen_rec.Station_Position = StationPosition;


                MakeXYFromLengh(Len_R, Len_L, ref xxx, ref yyy);


                if (forceUp)
                {
                    xxx        = xxx0;
                    yyy        = yyy0;
                    delta_move = delta_move_b;
                }

                if (bClicked)
                {       // click
                    if (bClickedSave == true)
                    {
                        PenStatus = PEN_MOVE;
                    }
                    else
                    {       //first down
                        bClickedSave = true;
                        PenStatus    = PEN_DOWN;
                        xxx0         = xxx;
                        yyy0         = yyy;
                        Len_Lb       = Len_L;
                        Len_Rb       = Len_R;
                        delta_move_b = 0;
                    }
                }
                else
                {     // pen up
                    if (bClickedSave == true)
                    { // pen up
                        bClickedSave = false;
                        PenStatus    = PEN_UP;
                    }
                    else
                    {       // hovering
                        PenStatus = PEN_HOVER;
                    }
                }
                if (Len_L == Len_Lb && Len_R == Len_Rb && bClicked == bClickedSave &&
                    PenStatus != PEN_DOWN)
                {
                    continue;
                }

#if true
                delta_move = GetLengthBetweenPoints(xxx, yyy, xxx0, yyy0);

                ///////
                // ---------------------------------------
                //  error correction
                // ---------------------------------------
                rmd = Math.Abs(delta_move - delta_move_b);

                if (rmd > RMD_CONST)
                {
                    rmdCnt++;
                    xxx        = xxx0;
                    yyy        = yyy0;
                    delta_move = delta_move_b;
                    ConsoleWriteLine("RMD ERROR rmd = {0}", rmd);
                    continue;
                }
                else
                {
                    rmdCnt = 0;
                }

                delta_move_b = delta_move;
#endif
                xxx = (xxx + xxx + xxx0) / 3;
                yyy = (yyy + yyy + yyy0) / 3;

                //---------------------------------------
                // Data shift
                //---------------------------------------

                xxx0   = xxx;
                yyy0   = yyy;
                Len_Rb = Len_R;
                Len_Lb = Len_L;


                //TRACE("X = %d, Y = %d, P = %d \n",pen_rec.X,pen_rec.Y, pen_rec.P);

                /////               >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                double sx = 0, sy = 0;
                transPoint(xxx, yyy, ref sx, ref sy);
#if true
                switch (StationPosition)
                {
                case DIRECTION_BOTTOM:
                    sy = XY_RANGE - sy;
                    sx = XY_RANGE - sx;
                    break;

                case DIRECTION_LEFT:
                {
                    double tempVV = sy;
                    sy = XY_RANGE - sx;
                    sx = tempVV;
                }
                break;

                case DIRECTION_RIGHT:
                {
                    double tempVV = sy;
                    sy = sx;
                    sx = XY_RANGE - tempVV;
                }
                break;
                }
#endif
//                ConsoleWriteLine("Trans Point xxx={0} yyy={1} sx={2} sy={3} status={4}", xxx,yyy,sx,sy,PenStatus);


                pen_rec.X         = xxx;
                pen_rec.Y         = yyy;
                pen_rec.FUNC      = bFuncClicked ? 1 : 0;
                pen_rec.P         = pressure;
                pen_rec.T         = (short)rxdata[13]; // temperature
                pen_rec.ModelCode = m_nModelCode;
                pen_rec.PenStatus = PenStatus;
                pen_rec.PenTiming = SMPenState;
                pen_rec.TX        = (float)sx;
                pen_rec.TY        = (float)sy;
                if (firePenDataEvent != null)
                {
                    PenDataEvent ev = new PenDataEvent();
                    ev.pen_rec = pen_rec;
                    firePenDataEvent(this, ev);
                    ev = null;
                }
            }   //end for
        }
Пример #2
0
        public async void OnPenDataHandlerAsync(object sender, PenDataEvent e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                      () =>
            {
                switch (e.pen_rec.PenStatus)
                {
                case eBeamSDKLib.PEN_DOWN:

                    break;

                case eBeamSDKLib.PEN_MOVE:

                    break;

                case eBeamSDKLib.PEN_UP:
                    m_calStatus++;
                    switch (m_calStatus)
                    {
                    case 0:               ///
                        break;

                    case 1:               ///
                        calNumber1Do.Visibility    = Visibility.Collapsed;
                        calNumber1Check.Visibility = Visibility.Visible;
                        calNumber1Text.Visibility  = Visibility.Collapsed;


                        calNumber2ColorPre.Visibility = Visibility.Collapsed;
                        calNumber2ColorDo.Visibility  = Visibility.Visible;
                        calNumber2Do.Visibility       = Visibility.Visible;
                        calNumber2Check.Visibility    = Visibility.Collapsed;
                        calNumber2Text.Visibility     = Visibility.Visible;

                        m_CalPoint[0].X = e.pen_rec.X - CALIBRATION_MARGIN;
                        m_CalPoint[0].Y = e.pen_rec.Y - CALIBRATION_MARGIN;

                        break;

                    case 2:
                        calNumber2ColorPre.Visibility = Visibility.Collapsed;
                        calNumber2ColorDo.Visibility  = Visibility.Visible;
                        calNumber2Do.Visibility       = Visibility.Collapsed;
                        calNumber2Check.Visibility    = Visibility.Visible;
                        calNumber2Text.Visibility     = Visibility.Collapsed;

                        calNumber3ColorPre.Visibility = Visibility.Collapsed;
                        calNumber3ColorDo.Visibility  = Visibility.Visible;
                        calNumber3Do.Visibility       = Visibility.Visible;
                        calNumber3Check.Visibility    = Visibility.Collapsed;
                        calNumber3Text.Visibility     = Visibility.Visible;

                        m_CalPoint[1].X = e.pen_rec.X - CALIBRATION_MARGIN;
                        m_CalPoint[1].Y = e.pen_rec.Y + CALIBRATION_MARGIN;
                        break;

                    case 3:
                        calNumber3ColorPre.Visibility = Visibility.Collapsed;
                        calNumber3ColorDo.Visibility  = Visibility.Visible;
                        calNumber3Do.Visibility       = Visibility.Collapsed;
                        calNumber3Check.Visibility    = Visibility.Visible;
                        //calNumber3Text.Visibility = Visibility.Collapsed;
                        calNumber3Text.Text = "Calibration is Finished.";
                        m_CalPoint[2].X     = e.pen_rec.X + CALIBRATION_MARGIN;
                        m_CalPoint[2].Y     = e.pen_rec.Y + CALIBRATION_MARGIN;

                        m_CalPoint[3].X = m_CalPoint[2].X;
                        m_CalPoint[3].Y = m_CalPoint[0].Y;
                        sdkLib.SaveCalibrationToDevice(m_CalPoint[0].X, m_CalPoint[0].Y,
                                                       m_CalPoint[1].X, m_CalPoint[1].Y,
                                                       m_CalPoint[2].X, m_CalPoint[2].Y,
                                                       m_CalPoint[3].X, m_CalPoint[3].Y);

                        break;
                    }

                    break;

                case eBeamSDKLib.PEN_HOVER:
                    break;
                }
            });
        }
Пример #3
0
        public async void OnPenDataHandlerAsync(object sender, PenDataEvent e)
        {
            var newValue = string.Format("Orignal (Virtual coordinates used by device.) : X={0} Y={1}  \r\n", e.pen_rec.X, e.pen_rec.Y);

            newValue += string.Format("Calibrated (Calibrated coordinates 0~{2}) : X={0} Y={1} \r\n", e.pen_rec.TX, e.pen_rec.TY, (int)eBeamSDKLib.XY_RANGE);
            newValue += string.Format("Pentip (1:Down 2:Move 3:Up 4:Hover) : {0} ", e.pen_rec.PenStatus);
            newValue += string.Format("Func Button(1:Clicked 2:not Clicked) : {0} \r\n", e.pen_rec.FUNC);

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                      () =>
            {
                if (m_bMouseMode)
                {
                    double rx     = 1;  // Windows.Graphics.Display.DisplayInformation.GetForCurrentView().ScreenWidthInRawPixels / (double)eBeamSDKLib.XY_RANGE;
                    double ry     = 1;  // Windows.Graphics.Display.DisplayInformation.GetForCurrentView().ScreenHeightInRawPixels / (double)eBeamSDKLib.XY_RANGE;
                    double localX = e.pen_rec.TX *rx;
                    double localY = e.pen_rec.TY *ry;
                    newValue     += string.Format("mouse X={0} Y={1} (Coordinates fitting screen)\r\n", localX, localY);
                    CharacteristicLatestValue.Text = newValue;
                    switch (e.pen_rec.PenStatus)
                    {
                    case eBeamSDKLib.PEN_DOWN:
                        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, (uint)localX, (uint)localY, 0, 0);
                        break;

                    case eBeamSDKLib.PEN_MOVE:
                        mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, (uint)localX, (uint)localY, 0, 0);
                        break;

                    case eBeamSDKLib.PEN_UP:
                        mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, (uint)localX, (uint)localY, 0, 0);
                        break;

                    case eBeamSDKLib.PEN_HOVER:
                        mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, (uint)localX, (uint)localY, 0, 0);
                        break;
                    }
                }
                else
                {
                    double rx     = drawCanvas.Width / (double)eBeamSDKLib.XY_RANGE;
                    double ry     = drawCanvas.Height / (double)eBeamSDKLib.XY_RANGE;
                    double localX = e.pen_rec.TX *rx;
                    double localY = e.pen_rec.TY *ry;
                    newValue     += string.Format("draw X={0} Y={1} (Coordinates fitting canvas)\r\n", localX, localY);
                    CharacteristicLatestValue.Text = newValue;
#if true  // line
                    switch (e.pen_rec.PenStatus)
                    {
                    case eBeamSDKLib.PEN_DOWN:
                        polyline = new Polyline();
                        polyline.StrokeLineJoin     = PenLineJoin.Round;
                        polyline.StrokeStartLineCap = PenLineCap.Round;
                        polyline.StrokeEndLineCap   = PenLineCap.Round;
                        polyline.Stroke             = new SolidColorBrush(Colors.Blue);
                        polyline.StrokeThickness    = 2;
                        polyline.Points.Add(new Windows.Foundation.Point(localX, localY));
                        drawCanvas.Children.Add(polyline);

                        break;

                    case eBeamSDKLib.PEN_MOVE:
                        polyline.Points.Add(new Windows.Foundation.Point(localX, localY));
                        break;

                    case eBeamSDKLib.PEN_UP:
                        polyline = null;
                        break;

                    case eBeamSDKLib.PEN_HOVER:
                        break;
                    }
#else // dot
                    Ellipse els = new Ellipse();
                    els.Width   = 2;
                    els.Height  = 2;

                    switch (e.pen_rec.PenStatus)
                    {
                    case eBeamSDKLib.PEN_DOWN:
                        els.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));

                        break;

                    case eBeamSDKLib.PEN_MOVE:
                        els.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                        break;

                    case eBeamSDKLib.PEN_UP:
                        els.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255));
                        break;

                    case eBeamSDKLib.PEN_HOVER:
                        els.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 255, 0));
                        break;
                    }
                    Canvas.SetLeft(els, localX);
                    Canvas.SetTop(els, localY);

                    drawCanvas.Children.Add(els);
#endif
                }
            });
        }
        public async void OnPenDataHandlerAsync(object sender, PenDataEvent e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                      () =>
            {
                switch (e.pen_rec.PenStatus)
                {
                case eBeamSDKLib.PEN_DOWN:

                    break;

                case eBeamSDKLib.PEN_MOVE:

                    break;

                case eBeamSDKLib.PEN_UP:
                    m_calStatus++;
                    switch (m_calStatus)
                    {
                    case 0:               ///
                        break;

                    case 1:               ///
                        calNumber1Do.Visibility    = Visibility.Collapsed;
                        calNumber1Check.Visibility = Visibility.Visible;
                        calNumber1Text.Visibility  = Visibility.Collapsed;


                        calNumber2ColorPre.Visibility = Visibility.Collapsed;
                        calNumber2ColorDo.Visibility  = Visibility.Visible;
                        calNumber2Do.Visibility       = Visibility.Visible;
                        calNumber2Check.Visibility    = Visibility.Collapsed;
                        calNumber2Text.Visibility     = Visibility.Visible;
                        if (LeftSide.IsChecked == true)
                        {
                            m_CalPoint[0].X = e.pen_rec.X - CALIBRATION_MARGIN;
                            m_CalPoint[0].Y = e.pen_rec.Y - CALIBRATION_MARGIN;
                        }
                        else
                        {
                            m_CalPoint[3].X = e.pen_rec.X + CALIBRATION_MARGIN;
                            m_CalPoint[3].Y = e.pen_rec.Y - CALIBRATION_MARGIN;
                        }

                        break;

                    case 2:
                        calNumber2ColorPre.Visibility = Visibility.Collapsed;
                        calNumber2ColorDo.Visibility  = Visibility.Visible;
                        calNumber2Do.Visibility       = Visibility.Collapsed;
                        calNumber2Check.Visibility    = Visibility.Visible;
                        calNumber2Text.Visibility     = Visibility.Collapsed;

                        calNumber2Text.Text = "Calibration is Finished.";
                        if (LeftSide.IsChecked == true)
                        {
                            m_CalPoint[2].X = e.pen_rec.X + CALIBRATION_MARGIN;
                            m_CalPoint[2].Y = e.pen_rec.Y + CALIBRATION_MARGIN;
                            m_CalPoint[1].X = m_CalPoint[0].X;
                            m_CalPoint[1].Y = m_CalPoint[2].Y;
                            m_CalPoint[3].X = m_CalPoint[2].X;
                            m_CalPoint[3].Y = m_CalPoint[0].Y;
                        }
                        else
                        {
                            m_CalPoint[1].X = e.pen_rec.X - CALIBRATION_MARGIN;
                            m_CalPoint[1].Y = e.pen_rec.Y + CALIBRATION_MARGIN;
                            m_CalPoint[0].X = m_CalPoint[1].X;
                            m_CalPoint[0].Y = m_CalPoint[3].Y;
                            m_CalPoint[2].X = m_CalPoint[3].X;
                            m_CalPoint[2].Y = m_CalPoint[1].Y;
                        }

                        int pos = (LeftSide.IsChecked == true) ?
                                  eBeamSDKLib.DIRECTION_LEFT : eBeamSDKLib.DIRECTION_RIGHT;
                        sdkLib.setSMPosition(pos);
                        sdkLib.SaveCalibrationToDevice(m_CalPoint[0].X, m_CalPoint[0].Y,
                                                       m_CalPoint[1].X, m_CalPoint[1].Y,
                                                       m_CalPoint[2].X, m_CalPoint[2].Y,
                                                       m_CalPoint[3].X, m_CalPoint[3].Y);

                        break;
                    }

                    break;

                case eBeamSDKLib.PEN_HOVER:
                    break;
                }
            });
        }