Example #1
0
File: Logic.cs Project: myfess/lego
        public void input_data(Lego.SensorData sd)
        {
            return;

            if (sd.sensor_number == 1)
            {
                direction *= -1;
                commands.Add(turn_on_motor());
            }
            else if (sd.sensor_number == 2)
            {
                commands.Add(turn_off_motor());
            }
            else if (sd.sensor_number == 3)
            {
                if (last_color == sd.value)
                {
                    return;
                }
                last_color = sd.value;

                long now_milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                long diff             = now_milliseconds - kick_milliseconds;

                if (diff < 2000)
                {
                    return;
                }

                if (sd.value == (int)Lego.Color.RED)
                {
                    deferred_commands.Add(new Lego.CommandData(
                                              rotate_360(MOTOR_B),
                                              now_milliseconds + 3300
                                              ));
                    // commands.Add(rotate_360(MOTOR_B));
                    kick_milliseconds = now_milliseconds;
                }
            }
        }
Example #2
0
        public static BTResult parse_msg(List <int> msg)
        {
            int len = msg.Count;

            if (len < 2)
            {
                return(new BTResult("ERROR", null));
            }

            int m_len = msg[0] + msg[1] * 256;

            if (len != m_len + 2)
            {
                return(new BTResult("ERROR", null));
            }

            if (m_len == 3 && msg[2] == 2 && msg[3] == 9 && msg[4] == 0)
            {
                return(new BTResult("VALUE_SENT", null));
            }

            if (m_len == 9 && msg[2] == 128 && msg[3] == 9 && msg[5] == 5 && msg[10] == 0)
            {
                int v = 0;
                for (int i = 3; i >= 0; i--)
                {
                    v  = v << 8;
                    v += msg[6 + i];
                }
                Lego.SensorData sd = new Lego.SensorData(v);

                return(new BTResult("SENSOR_DATA", sd));
            }

            return(new BTResult("UNKNOWN", null));
        }
Example #3
0
 public BTResult(string code, Lego.SensorData sensor_data)
 {
     this.code        = code;
     this.sensor_data = sensor_data;
 }