Exemplo n.º 1
0
        private void RequestRPM()
        {
            // Sending command
            SendCommand(ListOfCommands.OBD_rpmCommand);
            // Read response, add it in RAM
            string s = connectionService.Read();

            RPMstorage_raw.AppendLine(s);
        }
Exemplo n.º 2
0
        private void SetupConnection()
        {
            // Initialize the BluetoothChatService to perform bluetooth connections
            Handler myHandler = new MyHandler(this);

            connectionService = new OBDConnectionService(this, myHandler);

            // Here initialize the main activity layout:

            // Initialize the array adapter for the conversation thread
            conversationArrayAdapter = new ArrayAdapter <string>(this, Resource.Layout.message);
            conversationView         = FindViewById <ListView>(Resource.Id.@in);
            conversationView.Adapter = conversationArrayAdapter;

            /* Initialize the AT commands buttons with a listener that for click events */

            button_atReset        = FindViewById <Button>(Resource.Id.button_atReset);
            button_atReset.Click += delegate(object sender, EventArgs e) {
                SendCommand(ListOfCommands.AT_Reset);
                string s = connectionService.Read();
                conversationArrayAdapter.Add("Rec:" + s);
            };
            button_atAutomaticProtocol        = FindViewById <Button>(Resource.Id.button_atAutomaticProtocol);
            button_atAutomaticProtocol.Click += delegate(object sender, EventArgs e) {
                SendCommand(ListOfCommands.AT_AutomaticProtocol);
                string s = connectionService.Read();
                conversationArrayAdapter.Add("Rec:" + s);
            };
            button_atReadVoltage        = FindViewById <Button>(Resource.Id.button_atReadVoltage);
            button_atReadVoltage.Click += delegate(object sender, EventArgs e) {
                SendCommand(ListOfCommands.AT_ReadVoltage);
                string s = connectionService.Read();
                conversationArrayAdapter.Add("Rec:" + s);
            };
            button_atEchoOff        = FindViewById <Button>(Resource.Id.button_atEchoOff);
            button_atEchoOff.Click += delegate(object sender, EventArgs e) {
                SendCommand(ListOfCommands.AT_ECO_Off);
                string s = connectionService.Read();
                conversationArrayAdapter.Add("Rec:" + s);
            };
            button_atLinefeedsOff        = FindViewById <Button>(Resource.Id.button_atLinefeedsOff);
            button_atLinefeedsOff.Click += delegate(object sender, EventArgs e) {
                SendCommand(ListOfCommands.AT_Linefeeds_Off);
                string s = connectionService.Read();
                conversationArrayAdapter.Add("Rec:" + s);
            };

            /* Initialize the OBD commands buttons with a listener that for click events */

            button_obdRPM        = FindViewById <Button>(Resource.Id.button_obdRPM);
            button_obdRPM.Click += delegate(object sender, EventArgs e) {
                SendCommand(ListOfCommands.OBD_rpmCommand);
                string s = connectionService.Read();
                conversationArrayAdapter.Add("Rec:" + s);
            };
            button_obdSpeed        = FindViewById <Button>(Resource.Id.button_obdSpeed);
            button_obdSpeed.Click += delegate(object sender, EventArgs e)
            {
                SendCommand(ListOfCommands.OBD_speedCommand);
                string s = connectionService.Read();
                conversationArrayAdapter.Add("Rec:" + s);
            };

            /* Initialize the buttons for periodic requests with a listener that for click events */

            button_startMeasure        = FindViewById <Button>(Resource.Id.button_startMeasure);
            button_startMeasure.Click += delegate(object sender, EventArgs e) {
                // launch the thread to begin continuous request, if not already launched
                if (requestCommandThread == null)
                {
                    requestCommandThread = new RequestCommandThread(connectionService);
                    requestCommandThread.Start();
                    // start timer to show the seconds flow
                    time_sec = 0;
                    timeFlow = CreateTimer(myHandler, TIMER_TIMEFLOW_RAISED, 1000);
                }
            };
            button_stopMeasure        = FindViewById <Button>(Resource.Id.button_stopMeasure);
            button_stopMeasure.Click += delegate(object sender, EventArgs e) {
                // stop measure session
                if (requestCommandThread != null && requestCommandThread.isRunning == false)
                {
                    // stop time flow timer
                    timeFlow.Dispose();
                    // cancel thread
                    //requestCommandThread.Cancel(); //done automatically by Run()
                    requestCommandThread = null;
                }
            };

            // Here there are universal operations:

            // Initialize the BluetoothChatService to perform bluetooth connections
            // -> done at the beginning of this function
        }