Example #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);
        }
        private void instantiateModule(Module module, ModuleInfo info)
        {
            if (info.Present())
            {
                switch (module)
                {
                case SWITCH:
                    persistent.modules.Add(typeof(ISwitch).FullName, new Switch(bridge));
                    break;

                case LED:
                    persistent.modules.Add(typeof(ILed).FullName, new Led(bridge));
                    break;

                case ACCELEROMETER:
                    IAccelerometer accelerometer = null;

                    switch (info.implementation)
                    {
                    case AccelerometerMma8452q.IMPLEMENTATION:
                        accelerometer = new AccelerometerMma8452q(bridge);
                        persistent.modules.Add(typeof(IAccelerometerMma8452q).FullName, accelerometer);
                        break;

                    case AccelerometerBmi160.IMPLEMENTATION:
                        accelerometer = new AccelerometerBmi160(bridge);
                        persistent.modules.Add(typeof(IAccelerometerBosch).FullName, accelerometer);
                        persistent.modules.Add(typeof(IAccelerometerBmi160).FullName, accelerometer);
                        break;

                    case AccelerometerBma255.IMPLEMENTATION:
                        accelerometer = new AccelerometerBma255(bridge);
                        persistent.modules.Add(typeof(IAccelerometerBosch).FullName, accelerometer);
                        persistent.modules.Add(typeof(IAccelerometerBma255).FullName, accelerometer);
                        break;
                    }

                    if (accelerometer != null)
                    {
                        persistent.modules.Add(typeof(IAccelerometer).FullName, accelerometer);
                    }
                    break;

                case TEMPERATURE:
                    persistent.modules.Add(typeof(ITemperature).FullName, new Temperature(bridge));
                    break;

                case GPIO:
                    persistent.modules.Add(typeof(IGpio).FullName, new Gpio(bridge));
                    break;

                case NEO_PIXEL:
                    persistent.modules.Add(typeof(INeoPixel).FullName, new NeoPixel(bridge));
                    break;

                case IBEACON:
                    persistent.modules.Add(typeof(IIBeacon).FullName, new IBeacon(bridge));
                    break;

                case HAPTIC:
                    persistent.modules.Add(typeof(IHaptic).FullName, new Haptic(bridge));
                    break;

                case DATA_PROCESSOR:
                    persistent.modules.Add(typeof(IDataProcessor).FullName, new DataProcessor(bridge));
                    break;

                case EVENT:
                    persistent.modules.Add(typeof(Event).FullName, new Event(bridge));
                    break;

                case LOGGING:
                    persistent.modules.Add(typeof(ILogging).FullName, new Logging(bridge));
                    break;

                case TIMER:
                    persistent.modules.Add(typeof(Timer).FullName, new Timer(bridge));
                    break;

                case SERIAL_PASSTHROUGH:
                    persistent.modules.Add(typeof(ISerialPassthrough).FullName, new SerialPassthrough(bridge));
                    break;

                case MACRO:
                    persistent.modules.Add(typeof(IMacro).FullName, new Macro(bridge));
                    break;

                case GSR:
                    break;

                case SETTINGS:
                    persistent.modules.Add(typeof(ISettings).FullName, new Settings(bridge));
                    break;

                case BAROMETER:
                    IBarometerBosch barometer = null;

                    switch (info.implementation)
                    {
                    case BarometerBmp280.IMPLEMENTATION:
                        barometer = new BarometerBmp280(bridge);
                        persistent.modules.Add(typeof(IBarometerBmp280).FullName, barometer);
                        break;

                    case BarometerBme280.IMPLEMENTATION:
                        barometer = new BarometerBme280(bridge);
                        persistent.modules.Add(typeof(IBarometerBme280).FullName, barometer);
                        break;
                    }

                    if (barometer != null)
                    {
                        persistent.modules.Add(typeof(IBarometerBosch).FullName, barometer);
                    }
                    break;

                case GYRO:
                    persistent.modules.Add(typeof(IGyroBmi160).FullName, new GyroBmi160(bridge));
                    break;

                case AMBIENT_LIGHT:
                    persistent.modules.Add(typeof(IAmbientLightLtr329).FullName, new AmbientLightLtr329(bridge));
                    break;

                case MAGNETOMETER:
                    persistent.modules.Add(typeof(IMagnetometerBmm150).FullName, new MagnetometerBmm150(bridge));
                    break;

                case HUMIDITY:
                    persistent.modules.Add(typeof(IHumidityBme280).FullName, new HumidityBme280(bridge));
                    break;

                case COLOR_DETECTOR:
                    persistent.modules.Add(typeof(IColorTcs34725).FullName, new ColorTcs34725(bridge));
                    break;

                case PROXIMITY:
                    persistent.modules.Add(typeof(IProximityTsl2671).FullName, new ProximityTsl2671(bridge));
                    break;

                case SENSOR_FUSION:
                    persistent.modules.Add(typeof(ISensorFusionBosch).FullName, new SensorFusionBosch(bridge));
                    break;

                case DEBUG:
                    persistent.modules.Add(typeof(IDebug).FullName, new Debug(bridge));
                    break;
                }
            }
        }