001/* 002 * Copyright (C) Cross The Road Electronics. All rights reserved. 003 * License information can be found in CTRE_LICENSE.txt 004 * For support and suggestions contact support@ctr-electronics.com or file 005 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases 006 */ 007package com.ctre.phoenix6.configs; 008 009import com.ctre.phoenix6.StatusCode; 010import com.ctre.phoenix6.hardware.DeviceIdentifier; 011import com.ctre.phoenix6.configs.jni.ConfigJNI; 012import com.ctre.phoenix6.spns.*; 013 014/** 015 * Class for CANrange, a CAN based Time of Flight (ToF) sensor that measures the 016 * distance to the front of the device. 017 * 018 * This handles applying and refreshing the configurations for the 019 * {@link com.ctre.phoenix6.hardware.CANrange}. 020 */ 021public class CANrangeConfigurator extends ParentConfigurator { 022 public CANrangeConfigurator(DeviceIdentifier id) { 023 super(id); 024 } 025 026 /** 027 * Applies the contents of the specified config to the device. 028 * <p> 029 * This will wait up to {@link #DefaultTimeoutSeconds}. 030 * <p> 031 * Call to apply the selected configs. 032 * 033 * @param configs Configs to apply against. 034 * @return Status code of applying the configs 035 */ 036 public final StatusCode apply(CANrangeConfiguration configs) { 037 return apply(configs, DefaultTimeoutSeconds); 038 } 039 040 /** 041 * Applies the contents of the specified config to the device. 042 * <p> 043 * Call to apply the selected configs. 044 * 045 * @param configs Configs to apply against. 046 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 047 * @return Status code of applying the configs 048 */ 049 public final StatusCode apply(CANrangeConfiguration configs, double timeoutSeconds) { 050 return setConfigsPrivate(configs.serialize(), timeoutSeconds, configs.FutureProofConfigs, false); 051 } 052 053 /** 054 * Applies the contents of the specified config to the device. 055 * <p> 056 * This will wait up to {@link #DefaultTimeoutSeconds}. 057 * <p> 058 * Call to apply the selected configs. 059 * 060 * @param configs Configs to apply against. 061 * @return Status code of applying the configs 062 */ 063 public final StatusCode apply(CustomParamsConfigs configs) { 064 return apply(configs, DefaultTimeoutSeconds); 065 } 066 067 /** 068 * Applies the contents of the specified config to the device. 069 * <p> 070 * Call to apply the selected configs. 071 * 072 * @param configs Configs to apply against. 073 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 074 * @return Status code of applying the configs 075 */ 076 public final StatusCode apply(CustomParamsConfigs configs, double timeoutSeconds) { 077 return setConfigsPrivate(configs.serialize(), timeoutSeconds, false, false); 078 } 079 080 /** 081 * Applies the contents of the specified config to the device. 082 * <p> 083 * This will wait up to {@link #DefaultTimeoutSeconds}. 084 * <p> 085 * Call to apply the selected configs. 086 * 087 * @param configs Configs to apply against. 088 * @return Status code of applying the configs 089 */ 090 public final StatusCode apply(ToFParamsConfigs configs) { 091 return apply(configs, DefaultTimeoutSeconds); 092 } 093 094 /** 095 * Applies the contents of the specified config to the device. 096 * <p> 097 * Call to apply the selected configs. 098 * 099 * @param configs Configs to apply against. 100 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 101 * @return Status code of applying the configs 102 */ 103 public final StatusCode apply(ToFParamsConfigs configs, double timeoutSeconds) { 104 return setConfigsPrivate(configs.serialize(), timeoutSeconds, false, false); 105 } 106 107 /** 108 * Applies the contents of the specified config to the device. 109 * <p> 110 * This will wait up to {@link #DefaultTimeoutSeconds}. 111 * <p> 112 * Call to apply the selected configs. 113 * 114 * @param configs Configs to apply against. 115 * @return Status code of applying the configs 116 */ 117 public final StatusCode apply(ProximityParamsConfigs configs) { 118 return apply(configs, DefaultTimeoutSeconds); 119 } 120 121 /** 122 * Applies the contents of the specified config to the device. 123 * <p> 124 * Call to apply the selected configs. 125 * 126 * @param configs Configs to apply against. 127 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 128 * @return Status code of applying the configs 129 */ 130 public final StatusCode apply(ProximityParamsConfigs configs, double timeoutSeconds) { 131 return setConfigsPrivate(configs.serialize(), timeoutSeconds, false, false); 132 } 133 134 /** 135 * Applies the contents of the specified config to the device. 136 * <p> 137 * This will wait up to {@link #DefaultTimeoutSeconds}. 138 * <p> 139 * Call to apply the selected configs. 140 * 141 * @param configs Configs to apply against. 142 * @return Status code of applying the configs 143 */ 144 public final StatusCode apply(FovParamsConfigs configs) { 145 return apply(configs, DefaultTimeoutSeconds); 146 } 147 148 /** 149 * Applies the contents of the specified config to the device. 150 * <p> 151 * Call to apply the selected configs. 152 * 153 * @param configs Configs to apply against. 154 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 155 * @return Status code of applying the configs 156 */ 157 public final StatusCode apply(FovParamsConfigs configs, double timeoutSeconds) { 158 return setConfigsPrivate(configs.serialize(), timeoutSeconds, false, false); 159 } 160 161 /** 162 * Refreshes the values of the specified config group. 163 * <p> 164 * This will wait up to {@link #DefaultTimeoutSeconds}. 165 * <p> 166 * Call to refresh the selected configs from the device. 167 * 168 * @param configs The configs to refresh 169 * @return Status code of refreshing the configs 170 */ 171 public final StatusCode refresh(CANrangeConfiguration configs) { 172 return refresh(configs, DefaultTimeoutSeconds); 173 } 174 175 /** 176 * Refreshes the values of the specified config group. 177 * <p> 178 * Call to refresh the selected configs from the device. 179 * 180 * @param configs The configs to refresh 181 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 182 * @return Status code of refreshing the configs 183 */ 184 public final StatusCode refresh(CANrangeConfiguration configs, double timeoutSeconds) { 185 StringBuilder serializedString = new StringBuilder(); 186 StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds); 187 if (err == StatusCode.OK) { 188 /* Only deserialize if we successfully got configs */ 189 configs.deserialize(serializedString.toString()); 190 } 191 return err; 192 } 193 194 /** 195 * Refreshes the values of the specified config group. 196 * <p> 197 * This will wait up to {@link #DefaultTimeoutSeconds}. 198 * <p> 199 * Call to refresh the selected configs from the device. 200 * 201 * @param configs The configs to refresh 202 * @return Status code of refreshing the configs 203 */ 204 public final StatusCode refresh(CustomParamsConfigs configs) { 205 return refresh(configs, DefaultTimeoutSeconds); 206 } 207 208 /** 209 * Refreshes the values of the specified config group. 210 * <p> 211 * Call to refresh the selected configs from the device. 212 * 213 * @param configs The configs to refresh 214 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 215 * @return Status code of refreshing the configs 216 */ 217 public final StatusCode refresh(CustomParamsConfigs configs, double timeoutSeconds) { 218 StringBuilder serializedString = new StringBuilder(); 219 StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds); 220 if (err == StatusCode.OK) { 221 /* Only deserialize if we successfully got configs */ 222 configs.deserialize(serializedString.toString()); 223 } 224 return err; 225 } 226 227 /** 228 * Refreshes the values of the specified config group. 229 * <p> 230 * This will wait up to {@link #DefaultTimeoutSeconds}. 231 * <p> 232 * Call to refresh the selected configs from the device. 233 * 234 * @param configs The configs to refresh 235 * @return Status code of refreshing the configs 236 */ 237 public final StatusCode refresh(ToFParamsConfigs configs) { 238 return refresh(configs, DefaultTimeoutSeconds); 239 } 240 241 /** 242 * Refreshes the values of the specified config group. 243 * <p> 244 * Call to refresh the selected configs from the device. 245 * 246 * @param configs The configs to refresh 247 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 248 * @return Status code of refreshing the configs 249 */ 250 public final StatusCode refresh(ToFParamsConfigs configs, double timeoutSeconds) { 251 StringBuilder serializedString = new StringBuilder(); 252 StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds); 253 if (err == StatusCode.OK) { 254 /* Only deserialize if we successfully got configs */ 255 configs.deserialize(serializedString.toString()); 256 } 257 return err; 258 } 259 260 /** 261 * Refreshes the values of the specified config group. 262 * <p> 263 * This will wait up to {@link #DefaultTimeoutSeconds}. 264 * <p> 265 * Call to refresh the selected configs from the device. 266 * 267 * @param configs The configs to refresh 268 * @return Status code of refreshing the configs 269 */ 270 public final StatusCode refresh(ProximityParamsConfigs configs) { 271 return refresh(configs, DefaultTimeoutSeconds); 272 } 273 274 /** 275 * Refreshes the values of the specified config group. 276 * <p> 277 * Call to refresh the selected configs from the device. 278 * 279 * @param configs The configs to refresh 280 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 281 * @return Status code of refreshing the configs 282 */ 283 public final StatusCode refresh(ProximityParamsConfigs configs, double timeoutSeconds) { 284 StringBuilder serializedString = new StringBuilder(); 285 StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds); 286 if (err == StatusCode.OK) { 287 /* Only deserialize if we successfully got configs */ 288 configs.deserialize(serializedString.toString()); 289 } 290 return err; 291 } 292 293 /** 294 * Refreshes the values of the specified config group. 295 * <p> 296 * This will wait up to {@link #DefaultTimeoutSeconds}. 297 * <p> 298 * Call to refresh the selected configs from the device. 299 * 300 * @param configs The configs to refresh 301 * @return Status code of refreshing the configs 302 */ 303 public final StatusCode refresh(FovParamsConfigs configs) { 304 return refresh(configs, DefaultTimeoutSeconds); 305 } 306 307 /** 308 * Refreshes the values of the specified config group. 309 * <p> 310 * Call to refresh the selected configs from the device. 311 * 312 * @param configs The configs to refresh 313 * @param timeoutSeconds Maximum amount of time to wait when performing configuration 314 * @return Status code of refreshing the configs 315 */ 316 public final StatusCode refresh(FovParamsConfigs configs, double timeoutSeconds) { 317 StringBuilder serializedString = new StringBuilder(); 318 StatusCode err = getConfigsPrivate(serializedString, timeoutSeconds); 319 if (err == StatusCode.OK) { 320 /* Only deserialize if we successfully got configs */ 321 configs.deserialize(serializedString.toString()); 322 } 323 return err; 324 } 325 326 327 /** 328 * Clear the sticky faults in the device. 329 * <p> 330 * This typically has no impact on the device functionality. Instead, 331 * it just clears telemetry faults that are accessible via API and 332 * Tuner Self-Test. 333 * <p> 334 * This will wait up to {@link #DefaultTimeoutSeconds}. 335 * <p> 336 * This is available in the configurator in case the user wants 337 * to initialize their device entirely without passing a device 338 * reference down to the code that performs the initialization. 339 * In this case, the user passes down the configurator object 340 * and performs all the initialization code on the object. 341 * 342 * @return StatusCode of the set command 343 */ 344 public final StatusCode clearStickyFaults() { 345 return clearStickyFaults(DefaultTimeoutSeconds); 346 } 347 /** 348 * Clear the sticky faults in the device. 349 * <p> 350 * This typically has no impact on the device functionality. Instead, 351 * it just clears telemetry faults that are accessible via API and 352 * Tuner Self-Test. 353 * <p> 354 * This is available in the configurator in case the user wants 355 * to initialize their device entirely without passing a device 356 * reference down to the code that performs the initialization. 357 * In this case, the user passes down the configurator object 358 * and performs all the initialization code on the object. 359 * 360 * @param timeoutSeconds Maximum time to wait up to in seconds. 361 * @return StatusCode of the set command 362 */ 363 public final StatusCode clearStickyFaults(double timeoutSeconds) { 364 String serialized = ConfigJNI.Serializedouble(SpnValue.SPN_ClearStickyFaults.value, 0); 365 return setConfigsPrivate(serialized, timeoutSeconds, false, true); 366 } 367 368 /** 369 * Clear sticky fault: Hardware fault occurred 370 * <p> 371 * This will wait up to {@link #DefaultTimeoutSeconds}. 372 * <p> 373 * This is available in the configurator in case the user wants 374 * to initialize their device entirely without passing a device 375 * reference down to the code that performs the initialization. 376 * In this case, the user passes down the configurator object 377 * and performs all the initialization code on the object. 378 * 379 * @return StatusCode of the set command 380 */ 381 public final StatusCode clearStickyFault_Hardware() { 382 return clearStickyFault_Hardware(DefaultTimeoutSeconds); 383 } 384 /** 385 * Clear sticky fault: Hardware fault occurred 386 * <p> 387 * This is available in the configurator in case the user wants 388 * to initialize their device entirely without passing a device 389 * reference down to the code that performs the initialization. 390 * In this case, the user passes down the configurator object 391 * and performs all the initialization code on the object. 392 * 393 * @param timeoutSeconds Maximum time to wait up to in seconds. 394 * @return StatusCode of the set command 395 */ 396 public final StatusCode clearStickyFault_Hardware(double timeoutSeconds) { 397 String serialized = ConfigJNI.Serializedouble(SpnValue.ClearStickyFault_Hardware.value, 0); 398 return setConfigsPrivate(serialized, timeoutSeconds, false, true); 399 } 400 401 /** 402 * Clear sticky fault: Device supply voltage dropped to near brownout 403 * levels 404 * <p> 405 * This will wait up to {@link #DefaultTimeoutSeconds}. 406 * <p> 407 * This is available in the configurator in case the user wants 408 * to initialize their device entirely without passing a device 409 * reference down to the code that performs the initialization. 410 * In this case, the user passes down the configurator object 411 * and performs all the initialization code on the object. 412 * 413 * @return StatusCode of the set command 414 */ 415 public final StatusCode clearStickyFault_Undervoltage() { 416 return clearStickyFault_Undervoltage(DefaultTimeoutSeconds); 417 } 418 /** 419 * Clear sticky fault: Device supply voltage dropped to near brownout 420 * levels 421 * <p> 422 * This is available in the configurator in case the user wants 423 * to initialize their device entirely without passing a device 424 * reference down to the code that performs the initialization. 425 * In this case, the user passes down the configurator object 426 * and performs all the initialization code on the object. 427 * 428 * @param timeoutSeconds Maximum time to wait up to in seconds. 429 * @return StatusCode of the set command 430 */ 431 public final StatusCode clearStickyFault_Undervoltage(double timeoutSeconds) { 432 String serialized = ConfigJNI.Serializedouble(SpnValue.ClearStickyFault_Undervoltage.value, 0); 433 return setConfigsPrivate(serialized, timeoutSeconds, false, true); 434 } 435 436 /** 437 * Clear sticky fault: Device boot while detecting the enable signal 438 * <p> 439 * This will wait up to {@link #DefaultTimeoutSeconds}. 440 * <p> 441 * This is available in the configurator in case the user wants 442 * to initialize their device entirely without passing a device 443 * reference down to the code that performs the initialization. 444 * In this case, the user passes down the configurator object 445 * and performs all the initialization code on the object. 446 * 447 * @return StatusCode of the set command 448 */ 449 public final StatusCode clearStickyFault_BootDuringEnable() { 450 return clearStickyFault_BootDuringEnable(DefaultTimeoutSeconds); 451 } 452 /** 453 * Clear sticky fault: Device boot while detecting the enable signal 454 * <p> 455 * This is available in the configurator in case the user wants 456 * to initialize their device entirely without passing a device 457 * reference down to the code that performs the initialization. 458 * In this case, the user passes down the configurator object 459 * and performs all the initialization code on the object. 460 * 461 * @param timeoutSeconds Maximum time to wait up to in seconds. 462 * @return StatusCode of the set command 463 */ 464 public final StatusCode clearStickyFault_BootDuringEnable(double timeoutSeconds) { 465 String serialized = ConfigJNI.Serializedouble(SpnValue.ClearStickyFault_BootDuringEnable.value, 0); 466 return setConfigsPrivate(serialized, timeoutSeconds, false, true); 467 } 468 469 /** 470 * Clear sticky fault: An unlicensed feature is in use, device may not 471 * behave as expected. 472 * <p> 473 * This will wait up to {@link #DefaultTimeoutSeconds}. 474 * <p> 475 * This is available in the configurator in case the user wants 476 * to initialize their device entirely without passing a device 477 * reference down to the code that performs the initialization. 478 * In this case, the user passes down the configurator object 479 * and performs all the initialization code on the object. 480 * 481 * @return StatusCode of the set command 482 */ 483 public final StatusCode clearStickyFault_UnlicensedFeatureInUse() { 484 return clearStickyFault_UnlicensedFeatureInUse(DefaultTimeoutSeconds); 485 } 486 /** 487 * Clear sticky fault: An unlicensed feature is in use, device may not 488 * behave as expected. 489 * <p> 490 * This is available in the configurator in case the user wants 491 * to initialize their device entirely without passing a device 492 * reference down to the code that performs the initialization. 493 * In this case, the user passes down the configurator object 494 * and performs all the initialization code on the object. 495 * 496 * @param timeoutSeconds Maximum time to wait up to in seconds. 497 * @return StatusCode of the set command 498 */ 499 public final StatusCode clearStickyFault_UnlicensedFeatureInUse(double timeoutSeconds) { 500 String serialized = ConfigJNI.Serializedouble(SpnValue.ClearStickyFault_UnlicensedFeatureInUse.value, 0); 501 return setConfigsPrivate(serialized, timeoutSeconds, false, true); 502 } 503}