I’m trying to make a 3d mouse for rhino3d using arduino. Till now i made a plugin that connects with arduino mega. The Serial COM ports and baudrate and other thing is hard coded in the plugin cs file only for this time, the plugin take the serial data from arduino and rotates the active view in the x axis for now i have used a while loop for reading the serial data and have a if conditon for escape key to break the loop, but my problem is that i have to manually type the command name in the command prompt to start the command and then press escape key to end the command. Example : after starting rhino you need to type the command lets say “My3DMouse” in the command prompt and then the view gets rotated and won’t stop until you press escape. But this is not how 3D Connexion’s Space Mouse works , It works directly without typing commands on command prompt.
protected override Result RunCommand(RhinoDoc doc, RunMode mode) {
m_escape_key_pressed = false;
RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;
var currentView = doc.Views.ActiveView;
Point3d point = new Point3d(0, 0, 0);
Vector3d vectorx = new Vector3d(1, 0, 0);
Vector3d vectory = new Vector3d(0, 1, 0);
double angle = 90;
double radians = ConvertRadiansToDegree(angle);
while (true) {
RhinoApp.Wait();
//double read = double.Parse(serialPort.ReadLine());
//RhinoApp.Wait();
if (m_escape_key_pressed)
break;
//RhinoApp.Wait();
currentView.ActiveViewport.Rotate(0.10/100, vectorx, point);
//currentView.ActiveViewport.Rotate(read*2, vectory, point);
doc.Views.Redraw();
//RhinoApp.Wait();
}
doc.Views.Redraw();
RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;
return Result.Success;
}
currently this is the runcommand method for the plugin how could i make it run when lets say the serial data is <= 10 , Example arduino reads a analog sensor in loop and prints an output for now i’m reading that output with serialPort.ReadLine , Arduino prints sensor data from -1024 to 1024 with 0 in neutral or center position. So is it possible to make something that continuously listen to the serialPort and check whether the data is < = 10 or so if yes then run the command , Or any other solution and if not don’t run it also with no typing the command on the command prompt. just like a regular mouse dont need to type RotateView in order to rotate the view we just right click and move the mouse to rotate the view, or like 3DConnexion Space mouse dont need to type the command in order to rotate/translate view, just move the mouse and it works.