From a04b0a98b59a9db618acb539e9e4915fb05b5902 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Tue, 12 Mar 2024 00:07:05 +0200 Subject: [PATCH] Feat(maccel) +MA_CPI in VIA --- maccel/assets/charybdis_3x5.json | 13 +++++++++++++ maccel/assets/charybdis_3x6.json | 13 +++++++++++++ maccel/assets/charybdis_4x6.json | 13 +++++++++++++ maccel/assets/dilemma_max.json | 13 +++++++++++++ maccel/assets/dilemma_v2.json | 13 +++++++++++++ maccel/assets/via.json | 13 +++++++++++++ maccel/maccel_via.c | 32 +++++++++++++++++++++++--------- 7 files changed, 101 insertions(+), 9 deletions(-) diff --git a/maccel/assets/charybdis_3x5.json b/maccel/assets/charybdis_3x5.json index a3b61d96b21c..0b316ce4ed48 100644 --- a/maccel/assets/charybdis_3x5.json +++ b/maccel/assets/charybdis_3x5.json @@ -19,6 +19,19 @@ 5 ] }, + { + "label": "CPI", + "type": "range", + "options": [ + 10, + 2000 + ], + "content": [ + "id_maccel_cpi", + 24, + 6 + ] + }, { "label": "Takeoff", "type": "range", diff --git a/maccel/assets/charybdis_3x6.json b/maccel/assets/charybdis_3x6.json index 5b86bc860467..f1d0eb39ee7c 100644 --- a/maccel/assets/charybdis_3x6.json +++ b/maccel/assets/charybdis_3x6.json @@ -23,6 +23,19 @@ 5 ] }, + { + "label": "CPI", + "type": "range", + "options": [ + 10, + 2000 + ], + "content": [ + "id_maccel_cpi", + 24, + 6 + ] + }, { "label": "Takeoff", "type": "range", diff --git a/maccel/assets/charybdis_4x6.json b/maccel/assets/charybdis_4x6.json index 53be2376114f..10772b3dc1bf 100644 --- a/maccel/assets/charybdis_4x6.json +++ b/maccel/assets/charybdis_4x6.json @@ -19,6 +19,19 @@ 5 ] }, + { + "label": "CPI", + "type": "range", + "options": [ + 10, + 2000 + ], + "content": [ + "id_maccel_cpi", + 24, + 6 + ] + }, { "label": "Takeoff", "type": "range", diff --git a/maccel/assets/dilemma_max.json b/maccel/assets/dilemma_max.json index 4b156df6df9a..e374428e7395 100644 --- a/maccel/assets/dilemma_max.json +++ b/maccel/assets/dilemma_max.json @@ -23,6 +23,19 @@ 5 ] }, + { + "label": "CPI", + "type": "range", + "options": [ + 10, + 2000 + ], + "content": [ + "id_maccel_cpi", + 24, + 6 + ] + }, { "label": "Takeoff", "type": "range", diff --git a/maccel/assets/dilemma_v2.json b/maccel/assets/dilemma_v2.json index 2abf3acfd6eb..fad9a7e4dda2 100644 --- a/maccel/assets/dilemma_v2.json +++ b/maccel/assets/dilemma_v2.json @@ -19,6 +19,19 @@ 5 ] }, + { + "label": "CPI", + "type": "range", + "options": [ + 10, + 2000 + ], + "content": [ + "id_maccel_cpi", + 24, + 6 + ] + }, { "label": "Takeoff", "type": "range", diff --git a/maccel/assets/via.json b/maccel/assets/via.json index 9536c4da44f1..4a7c721cd5bb 100644 --- a/maccel/assets/via.json +++ b/maccel/assets/via.json @@ -13,6 +13,19 @@ 5 ] }, + { + "label": "CPI", + "type": "range", + "options": [ + 10, + 2000 + ], + "content": [ + "id_maccel_cpi", + 24, + 6 + ] + }, { "label": "Takeoff", "type": "range", diff --git a/maccel/maccel_via.c b/maccel/maccel_via.c index 2fd2df61921f..de9f133a7c99 100644 --- a/maccel/maccel_via.c +++ b/maccel/maccel_via.c @@ -16,11 +16,12 @@ enum via_maccel_channel { }; enum via_maccel_ids { // clang-format off - id_maccel_takeoff = 1, - id_maccel_growth_rate = 2, - id_maccel_offset = 3, - id_maccel_limit = 4, - id_maccel_enabled = 5 + id_maccel_takeoff = 1, + id_maccel_growth_rate = 2, + id_maccel_offset = 3, + id_maccel_limit = 4, + id_maccel_enabled = 5, + id_maccel_cpi = 6 // clang-format on }; @@ -33,13 +34,20 @@ void maccel_config_set_value(uint8_t *data) { uint8_t *value_data = &(data[1]); switch (*value_id) { + case id_maccel_cpi: { + g_maccel_config.cpi = COMBINE_UINT8(value_data[0], value_data[1]); +#ifdef MACCEL_DEBUG + printf("MACCEL:via: CPI: %3i tko: %.3f grw: %.3f ofs: %.3f LMT: %.3f\n", g_maccel_config.cpi, g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); +#endif + break; + } case id_maccel_takeoff: { uint16_t takeoff = COMBINE_UINT8(value_data[0], value_data[1]); // calc uint16 to float: takeoff moves comma and shifts by 0.5, so that 0.5..6.5 fits into 0..60k g_maccel_config.takeoff = (takeoff / 10000.0f) + 0.5; #ifdef MACCEL_DEBUG - printf("MACCEL:via: TKO: %.3f grw: %.3f ofs: %.3f lmt: %.3f\n", g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); + printf("MACCEL:via: cpi: %3i TKO: %.3f grw: %.3f ofs: %.3f lmt: %.3f\n", g_maccel_config.cpi, g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); #endif break; } @@ -49,7 +57,7 @@ void maccel_config_set_value(uint8_t *data) { // calc uint16 to float: growth_rate only moves the comma g_maccel_config.growth_rate = growth_rate / 10000.0f; #ifdef MACCEL_DEBUG - printf("MACCEL:via: tko: %.3f GRW: %.3f ofs: %.3f lmt: %.3f\n", g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); + printf("MACCEL:via: cpi: %3i tko: %.3f GRW: %.3f ofs: %.3f lmt: %.3f\n", g_maccel_config.cpi, g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); #endif break; } @@ -59,7 +67,7 @@ void maccel_config_set_value(uint8_t *data) { // calc uint16 to float: offset moves comma and shifts by 3, so that -3..3 fits into 0..60k g_maccel_config.offset = (offset / 10000.0f) - 3; #ifdef MACCEL_DEBUG - printf("MACCEL:via: tko: %.3f grw: %.3f OFS: %.3f lmt: %.3f\n", g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); + printf("MACCEL:via: cpi: %3i tko: %.3f grw: %.3f OFS: %.3f lmt: %.3f\n", g_maccel_config.cpi, g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); #endif break; } @@ -69,7 +77,7 @@ void maccel_config_set_value(uint8_t *data) { // calc uint16 to float: offset moves comma, divides by 2 and shifts by 1, so that 1..14 fits into 0..60k g_maccel_config.limit = (limit / 5000.0f) + 1; #ifdef MACCEL_DEBUG - printf("MACCEL:via: tko: %.3f grw: %.3f ofs: %.3f LMT: %.3f\n", g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); + printf("MACCEL:via: cpi: %3i tko: %.3f grw: %.3f ofs: %.3f LMT: %.3f\n", g_maccel_config.cpi, g_maccel_config.takeoff, g_maccel_config.growth_rate, g_maccel_config.offset, g_maccel_config.limit); #endif break; } @@ -87,6 +95,12 @@ void maccel_config_get_value(uint8_t *data) { uint8_t *value_data = &(data[1]); switch (*value_id) { + case id_maccel_cpi: { + uint16_t cpi = g_maccel_config.cpi; + value_data[0] = cpi >> 8; + value_data[1] = cpi & 0xFF; + break; + } case id_maccel_takeoff: { uint16_t takeoff = (g_maccel_config.takeoff - 0.5) * 5000; value_data[0] = takeoff >> 8;