Skip to content

Commit

Permalink
USB connection revised
Browse files Browse the repository at this point in the history
  • Loading branch information
Berk Arslan committed Jul 1, 2019
1 parent 4eff9ac commit 529d5ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
40 changes: 26 additions & 14 deletions NrxRelayController/ToggleSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,7 @@ public void ToggleSwitch_Paint(object sender, PaintEventArgs e)

private void toggleSwitch_Click(object sender, EventArgs e)
{
if (device == null)
{
Console.WriteLine("Device not connected");
return;
}

if (usbData == null)
{
Console.WriteLine("USB data is null");
return;
}

HidReport report = new HidReport(usbData.Length, new HidDeviceData(usbData, HidDeviceData.ReadStatus.Success));
report.ReportId = 0x00;
device.WriteReport(report);
}

private void ToggleSwitch_ButtonTimer(object sender, EventArgs e)
Expand Down Expand Up @@ -125,15 +111,41 @@ private void ToggleSwitch_ButtonTimer(object sender, EventArgs e)

protected override void OnMouseDown(MouseEventArgs e)
{
if (device == null)
{
Console.WriteLine("Device not connected");
return;
}

if (usbData == null)
{
Console.WriteLine("USB data is null");
return;
}

if (!active)
{
//buttonControl.deactivateAll();
active = true;

usbData[2] = Convert.ToByte(active);
HidReport report = new HidReport(usbData.Length, new HidDeviceData(usbData, HidDeviceData.ReadStatus.Success));
device.WriteReport(report);

Console.WriteLine("Relay" + Name[Name.Length - 1] + " is " + "closed");

timer.Start();
}
else
{
active = false;

usbData[2] = Convert.ToByte(active);
HidReport report = new HidReport(usbData.Length, new HidDeviceData(usbData, HidDeviceData.ReadStatus.Success));
device.WriteReport(report);

Console.WriteLine("Relay" + Name[Name.Length - 1] + " is " + "opened");

timer.Start();
}
this.Refresh();
Expand Down
4 changes: 2 additions & 2 deletions NrxRelayController/mainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public mainForm()

toggleSwitch1.device = this.device;
toggleSwitch2.device = this.device;
toggleSwitch1.usbData = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
toggleSwitch2.usbData = new byte[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
toggleSwitch1.usbData = new byte[] { 0, 0, 0 };
toggleSwitch2.usbData = new byte[] { 0, 1, 0 };
}

private int DeviceConnect()
Expand Down

0 comments on commit 529d5ec

Please sign in to comment.