Ejemplo n.º 1
0
        internal string CreateIdentifier(IModuleBoardBridge bridge)
        {
            string myIdentifier = null;

            switch ((Module)eventConfig[0])
            {
            case SWITCH:
                myIdentifier = "switch";
                break;

            case ACCELEROMETER: {
                var module = bridge.GetModule <IAccelerometer>();
                if (module is AccelerometerMma8452q)
                {
                    myIdentifier = AccelerometerMma8452q.createIdentifier(this);
                }
                else if (module is AccelerometerBmi160)
                {
                    myIdentifier = AccelerometerBmi160.createIdentifier(this);
                }
                else if (module is AccelerometerBma255)
                {
                    myIdentifier = AccelerometerBosch.createIdentifier(this);
                }
                else
                {
                    myIdentifier = null;
                }
                break;
            }

            case TEMPERATURE:
                myIdentifier = string.Format("temperature[{0}]", eventConfig[2]);
                break;

            case GPIO:
                myIdentifier = Gpio.createIdentifier(this);
                break;

            case DATA_PROCESSOR:
                myIdentifier = DataProcessor.createIdentifier(this, bridge.GetModule <IDataProcessor>() as DataProcessor, bridge.getFirmware());
                break;

            case SERIAL_PASSTHROUGH:
                myIdentifier = SerialPassthrough.createIdentifier(this);
                break;

            case SETTINGS:
                myIdentifier = Settings.createIdentifier(this);
                break;

            case BAROMETER:
                myIdentifier = BarometerBosch.createIdentifier(this);
                break;

            case GYRO:
                myIdentifier = attributes.length() > 2 ? "angular-velocity" : string.Format("angular-velocity[{0}]", (attributes.offset >> 1));
                break;

            case AMBIENT_LIGHT:
                myIdentifier = "illuminance";
                break;

            case MAGNETOMETER:
                myIdentifier = attributes.length() > 2 ? "magnetic-field" : string.Format("magnetic-field[{0}]", (attributes.offset >> 1));
                break;

            case HUMIDITY:
                myIdentifier = "relative-humidity";
                break;

            case COLOR_DETECTOR:
                myIdentifier = attributes.length() > 2 ? "color" : string.Format("color[{0}]", (attributes.offset >> 1));
                break;

            case PROXIMITY:
                myIdentifier = "proximity";
                break;

            case SENSOR_FUSION:
                myIdentifier = SensorFusionBosch.createIdentifier(this);
                break;
            }

            if (myIdentifier == null)
            {
                throw new InvalidOperationException("Cannot create identifier string for data type: " + Util.arrayToHexString(eventConfig));
            }

            return((input != null && !input.eventConfig.SequenceEqual(eventConfig) ? input.CreateIdentifier(bridge) + ":" : "") + myIdentifier);
        }