X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fkernel%2Fao_config.c;h=bfc0325e00d9406c59c51cc2d7fd9a23c8682310;hb=f7c8f0b14cf19804106860a5689cf1f37df20669;hp=e4fc73c99059aadac5c7e9360f702a43770fb7d6;hpb=9416e5d71dc57df6612f62451433a34bf669b2cc;p=fw%2Faltos diff --git a/src/kernel/ao_config.c b/src/kernel/ao_config.c index e4fc73c9..bfc0325e 100644 --- a/src/kernel/ao_config.c +++ b/src/kernel/ao_config.c @@ -190,7 +190,7 @@ _ao_config_get(void) if (minor < 14) ao_config.radio_amp = AO_CONFIG_DEFAULT_RADIO_AMP; #endif -#if HAS_GYRO +#if HAS_IMU if (minor < 15) { ao_config.accel_zero_along = 0; ao_config.accel_zero_across = 0; @@ -367,6 +367,8 @@ ao_config_send_frequency_set(void) #if HAS_FLIGHT +#if HAS_BARO + static void ao_config_main_deploy_show(void) { @@ -385,13 +387,15 @@ ao_config_main_deploy_set(void) _ao_config_edit_finish(); } +#endif + #if HAS_ACCEL static void ao_config_accel_calibrate_show(void) { printf("Accel cal +1g: %d -1g: %d\n", ao_config.accel_plus_g, ao_config.accel_minus_g); -#if HAS_GYRO +#if HAS_IMU printf ("IMU cal along %d across %d through %d\n", ao_config.accel_zero_along, ao_config.accel_zero_across, @@ -402,7 +406,7 @@ ao_config_accel_calibrate_show(void) #define ACCEL_CALIBRATE_SAMPLES 1024 #define ACCEL_CALIBRATE_SHIFT 10 -#if HAS_GYRO +#if HAS_IMU static int16_t accel_cal_along; static int16_t accel_cal_across; static int16_t accel_cal_through; @@ -414,7 +418,7 @@ ao_config_accel_calibrate_auto(char *orientation) uint16_t i; int32_t accel_total; uint8_t cal_data_ring; -#if HAS_GYRO +#if HAS_IMU int32_t accel_along_total = 0; int32_t accel_across_total = 0; int32_t accel_through_total = 0; @@ -432,7 +436,7 @@ ao_config_accel_calibrate_auto(char *orientation) ao_sleep(&ao_sample_data); while (i && cal_data_ring != ao_sample_data) { accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]); -#if HAS_GYRO +#if HAS_IMU accel_along_total += (int32_t) ao_data_along(&ao_data_ring[cal_data_ring]); accel_across_total += (int32_t) ao_data_across(&ao_data_ring[cal_data_ring]); accel_through_total += (int32_t) ao_data_through(&ao_data_ring[cal_data_ring]); @@ -441,7 +445,7 @@ ao_config_accel_calibrate_auto(char *orientation) i--; } } -#if HAS_GYRO +#if HAS_IMU accel_cal_along = accel_along_total >> ACCEL_CALIBRATE_SHIFT; accel_cal_across = accel_across_total >> ACCEL_CALIBRATE_SHIFT; accel_cal_through = accel_through_total >> ACCEL_CALIBRATE_SHIFT; @@ -453,35 +457,31 @@ static void ao_config_accel_calibrate_set(void) { int16_t up, down; - uint16_t r; -#if HAS_GYRO + bool auto_cal; +#if HAS_IMU int16_t accel_along_up = 0, accel_along_down = 0; int16_t accel_across_up = 0, accel_across_down = 0; int16_t accel_through_up = 0, accel_through_down = 0; #endif - r = ao_cmd_decimal(); + up = ao_cmd_decimal(); if (ao_cmd_status != ao_cmd_success) return; - if (r == 0) { + down = ao_cmd_decimal(); + auto_cal = (up == 0 && ao_cmd_status != ao_cmd_success); + if (auto_cal) { up = ao_config_accel_calibrate_auto("up"); -#if HAS_GYRO +#if HAS_IMU accel_along_up = accel_cal_along; accel_across_up = accel_cal_across; accel_through_up = accel_cal_through; #endif down = ao_config_accel_calibrate_auto("down"); -#if HAS_GYRO +#if HAS_IMU accel_along_down = accel_cal_along; accel_across_down = accel_cal_across; accel_through_down = accel_cal_through; #endif - } else { - up = r; - r = ao_cmd_decimal(); - if (ao_cmd_status != ao_cmd_success) - return; - down = r; } if (up >= down) { printf("Invalid accel: up (%d) down (%d)\n", @@ -491,17 +491,32 @@ ao_config_accel_calibrate_set(void) _ao_config_edit_start(); ao_config.accel_plus_g = up; ao_config.accel_minus_g = down; -#if HAS_GYRO - if (r == 0) { +#if HAS_IMU + if (auto_cal) { ao_config.accel_zero_along = (accel_along_up + accel_along_down) / 2; ao_config.accel_zero_across = (accel_across_up + accel_across_down) / 2; ao_config.accel_zero_through = (accel_through_up + accel_through_down) / 2; + } else { + int16_t v; + + v = ao_cmd_decimal(); + if (ao_cmd_status == ao_cmd_success) { + ao_config.accel_zero_along = v; + v = ao_cmd_decimal(); + if (ao_cmd_status == ao_cmd_success) { + ao_config.accel_zero_across = v; + v = ao_cmd_decimal(); + if (ao_cmd_status == ao_cmd_success) + ao_config.accel_zero_through = v; + } + } } #endif _ao_config_edit_finish(); } #endif /* HAS_ACCEL */ +#if HAS_BARO static void ao_config_apogee_delay_show(void) { @@ -537,6 +552,7 @@ ao_config_apogee_lockout_set(void) ao_config.apogee_lockout = r; _ao_config_edit_finish(); } +#endif #endif /* HAS_FLIGHT */ @@ -623,26 +639,26 @@ static void ao_config_log_set(void) { #if FLIGHT_LOG_APPEND - printf("Flight log fixed size %d kB\n", ao_storage_log_max >> 10); + printf("Flight log fixed size %u kB\n", (unsigned) (ao_storage_log_max >> 10)); #else - uint16_t block = (uint16_t) (ao_storage_block >> 10); - uint16_t log_max = (uint16_t) (ao_storage_log_max >> 10); uint32_t r; r = ao_cmd_decimal(); if (ao_cmd_status != ao_cmd_success) return; - if (ao_log_present()) - printf("Storage must be empty before changing log size\n"); - else if (block > 1024 && (r & (block - 1))) - printf("Flight log size must be multiple of %d kB\n", block); - else if (r > log_max) - printf("Flight log max %d kB\n", log_max); - else { - _ao_config_edit_start(); - ao_config.flight_log_max = r << 10; - _ao_config_edit_finish(); + r = r << 10; + if (ao_log_present()) { + if (r != ao_config.flight_log_max) + printf("Storage must be empty before changing log size\n"); + return; + } + if (r > ao_storage_log_max) { + printf("Flight log max %u kB\n", (unsigned) (ao_storage_log_max >> 10)); + return; } + _ao_config_edit_start(); + ao_config.flight_log_max = r & ~(ao_storage_block - 1); + _ao_config_edit_finish(); #endif } #endif /* HAS_LOG */ @@ -988,7 +1004,7 @@ ao_config_save(void); #endif const struct ao_config_var ao_config_vars[] = { -#if HAS_FLIGHT +#if HAS_FLIGHT && HAS_BARO { "m \0Main deploy (m)", ao_config_main_deploy_set, ao_config_main_deploy_show, }, { "d \0Apogee delay (s)", @@ -1033,7 +1049,7 @@ const struct ao_config_var ao_config_vars[] = { ao_config_log_set, ao_config_log_show }, #endif #if HAS_IGNITE - { "i <0 dual, 1 apogee, 2 main>\0Igniter mode", + { "i <0 dual, 1 apogee, 2 main, 3 booster>\0Igniter mode", ao_config_ignite_mode_set, ao_config_ignite_mode_show }, #endif #if HAS_AES