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