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