public void TestTalonSRXStarts0()
 {
     using (TalonSRX t = new TalonSRX(2))
     {
         Assert.AreEqual(t.Get(), 0);
     }
 }
 public void TestTalonSRXSet()
 {
     using (TalonSRX t = new TalonSRX(2))
     {
         t.Set(1);
         Assert.AreEqual(t.Get(), 1);
     }
 }
        public void TestPIDWrite()
        {
            using (TalonSRX t = new TalonSRX(2))
            {
                t.PidWrite(-1);

                Assert.AreEqual(t.Get(), -1);
            }
        }
 public void TestPWMHelpers()
 {
     using (TalonSRX t = new TalonSRX(2))
     {
         t.Set(1);
         Assert.AreEqual(PWMHelpers.ReverseByType(nameof(TalonSRX), HalData()["pwm"][2]["raw_value"]), 1);
         Assert.AreEqual(PWMHelpers.ReverseByType(2), 1);
         Assert.AreEqual(HalData()["pwm"][2]["value"], 1);
     }
 }
 public void TestTalonSRXInitialized()
 {
     using (TalonSRX t = new TalonSRX(2))
         Assert.AreEqual(HalData()["pwm"][2]["type"], "talonsrx");
 }
        public static IntPtr c_TalonSRX_Create(int deviceNumber, int controlPeriodMs)
        {
            if (halData["CAN"].ContainsKey(deviceNumber))
            {
                throw new ArgumentOutOfRangeException(nameof(deviceNumber), "Device Already Allocated.");
            }
            halData["CAN"][deviceNumber] = new NotifyDict<dynamic, dynamic>()
            {
                ["type"] = "talonsrx",
                ["value"] = 0,
                ["params"] = new NotifyDict<dynamic, dynamic>()
                {
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot0_P] = 1.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot0_I] = 2.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot0_D] = 3.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot0_F] = 4.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot0_IZone] = 5.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot0_CloseLoopRampRate] = 6.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot1_P] = 11.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot1_I] = 12.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot1_D] = 13.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot1_F] = 14.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot1_IZone] = 15.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSlot1_CloseLoopRampRate] = 16.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSoftLimitForThreshold] = 21.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSoftLimitRevThreshold] = 22.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSoftLimitForEnable] = 23.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileParamSoftLimitRevEnable] = 24.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eOnBoot_BrakeMode] = 31.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eOnBoot_LimitSwitch_Forward_NormallyClosed] = 32.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eOnBoot_LimitSwitch_Reverse_NormallyClosed] = 33.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eOnBoot_LimitSwitch_Forward_Disable] = 34.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eOnBoot_LimitSwitch_Reverse_Disable] = 35.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFault_OverTemp] = 41.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFault_UnderVoltage] = 42.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFault_ForLim] = 43.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFault_RevLim] = 44.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFault_HardwareFailure] = 45.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFault_ForSoftLim] = 46.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFault_RevSoftLim] = 47.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eStckyFault_OverTemp] = 48.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eStckyFault_UnderVoltage] = 49.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eStckyFault_ForLim] = 50.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eStckyFault_RevLim] = 51.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eStckyFault_ForSoftLim] = 52.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eStckyFault_RevSoftLim] = 53.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eAppliedThrottle] = 61.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eCloseLoopErr] = 62.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFeedbackDeviceSelect] = 63.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eRevMotDuringCloseLoopEn] = 64.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eModeSelect] = 65.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eProfileSlotSelect] = 66.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eRampThrottle] = 67.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eRevFeedbackSensor] = 68.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eLimitSwitchEn] = 69.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eLimitSwitchClosedFor] = 70.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eLimitSwitchClosedRev] = 71.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eSensorPosition] = 73.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eSensorVelocity] = 74.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eCurrent] = 75.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eBrakeIsEnabled] = 76.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eEncPosition] = 77.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eEncVel] = 78.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eEncIndexRiseEvents] = 79.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eQuadApin] = 80.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eQuadBpin] = 81.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eQuadIdxpin] = 82.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eAnalogInWithOv] = 83.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eAnalogInVel] = 84.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eTemp] = 85.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eBatteryV] = 86.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eResetCount] = 87.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eResetFlags] = 88.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eFirmVers] = 89.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eSettingsChanged] = 90.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.eQuadFilterEn] = 91.0,
                    [(int)HAL_Base.HALCanTalonSRX.ParamID.ePidIaccum] = 93.0,
                },

                ["fault_overtemp"] = 0,
                ["fault_undervoltage"] = 0,
                ["fault_forlim"] = 0,
                ["fault_revlim"] = 0,
                ["fault_hwfailure"] = 0,
                ["fault_forsoftlim"] = 0,
                ["fault_revsoftlim"] = 0,
                ["stickyfault_overtemp"] = 0,
                ["stickyfault_undervoltage"] = 0,
                ["stickyfault_forlim"] = 0,
                ["stickyfault_revlim"] = 0,
                ["stickyfault_forsoftlim"] = 0,
                ["stickyfault_revsoftlim"] = 0,
                ["applied_throttle"] = 0,
                ["closeloop_err"] = 0,
                ["feedback_device_select"] = 0,
                ["mode_select"] = 0,
                ["limit_switch_en"] = 0,
                ["limit_switch_closed_for"] = 0,
                ["limit_switch_closed_rev"] = 0,
                ["sensor_position"] = 0,
                ["sensor_velocity"] = 0,
                ["current"] = 0,
                ["brake_enabled"] = 0,
                ["enc_position"] = 0,
                ["enc_velocity"] = 0,
                ["enc_index_rise_events"] = 0,
                ["quad_apin"] = 0,
                ["quad_bpin"] = 0,
                ["quad_idxpin"] = 0,
                ["analog_in_with_ov"] = 0,
                ["analog_in_vel"] = 0,
                ["temp"] = 0,
                ["battery"] = 0,
                ["reset_count"] = 0,
                ["reset_flags"] = 0,
                ["firmware_version"] = 0,
                ["override_limit_switch"] = 0,

                ["feedback_device"] = null,
                ["rev_motor_during_close_loop"] = null,
                ["override_braketype"] = null,
                ["profile_slot_select"] = null,
                ["ramp_throttle"] = null,
                ["rev_feedback_sensor"] = null
            };


            TalonSRX srx = new TalonSRX { deviceNumber = deviceNumber };
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(srx));
            Marshal.StructureToPtr(srx, ptr, true);
            return ptr;
        }