public ExpansionPlate(PiTop4Board module) : base(module)
        {
            _foundationPlate = module.GetOrCreatePlate <FoundationPlate>();

            _servoMotorsFactory = new ConnectedDeviceFactory <ServoMotorPort, ServoMotor>(deviceType =>
            {
                var ctorSignature = new[] { typeof(ServoMotorPort), typeof(SMBusDevice) };
                var ctor          = deviceType.GetConstructor(ctorSignature);
                if (ctor != null)
                {
                    return(devicePort =>
                           (ServoMotor)Activator.CreateInstance(deviceType, devicePort, GetOrCreateMcu()) !);
                }
                throw new InvalidOperationException(
                    $"Cannot find suitable constructor for type {deviceType}, looking for signature {ctorSignature}");
            });

            _encoderMotorFactory = new ConnectedDeviceFactory <EncoderMotorPort, EncoderMotor>(
                deviceType =>
            {
                var ctorSignature = new[] { typeof(EncoderMotorPort), typeof(SMBusDevice) };
                var ctor          = deviceType.GetConstructor(ctorSignature);
                if (ctor != null)
                {
                    return(devicePort =>
                           (EncoderMotor)Activator.CreateInstance(deviceType, devicePort, GetOrCreateMcu()) !);
                }
                throw new InvalidOperationException(
                    $"Cannot find suitable constructor for type {deviceType}, looking for signature {ctorSignature}");
            });

            // set up heartbeat
            RegisterForDisposal(Observable.Interval(HEARTBEAT_SEND_INTERVAL, TaskPoolScheduler.Default).Subscribe(_ =>
            {
                GetOrCreateMcu().WriteByte(REGISTER_HEARTBEAT, HEARTBEAT_SECONDS_BEFORE_SHUTDOWN);
            }));

            RegisterForDisposal(_servoMotorsFactory);
            RegisterForDisposal(_encoderMotorFactory);
            RegisterForDisposal(() =>
            {
                _imu?.Dispose();
                _mcu?.I2c.Dispose();
            });
        }
Esempio n. 2
0
 public static FoundationPlate GetOrCreateFoundationPlate(this PiTop4Board module)
 {
     return(module.GetOrCreatePlate <FoundationPlate>());
 }
Esempio n. 3
0
        public void can_obtain_plate_from_module()
        {
            using var plate = _module.GetOrCreatePlate <ExpansionPlate>();

            plate.Should().NotBeNull();
        }
Esempio n. 4
0
 public static ExpansionPlate GetOrCreateExpansionPlate(this PiTop4Board module)
 {
     return(module.GetOrCreatePlate <ExpansionPlate>());
 }