Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //IMGE
- using System;
- using System.IO.Ports;
- //variablen
- private SerialPort stream = new SerialPort("COM3", 115200);
- string recievedData = "EMPTY";
- //bitmasks buttons
- private int sw1 = 0x40;
- private int sw2 = 0x80;
- private int sw3 = 0x100;
- private int sw4 = 0x200;
- private int sw5 = 0x400;
- private int sw6 = 0x800;
- ###################################
- //START()
- //open serial Stream
- stream.Open();
- ###################################
- //UPDATE()
- stream.Write("1"); //get IDR from the device
- recievedData = stream.ReadLine();
- int defaultValue = System.Convert.ToInt32(recievedData, 16);
- ###################################
- //SLIDER
- stream.Write("4");
- recievedData = stream.ReadLine();
- -> Splitten [A] [rv1] [rv2] [rv3] [rv4]
- ###################################
- //rumble pad
- stream.Write("m <VALUE>\r\n");
- ###################################
- //leds
- stream.Write("l <LED NR> <MODE>\r\n"); <LED NR> - 1 bis 3 | <MODE> 0 = off , 1 = on, 2 = toggle
- ##################################
- //acceleration
- stream.Write("a");
- recievedData = stream.ReadLine();
- -> Splitten [Accel] [FF] [FF] [FF]
- ------code------
- stream.Write("a");
- recievedData = stream.ReadLine();
- string[] split = recievedData.Split(' ');
- float x = System.Convert.ToInt32(split[1], 16);
- float y = System.Convert.ToInt32(split[2], 16);
- float z = System.Convert.ToInt32(split[3], 16);
- if (x > 127.0f)
- {
- x -= 256.0f;
- }
- if (y> 127f)
- {
- y -= 256f;
- }
- if (z > 127f)
- {
- z -= 256f;
- }
- x = mapToOne(x);
- y = mapToOne(y);
- z = mapToOne(z);
- float mapToOne(float f)
- {
- if (f > 0)
- {
- return f / 127f;
- }
- else
- {
- return f / 128f;
- }
- }
- ##################################
- //sound
- stream.Write("s");
- recievedData = stream.ReadLine();
- string[] split = recievedData.Split(' ');
- float value = float.Parse(split[1], System.Globalization.CultureInfo.InvariantCulture);
- value /= 32768f;
Advertisement
Add Comment
Please, Sign In to add comment