Пример #1
0
        private void ConnectEvents(wclWeDoIo Device)
        {
            switch (Device.DeviceType)
            {
            case wclWeDoIoDeviceType.iodCurrentSensor:
                (Device as wclWeDoCurrentSensor).OnCurrentChanged += FmMain_OnCurrentChanged;
                break;

            case wclWeDoIoDeviceType.iodVoltageSensor:
                (Device as wclWeDoVoltageSensor).OnVoltageChanged += FmMain_OnVoltageChanged;
                break;

            case wclWeDoIoDeviceType.iodRgb:
                wclWeDoRgbLight Rgb = (Device as wclWeDoRgbLight);
                Rgb.OnColorChanged += FmMain_OnColorChanged;
                Rgb.OnModeChanged  += FmMain_OnModeChanged;
                break;

            case wclWeDoIoDeviceType.iodMotionSensor:
                wclWeDoMotionSensor Motion = (Device as wclWeDoMotionSensor);
                Motion.OnCountChanged    += FmMain_OnCountChanged;
                Motion.OnDistanceChanged += FmMain_OnDistanceChanged;
                Motion.OnModeChanged     += FmMain_OnMotionModeChanged;
                break;

            case wclWeDoIoDeviceType.iodTiltSensor:
                wclWeDoTiltSensor Tilt = (Device as wclWeDoTiltSensor);
                Tilt.OnModeChanged      += Tilt_OnModeChanged;
                Tilt.OnDirectionChanged += Tilt_OnDirectionChanged;
                Tilt.OnCrashChanged     += Tilt_OnCrashChanged;
                Tilt.OnAngleChanged     += Tilt_OnAngleChanged;
                break;
            }
        }
Пример #2
0
 private void FHub_OnDeviceDetached(Object Sender, wclWeDoIo Device)
 {
     if (Device.DeviceType == wclWeDoIoDeviceType.iodRgb)
     {
         FRgb = null;
         EnableSetColors(false);
     }
 }
Пример #3
0
        private void UpdateRgbColors(wclWeDoRgbLight Rgb)
        {
            Color c = Rgb.Color;

            edR.Text = c.R.ToString();
            edG.Text = c.G.ToString();
            edB.Text = c.B.ToString();
        }
Пример #4
0
        private void UpdateRgb(wclWeDoRgbLight Sensor)
        {
            UpdateDeviceInfo(laRgbVersion, laRgbDeviceType, laRgbConnectionId, Sensor);

            UpdateRgbColors(Sensor);
            UpdateRgbIndex(Sensor);
            UpdateRgbMode(Sensor);
        }
Пример #5
0
        private void FHub_OnDeviceAttached(Object Sender, wclWeDoIo Device)
        {
            if (Device.DeviceType == wclWeDoIoDeviceType.iodRgb)
            {
                FRgb = (wclWeDoRgbLight)Device;
                FRgb.OnColorChanged += FRgb_OnColorChanged;
                FRgb.OnModeChanged  += FRgb_OnModeChanged;

                EnableSetColors(true);
                EnableColorControls();
            }
        }
Пример #6
0
        private void FHub_OnDeviceDetached(object Sender, wclWeDoIo Device)
        {
            if (Device.DeviceType == wclWeDoIoDeviceType.iodColorSensor && FColor != null && Device.ConnectionId == FColor.ConnectionId)
            {
                FColor = null;
                EnableControl(false);
            }

            if (Device.DeviceType == wclWeDoIoDeviceType.iodRgb)
            {
                FRgb = null;
            }
        }
Пример #7
0
        private void btSetDefault_Click(object sender, EventArgs e)
        {
            wclWeDoHub      Hub = GetHub();
            wclWeDoRgbLight Rgb = FRobot.GetRgbDevice(Hub);

            if (Rgb != null)
            {
                Int32 Res = Rgb.SwitchToDefaultColor();
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    MessageBox.Show("Unable to set default color: 0x" + Res.ToString("X8"));
                }
            }
        }
Пример #8
0
        private void btSetIndex_Click(object sender, EventArgs e)
        {
            wclWeDoHub      Hub = GetHub();
            wclWeDoRgbLight Rgb = FRobot.GetRgbDevice(Hub);

            if (Rgb != null)
            {
                Int32 Res = Rgb.SetColorIndex((wclWeDoColor)cbColorIndex.SelectedIndex);
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    MessageBox.Show("Unable to set color index: 0x" + Res.ToString("X8"));
                }
            }
        }
Пример #9
0
        private void btTurnOff_Click(object sender, EventArgs e)
        {
            wclWeDoHub      Hub = GetHub();
            wclWeDoRgbLight Rgb = FRobot.GetRgbDevice(Hub);

            if (Rgb != null)
            {
                Int32 Res = Rgb.SwitchOff();
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    MessageBox.Show("Unable to switch LED off: 0x" + Res.ToString("X8"));
                }
            }
        }
Пример #10
0
        private void fmMain_Load(object sender, EventArgs e)
        {
            FManager = new wclBluetoothManager();

            FWatcher             = new wclWeDoWatcher();
            FWatcher.OnHubFound += FWatcher_OnHubFound;

            FHub                   = new wclWeDoHub();
            FHub.OnConnected      += FHub_OnConnected;
            FHub.OnDisconnected   += FHub_OnDisconnected;
            FHub.OnDeviceAttached += FHub_OnDeviceAttached;
            FHub.OnDeviceDetached += FHub_OnDeviceDetached;

            FColor = null;
            FRgb   = null;
        }
Пример #11
0
        private void btSetRgb_Click(object sender, EventArgs e)
        {
            wclWeDoHub      Hub = GetHub();
            wclWeDoRgbLight Rgb = FRobot.GetRgbDevice(Hub);

            if (Rgb != null)
            {
                Color c = Color.FromRgb(Convert.ToByte(edR.Text), Convert.ToByte(edG.Text),
                                        Convert.ToByte(edB.Text));
                Int32 Res = Rgb.SetColor(c);
                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    MessageBox.Show("Unable to set color: 0x" + Res.ToString("X8"));
                }
            }
        }
Пример #12
0
        private void FHub_OnDeviceAttached(object Sender, wclWeDoIo Device)
        {
            if (FColor == null)
            {
                if (Device.DeviceType == wclWeDoIoDeviceType.iodColorSensor)
                {
                    FColor = (wclWeDoColorSensor)Device;
                    FColor.OnColorDetected += FColor_OnColorDetected;
                    EnableControl(true);
                }
            }

            if (Device.DeviceType == wclWeDoIoDeviceType.iodRgb)
            {
                FRgb = (wclWeDoRgbLight)Device;
            }
        }
Пример #13
0
        private void FmMain_Load(Object Sender, EventArgs e)
        {
            cbColorMode.SelectedIndex = -1;

            FManager = new wclBluetoothManager();

            FWatcher             = new wclWeDoWatcher();
            FWatcher.OnHubFound += FWatcher_OnHubFound;

            FHub                   = new wclWeDoHub();
            FHub.OnConnected      += FHub_OnConnected;
            FHub.OnDisconnected   += FHub_OnDisconnected;
            FHub.OnDeviceAttached += FHub_OnDeviceAttached;
            FHub.OnDeviceDetached += FHub_OnDeviceDetached;

            FRgb = null;
        }
Пример #14
0
        private void UpdateRgbMode(wclWeDoRgbLight Rgb)
        {
            switch (Rgb.Mode)
            {
            case wclWeDoRgbLightMode.lmDiscrete:
                cbColorMode.SelectedIndex = 0;
                break;

            case wclWeDoRgbLightMode.lmAbsolute:
                cbColorMode.SelectedIndex = 1;
                break;

            default:
                cbColorMode.SelectedIndex = -1;
                break;
            }
        }
Пример #15
0
        private void btSetMode_Click(object sender, EventArgs e)
        {
            wclWeDoHub      Hub = GetHub();
            wclWeDoRgbLight Rgb = FRobot.GetRgbDevice(Hub);

            if (Rgb != null)
            {
                Boolean RgbEnabled   = (cbColorMode.SelectedIndex == 1);
                Boolean IndexEnabled = (cbColorMode.SelectedIndex == 0);

                Int32 Res = wclErrors.WCL_E_SUCCESS;
                if (RgbEnabled)
                {
                    Res = Rgb.SetMode(wclWeDoRgbLightMode.lmAbsolute);
                }
                else
                {
                    if (IndexEnabled)
                    {
                        Res = Rgb.SetMode(wclWeDoRgbLightMode.lmDiscrete);
                    }
                }

                if (Res != wclErrors.WCL_E_SUCCESS)
                {
                    MessageBox.Show("Unable to change color mode: 0x" + Res.ToString("X8"));
                }
                else
                {
                    if (RgbEnabled)
                    {
                        UpdateRgbColors(Rgb);
                    }
                    else
                    {
                        if (IndexEnabled)
                        {
                            UpdateRgbIndex(Rgb);
                        }
                    }
                }
            }
        }
Пример #16
0
 private void UpdateRgbIndex(wclWeDoRgbLight Rgb)
 {
     cbColorIndex.SelectedIndex = (Int32)Rgb.ColorIndex;
 }
Пример #17
0
        private void UpdateTabs()
        {
            wclWeDoHub Hub = GetHub();

            if (Hub == null)
            {
                RemoveTabs();
            }
            else
            {
                AddPage(tsHubInfo);
                UpdateHubInfo(Hub);

                wclWeDoCurrentSensor Current = FRobot.GetCurrentSensor(Hub);
                if (Current != null && Current.Attached)
                {
                    AddPage(tsCurrent);
                    UpdateCurrent(Current);
                }

                wclWeDoVoltageSensor Voltage = FRobot.GetVoltageSensor(Hub);
                if (Voltage != null && Voltage.Attached)
                {
                    AddPage(tsVoltage);
                    UpdateVoltage(Voltage);
                }

                wclWeDoRgbLight Rgb = FRobot.GetRgbDevice(Hub);
                if (Rgb != null && Rgb.Attached)
                {
                    AddPage(tsRgb);
                    UpdateRgb(Rgb);
                }

                wclWeDoPiezo Piezo = FRobot.GetPiezoDevice(Hub);
                if (Piezo != null && Piezo.Attached)
                {
                    AddPage(tsPiezo);
                    UpdatePiezo(Piezo);
                }

                wclWeDoMotionSensor Motion = GetMotionSensor(0);
                if (Motion != null && Motion.Attached)
                {
                    AddPage(tsMotion1);
                    UpdateMotion(Motion);
                }

                Motion = GetMotionSensor(1);
                if (Motion != null && Motion.Attached)
                {
                    AddPage(tsMotion2);
                    UpdateMotion(Motion);
                }

                wclWeDoTiltSensor Tilt = GetTiltSensor(0);
                if (Tilt != null && Tilt.Attached)
                {
                    AddPage(tsTilt1);
                    UpdateTilt(Tilt);
                }

                Tilt = GetTiltSensor(1);
                if (Tilt != null && Tilt.Attached)
                {
                    AddPage(tsTilt2);
                    UpdateTilt(Tilt);
                }

                wclWeDoMotor Motor = GetMotor(0);
                if (Motor != null && Motor.Attached)
                {
                    AddPage(tsMotor1);
                    UpdateMotor(Motor);
                }

                Motor = GetMotor(1);
                if (Motor != null && Motor.Attached)
                {
                    AddPage(tsMotor2);
                    UpdateMotor(Motor);
                }
            }
        }