void PIEDataHandler.HandlePIEHidData(byte[] data, PIEDevice sourceDevice) { if (sourceDevice != _device.BackingObject) { return; } while (0 == sourceDevice.ReadData(ref data)) { var state = BinaryConversions.ConvertKeypad(data); var changes = state.Buttons.Changes(_history.Last.Value.Buttons); _history.AddLast(state); Buttons = state.Buttons; var @event = DeviceEvent.KeypadStateChanged(_device, null); _device.AddEvent(@event); } }
public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice) { //check the sourceDevice and make sure it is the same device as selected in CboDevice if (sourceDevice == devices[selecteddevice]) { byte[] rdata = null; while (0 == sourceDevice.ReadData(ref rdata)) //do this so don't ever miss any data { //write raw data to listbox1 in HEX //String output = string.Format("Callback: {0}, ID: {1}, UnitID: {2}, data=", sourceDevice.Pid, selecteddevice.ToString(), rdata[1].ToString()); //for (int i = 0; i < sourceDevice.ReadLength; i++) //{ //output = output + BinToHex(rdata[i]) + " "; //} String output = string.Format("Callback: {0}, ID: {1}, UnitID: {2}, data=", sourceDevice.Pid, selecteddevice.ToString(), rdata[1].ToString()); BitArray col1 = new BitArray(new byte[] { rdata[3] }); BitArray col2 = new BitArray(new byte[] { rdata[4] }); BitArray col3 = new BitArray(new byte[] { rdata[5] }); BitArray col4 = new BitArray(new byte[] { rdata[6] }); switch (device_type) { case "XK-24": case "XK-60": case "XK-80": for (int i = 0; i < col1.Length; i++) { if (col1[i]) { int key = i; output = output + " Key pressed: " + key + " " + col1[i].ToString(); } } for (int i = 0; i < col2.Length; i++) { if (col2[i]) { int key = i + 8; output = output + " Key pressed: " + key + " " + col2[i].ToString(); } } for (int i = 0; i < col3.Length; i++) { if (col3[i]) { int key = i + 16; output = output + " Key pressed: " + key + " " + col3[i].ToString(); } } for (int i = 0; i < col4.Length; i++) { if (col4[i]) { int key = i + 24; output = output + " Key pressed: " + key + " " + col4[i].ToString(); } } if (device_type == "XK-24") { // XK-24 only has 24 keys break; } BitArray col5 = new BitArray(new byte[] { rdata[7] }); BitArray col6 = new BitArray(new byte[] { rdata[8] }); BitArray col7 = new BitArray(new byte[] { rdata[9] }); BitArray col8 = new BitArray(new byte[] { rdata[10] }); BitArray col9 = new BitArray(new byte[] { rdata[11] }); BitArray col10 = new BitArray(new byte[] { rdata[12] }); for (int i = 0; i < col5.Length; i++) { if (col1[i]) { int key = i + 32; output = output + " Key pressed: " + key + " " + col1[i].ToString(); } } for (int i = 0; i < col6.Length; i++) { if (col2[i]) { int key = i + 40; output = output + " Key pressed: " + key + " " + col2[i].ToString(); } } for (int i = 0; i < col7.Length; i++) { if (col3[i]) { int key = i + 48; output = output + " Key pressed: " + key + " " + col3[i].ToString(); } } for (int i = 0; i < col8.Length; i++) { if (col4[i]) { int key = i + 56; output = output + " Key pressed: " + key + " " + col4[i].ToString(); } } for (int i = 0; i < col9.Length; i++) { if (col3[i]) { int key = i + 64; output = output + " Key pressed: " + key + " " + col3[i].ToString(); } } for (int i = 0; i < col10.Length; i++) { if (col4[i]) { int key = i + 72; output = output + " Key pressed: " + key + " " + col4[i].ToString(); } } break; default: for (int i = 0; i < sourceDevice.ReadLength; i++) { output = output + BinToHex(rdata[i]) + " "; } break; } OnUIThread(() => Diagnostics.Instance.DiagnosticListbox.Items.Add(output)); }//end while } }
//data callback public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice) { //check the sourceDevice and make sure it is the same device as selected in CboDevice if (sourceDevice == devices[selecteddevice]) { byte[] rdata = null; while (0 == sourceDevice.ReadData(ref rdata)) //do this so don't ever miss any data { //read the unit ID c = this.LblUnitID; this.SetText(rdata[sourceDevice.ReadLength - 1].ToString()); //write raw data to listbox1 String output = "Callback: " + this.devices[selecteddevice].Pid + ", ID: " + selecteddevice.ToString() + ", data="; for (int i = 0; i < sourceDevice.ReadLength; i++) { output = output + rdata[i].ToString() + " "; } this.SetListBox(output); //write Analog data to the individual textboxes c = this.textBoxA2; this.SetText(rdata[1].ToString()); c = this.textBoxA3; this.SetText(rdata[2].ToString()); c = this.textBoxA4; this.SetText(rdata[3].ToString()); c = this.textBoxA5; this.SetText(rdata[4].ToString()); c = this.textBoxA6; this.SetText(rdata[5].ToString()); c = this.textBoxA7; this.SetText(rdata[6].ToString()); c = this.textBoxA8; this.SetText(rdata[7].ToString()); c = this.textBoxA9; this.SetText(rdata[8].ToString()); c = this.textBoxA10; this.SetText(rdata[9].ToString()); c = this.textBoxA11; this.SetText(rdata[10].ToString()); c = this.textBoxA12; this.SetText(rdata[11].ToString()); c = this.textBoxA13; this.SetText(rdata[12].ToString()); c = this.textBoxA14; this.SetText(rdata[13].ToString()); c = this.textBoxA15; this.SetText(rdata[14].ToString()); c = this.textBoxA16; this.SetText(rdata[15].ToString()); c = this.textBoxA17; this.SetText(rdata[16].ToString()); c = this.textBoxA18; this.SetText(rdata[17].ToString()); c = this.textBoxA19; this.SetText(rdata[18].ToString()); c = this.textBoxA20; this.SetText(rdata[19].ToString()); c = this.textBoxA21; this.SetText(rdata[20].ToString()); c = this.textBoxA22; this.SetText(rdata[21].ToString()); c = this.textBoxA23; this.SetText(rdata[22].ToString()); c = this.textBoxA24; this.SetText(rdata[23].ToString()); //pin 24 //write digital 1 data to the individual textboxes c = this.textBoxD12; this.SetText((rdata[24] & 1).ToString()); c = this.textBoxD13; this.SetText(((rdata[24] & 2) >> 1).ToString()); c = this.textBoxD14; this.SetText(((rdata[24] & 4) >> 2).ToString()); c = this.textBoxD15; this.SetText(((rdata[24] & 8) >> 3).ToString()); c = this.textBoxD16; this.SetText(((rdata[24] & 16) >> 4).ToString()); c = this.textBoxD17; this.SetText(((rdata[24] & 32) >> 5).ToString()); c = this.textBoxD18; this.SetText(((rdata[24] & 64) >> 6).ToString()); c = this.textBoxD19; this.SetText(((rdata[24] & 128) >> 7).ToString()); c = this.textBoxD110; this.SetText((rdata[25] & 1).ToString()); c = this.textBoxD111; this.SetText(((rdata[25] & 2) >> 1).ToString()); c = this.textBoxD112; this.SetText(((rdata[25] & 4) >> 2).ToString()); c = this.textBoxD113; this.SetText(((rdata[25] & 8) >> 3).ToString()); c = this.textBoxD114; this.SetText(((rdata[25] & 16) >> 4).ToString()); c = this.textBoxD115; this.SetText(((rdata[25] & 32) >> 5).ToString()); c = this.textBoxD116; this.SetText(((rdata[25] & 64) >> 6).ToString()); c = this.textBoxD117; this.SetText(((rdata[25] & 128) >> 7).ToString()); c = this.textBoxD118; this.SetText((rdata[26] & 1).ToString()); c = this.textBoxD119; this.SetText(((rdata[26] & 2) >> 1).ToString()); c = this.textBoxD120; this.SetText(((rdata[26] & 4) >> 2).ToString()); c = this.textBoxD121; this.SetText(((rdata[26] & 8) >> 3).ToString()); c = this.textBoxD122; this.SetText(((rdata[26] & 16) >> 4).ToString()); c = this.textBoxD123; this.SetText(((rdata[26] & 32) >> 5).ToString()); c = this.textBoxD124; this.SetText(((rdata[26] & 64) >> 6).ToString()); //pin 24 //write digital 2 data to the individual textboxes c = this.textBoxD22; this.SetText((rdata[27] & 1).ToString()); c = this.textBoxD23; this.SetText(((rdata[27] & 2) >> 1).ToString()); c = this.textBoxD24; this.SetText(((rdata[27] & 4) >> 2).ToString()); c = this.textBoxD25; this.SetText(((rdata[27] & 8) >> 3).ToString()); c = this.textBoxD26; this.SetText(((rdata[27] & 16) >> 4).ToString()); c = this.textBoxD27; this.SetText(((rdata[27] & 32) >> 5).ToString()); c = this.textBoxD28; this.SetText(((rdata[27] & 64) >> 6).ToString()); c = this.textBoxD29; this.SetText(((rdata[27] & 128) >> 7).ToString()); c = this.textBoxD210; this.SetText((rdata[28] & 1).ToString()); c = this.textBoxD211; this.SetText(((rdata[28] & 2) >> 1).ToString()); c = this.textBoxD212; this.SetText(((rdata[28] & 4) >> 2).ToString()); c = this.textBoxD213; this.SetText(((rdata[28] & 8) >> 3).ToString()); c = this.textBoxD214; this.SetText(((rdata[28] & 16) >> 4).ToString()); c = this.textBoxD215; this.SetText(((rdata[28] & 32) >> 5).ToString()); c = this.textBoxD216; this.SetText(((rdata[28] & 64) >> 6).ToString()); c = this.textBoxD217; this.SetText(((rdata[28] & 128) >> 7).ToString()); c = this.textBoxD218; this.SetText((rdata[29] & 1).ToString()); c = this.textBoxD219; this.SetText(((rdata[29] & 2) >> 1).ToString()); c = this.textBoxD220; this.SetText(((rdata[29] & 4) >> 2).ToString()); c = this.textBoxD221; this.SetText(((rdata[29] & 8) >> 3).ToString()); c = this.textBoxD222; this.SetText(((rdata[29] & 16) >> 4).ToString()); c = this.textBoxD223; this.SetText(((rdata[29] & 32) >> 5).ToString()); c = this.textBoxD224; this.SetText(((rdata[29] & 64) >> 6).ToString()); //pin 24 } } }
// Data callback public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice) { // Check the sourceDevice and make sure it is the same device as selected in CboDevice if (sourceDevice == devices[selectedDevice]) { // byte array used for read data byte[] rData = null; // I think an MCU would use while(1) here, as an equivalent structure (TB, 11/12/2011) while (0 == sourceDevice.ReadData(ref rData)) // do this so don't ever miss any data { // Read the unit ID // TODO: If we do only have one device, then we could simply grab the ID once up above, and load it into an // instance variable on form_load. Need to verify that we are using only one device, and then how // that device is numbered c = this.LblUnitID; this.SetText(rData[sourceDevice.ReadLength - 1].ToString()); //write raw data to listbox1 String output = "Callback: " + this.devices[selectedDevice].Pid + ", ID: " + selectedDevice.ToString() + ", data="; for (int i = 0; i < sourceDevice.ReadLength; i++) { output = output + rData[i].ToString() + " "; } this.SetListBox(output); // TODO: We'll need to convert THESE data into the correct formats needed by SimConnect (TB, 11/12/2011) // Write Analog data from each pin, to the corresponding individual textboxes. Each of these pins // will have specific data assigned (if all are used), and these data will have to be translated // into the proper SimConnect Event calls. // TODO: Use the debugger to check the format of these bytes, and how the data changes. I believe // these to be the analog data, and thus it should be a simply matter of writing the values // to the appropriate P3D event/variable. c = this.textBoxA2; this.SetText(rData[1].ToString()); // pin 0 c = this.textBoxA3; this.SetText(rData[2].ToString()); c = this.textBoxA4; this.SetText(rData[3].ToString()); c = this.textBoxA5; this.SetText(rData[4].ToString()); c = this.textBoxA6; this.SetText(rData[5].ToString()); c = this.textBoxA7; this.SetText(rData[6].ToString()); c = this.textBoxA8; this.SetText(rData[7].ToString()); c = this.textBoxA9; this.SetText(rData[8].ToString()); c = this.textBoxA10; this.SetText(rData[9].ToString()); c = this.textBoxA11; this.SetText(rData[10].ToString()); c = this.textBoxA12; this.SetText(rData[11].ToString()); c = this.textBoxA13; this.SetText(rData[12].ToString()); c = this.textBoxA14; this.SetText(rData[13].ToString()); c = this.textBoxA15; this.SetText(rData[14].ToString()); c = this.textBoxA16; this.SetText(rData[15].ToString()); c = this.textBoxA17; this.SetText(rData[16].ToString()); c = this.textBoxA18; this.SetText(rData[17].ToString()); c = this.textBoxA19; this.SetText(rData[18].ToString()); c = this.textBoxA20; this.SetText(rData[19].ToString()); c = this.textBoxA21; this.SetText(rData[20].ToString()); c = this.textBoxA22; this.SetText(rData[21].ToString()); c = this.textBoxA23; this.SetText(rData[22].ToString()); c = this.textBoxA24; this.SetText(rData[23].ToString()); // pin 24 //write digital 1 data to the individual textboxes c = this.textBoxD12; this.SetText((rData[24] & 1).ToString()); // Bitwise AND with 0b00000001 c = this.textBoxD13; this.SetText(((rData[24] & 2) >> 1).ToString()); c = this.textBoxD14; this.SetText(((rData[24] & 4) >> 2).ToString()); c = this.textBoxD15; this.SetText(((rData[24] & 8) >> 3).ToString()); c = this.textBoxD16; this.SetText(((rData[24] & 16) >> 4).ToString()); c = this.textBoxD17; this.SetText(((rData[24] & 32) >> 5).ToString()); c = this.textBoxD18; this.SetText(((rData[24] & 64) >> 6).ToString()); c = this.textBoxD19; this.SetText(((rData[24] & 128) >> 7).ToString()); c = this.textBoxD110; this.SetText((rData[25] & 1).ToString()); c = this.textBoxD111; this.SetText(((rData[25] & 2) >> 1).ToString()); c = this.textBoxD112; this.SetText(((rData[25] & 4) >> 2).ToString()); c = this.textBoxD113; this.SetText(((rData[25] & 8) >> 3).ToString()); c = this.textBoxD114; this.SetText(((rData[25] & 16) >> 4).ToString()); c = this.textBoxD115; this.SetText(((rData[25] & 32) >> 5).ToString()); c = this.textBoxD116; this.SetText(((rData[25] & 64) >> 6).ToString()); c = this.textBoxD117; this.SetText(((rData[25] & 128) >> 7).ToString()); c = this.textBoxD118; this.SetText((rData[26] & 1).ToString()); c = this.textBoxD119; this.SetText(((rData[26] & 2) >> 1).ToString()); c = this.textBoxD120; this.SetText(((rData[26] & 4) >> 2).ToString()); c = this.textBoxD121; this.SetText(((rData[26] & 8) >> 3).ToString()); c = this.textBoxD122; this.SetText(((rData[26] & 16) >> 4).ToString()); c = this.textBoxD123; this.SetText(((rData[26] & 32) >> 5).ToString()); c = this.textBoxD124; this.SetText(((rData[26] & 64) >> 6).ToString()); //pin 24 //write digital 2 data to the individual textboxes c = this.textBoxD22; this.SetText((rData[27] & 1).ToString()); c = this.textBoxD23; this.SetText(((rData[27] & 2) >> 1).ToString()); c = this.textBoxD24; this.SetText(((rData[27] & 4) >> 2).ToString()); c = this.textBoxD25; this.SetText(((rData[27] & 8) >> 3).ToString()); c = this.textBoxD26; this.SetText(((rData[27] & 16) >> 4).ToString()); c = this.textBoxD27; this.SetText(((rData[27] & 32) >> 5).ToString()); c = this.textBoxD28; this.SetText(((rData[27] & 64) >> 6).ToString()); c = this.textBoxD29; this.SetText(((rData[27] & 128) >> 7).ToString()); c = this.textBoxD210; this.SetText((rData[28] & 1).ToString()); c = this.textBoxD211; this.SetText(((rData[28] & 2) >> 1).ToString()); c = this.textBoxD212; this.SetText(((rData[28] & 4) >> 2).ToString()); c = this.textBoxD213; this.SetText(((rData[28] & 8) >> 3).ToString()); c = this.textBoxD214; this.SetText(((rData[28] & 16) >> 4).ToString()); c = this.textBoxD215; this.SetText(((rData[28] & 32) >> 5).ToString()); c = this.textBoxD216; this.SetText(((rData[28] & 64) >> 6).ToString()); c = this.textBoxD217; this.SetText(((rData[28] & 128) >> 7).ToString()); c = this.textBoxD218; this.SetText((rData[29] & 1).ToString()); c = this.textBoxD219; this.SetText(((rData[29] & 2) >> 1).ToString()); c = this.textBoxD220; this.SetText(((rData[29] & 4) >> 2).ToString()); c = this.textBoxD221; this.SetText(((rData[29] & 8) >> 3).ToString()); c = this.textBoxD222; this.SetText(((rData[29] & 16) >> 4).ToString()); c = this.textBoxD223; this.SetText(((rData[29] & 32) >> 5).ToString()); c = this.textBoxD224; this.SetText(((rData[29] & 64) >> 6).ToString()); //pin 24 } } }
/// <summary> /// Data callback, called when RailDriver data is available /// </summary> /// <param name="data"></param> /// <param name="sourceDevice"></param> public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice) { if (sourceDevice != Device) { return; } State.SaveButtonData(); byte[] rdata = null; while (0 == sourceDevice.ReadData(ref rdata)) //do this so don't ever miss any data { #if false String output = "Callback: " + sourceDevice.Pid + ", ID: " + Device.ToString() + ", data="; for (int i = 0; i < sourceDevice.ReadLength; i++) { output = output + rdata[i].ToString() + " "; } Console.WriteLine(output); #endif State.DirectionPercent = Percentage(rdata[1], FullReversed, Neutral, FullForward); State.ThrottlePercent = Percentage(rdata[2], ThrottleIdle, FullThrottle); State.DynamicBrakePercent = Percentage(rdata[2], ThrottleIdle, DynamicBrakeSetup, DynamicBrake); State.TrainBrakePercent = Percentage(rdata[3], AutoBrakeRelease, FullAutoBrake); State.EngineBrakePercent = Percentage(rdata[4], IndependentBrakeRelease, IndependentBrakeFull); float a = .01f * State.EngineBrakePercent; float calOff = (1 - a) * BailOffDisengagedRelease + a * BailOffDisengagedFull; float calOn = (1 - a) * BailOffEngagedRelease + a * BailOffEngagedFull; State.BailOff = Percentage(rdata[5], calOff, calOn) > 50; if (State.TrainBrakePercent >= 100) { State.Emergency = Percentage(rdata[3], FullAutoBrake, EmergencyBrake) > 50; } State.Wipers = (int)(.01 * Percentage(rdata[6], Rotary1Position1, Rotary1Position2, Rotary1Position3) + 2.5); State.Lights = (int)(.01 * Percentage(rdata[7], Rotary2Position1, Rotary2Position2, Rotary2Position3) + 2.5); State.AddButtonData(rdata); } if (State.IsPressed(4, 0x30)) { State.Emergency = true; } if (State.IsPressed(1, 0x40)) { Active = !Active; EnableSpeaker(Active); if (Active) { SetLEDs(0x80, 0x80, 0x80); LEDSpeed = -1; UserInput.RDState = State; } else { SetLEDs(0x40, 0x40, 0x40); UserInput.RDState = null; } } State.Changed = true; }