Skip to content

Commit

Permalink
Feat(maccel) +MA_CPI in VIA
Browse files Browse the repository at this point in the history
  • Loading branch information
ankostis committed Mar 12, 2024
1 parent 2420605 commit a04b0a9
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 9 deletions.
13 changes: 13 additions & 0 deletions maccel/assets/charybdis_3x5.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
5
]
},
{
"label": "CPI",
"type": "range",
"options": [
10,
2000
],
"content": [
"id_maccel_cpi",
24,
6
]
},
{
"label": "Takeoff",
"type": "range",
Expand Down
13 changes: 13 additions & 0 deletions maccel/assets/charybdis_3x6.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
5
]
},
{
"label": "CPI",
"type": "range",
"options": [
10,
2000
],
"content": [
"id_maccel_cpi",
24,
6
]
},
{
"label": "Takeoff",
"type": "range",
Expand Down
13 changes: 13 additions & 0 deletions maccel/assets/charybdis_4x6.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
5
]
},
{
"label": "CPI",
"type": "range",
"options": [
10,
2000
],
"content": [
"id_maccel_cpi",
24,
6
]
},
{
"label": "Takeoff",
"type": "range",
Expand Down
13 changes: 13 additions & 0 deletions maccel/assets/dilemma_max.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
5
]
},
{
"label": "CPI",
"type": "range",
"options": [
10,
2000
],
"content": [
"id_maccel_cpi",
24,
6
]
},
{
"label": "Takeoff",
"type": "range",
Expand Down
13 changes: 13 additions & 0 deletions maccel/assets/dilemma_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
5
]
},
{
"label": "CPI",
"type": "range",
"options": [
10,
2000
],
"content": [
"id_maccel_cpi",
24,
6
]
},
{
"label": "Takeoff",
"type": "range",
Expand Down
13 changes: 13 additions & 0 deletions maccel/assets/via.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
5
]
},
{
"label": "CPI",
"type": "range",
"options": [
10,
2000
],
"content": [
"id_maccel_cpi",
24,
6
]
},
{
"label": "Takeoff",
"type": "range",
Expand Down
32 changes: 23 additions & 9 deletions maccel/maccel_via.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit a04b0a9

Please sign in to comment.