2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file fsio_impl.cpp
|
|
|
|
* @brief FSIO as it's used for GPIO
|
|
|
|
*
|
2022-02-01 23:03:31 -08:00
|
|
|
* TODO: rename this file, FSIO is gone!
|
2019-09-11 17:46:50 -07:00
|
|
|
*
|
2015-07-10 06:01:56 -07:00
|
|
|
* @date Oct 5, 2014
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2022-07-14 04:52:58 -07:00
|
|
|
#include "script_impl.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-14 07:39:47 -08:00
|
|
|
static fsio8_Map3D_f32t scriptTable1;
|
|
|
|
static fsio8_Map3D_u8t scriptTable2;
|
|
|
|
static fsio8_Map3D_u8t scriptTable3;
|
|
|
|
static fsio8_Map3D_u8t scriptTable4;
|
2016-04-04 07:01:43 -07:00
|
|
|
|
2021-11-14 07:39:47 -08:00
|
|
|
ValueProvider3D *getscriptTable(int index) {
|
2019-07-12 05:31:38 -07:00
|
|
|
switch (index) {
|
|
|
|
default:
|
2021-11-14 07:39:47 -08:00
|
|
|
return &scriptTable1;
|
2019-07-12 05:31:38 -07:00
|
|
|
case 1:
|
2021-11-14 07:39:47 -08:00
|
|
|
return &scriptTable2;
|
2019-07-12 05:31:38 -07:00
|
|
|
case 2:
|
2021-11-14 07:39:47 -08:00
|
|
|
return &scriptTable3;
|
2019-07-12 05:31:38 -07:00
|
|
|
case 3:
|
2021-11-14 07:39:47 -08:00
|
|
|
return &scriptTable4;
|
2019-07-12 05:31:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-14 09:51:41 -08:00
|
|
|
// todo: template this copy-pasta
|
2021-11-05 12:25:29 -07:00
|
|
|
/**
|
|
|
|
* @return zero-based index of curve with given name
|
|
|
|
*/
|
2022-08-28 06:43:21 -07:00
|
|
|
expected<int> getCurveIndexByName(const char *name) {
|
2021-11-05 12:25:29 -07:00
|
|
|
for (int i = 0;i<SCRIPT_CURVE_COUNT;i++) {
|
|
|
|
if (strEqualCaseInsensitive(name, engineConfiguration->scriptCurveName[i])) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2022-08-28 06:43:21 -07:00
|
|
|
|
|
|
|
return unexpected;
|
2021-11-05 12:25:29 -07:00
|
|
|
}
|
|
|
|
|
2022-08-28 06:43:21 -07:00
|
|
|
expected<int> getTableIndexByName(const char *name) {
|
2021-11-13 07:02:01 -08:00
|
|
|
for (int i = 0;i<SCRIPT_TABLE_COUNT;i++) {
|
|
|
|
if (strEqualCaseInsensitive(name, engineConfiguration->scriptTableName[i])) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2022-08-28 06:43:21 -07:00
|
|
|
|
|
|
|
return unexpected;
|
2021-11-13 07:02:01 -08:00
|
|
|
}
|
|
|
|
|
2022-08-28 06:43:21 -07:00
|
|
|
expected<int> getSettingIndexByName(const char *name) {
|
2021-11-14 09:51:41 -08:00
|
|
|
for (int i = 0;i<SCRIPT_SETTING_COUNT;i++) {
|
|
|
|
if (strEqualCaseInsensitive(name, engineConfiguration->scriptSettingName[i])) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2022-08-28 06:43:21 -07:00
|
|
|
|
|
|
|
return unexpected;
|
2021-11-14 09:51:41 -08:00
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
float getCurveValue(int index, float key) {
|
2021-11-04 20:22:37 -07:00
|
|
|
// not great code at all :(
|
|
|
|
switch (index) {
|
|
|
|
default:
|
2022-05-01 20:43:43 -07:00
|
|
|
return interpolate2d(key, config->scriptCurve1Bins, config->scriptCurve1);
|
2021-11-04 20:59:04 -07:00
|
|
|
case 1:
|
2022-05-01 20:43:43 -07:00
|
|
|
return interpolate2d(key, config->scriptCurve2Bins, config->scriptCurve2);
|
2021-11-04 20:59:04 -07:00
|
|
|
case 2:
|
2022-05-01 20:43:43 -07:00
|
|
|
return interpolate2d(key, config->scriptCurve3Bins, config->scriptCurve3);
|
2021-11-04 20:59:04 -07:00
|
|
|
case 3:
|
2022-05-01 20:43:43 -07:00
|
|
|
return interpolate2d(key, config->scriptCurve4Bins, config->scriptCurve4);
|
2021-11-04 20:59:04 -07:00
|
|
|
case 4:
|
2022-05-01 20:43:43 -07:00
|
|
|
return interpolate2d(key, config->scriptCurve5Bins, config->scriptCurve5);
|
2021-11-04 20:59:04 -07:00
|
|
|
case 5:
|
2022-05-01 20:43:43 -07:00
|
|
|
return interpolate2d(key, config->scriptCurve6Bins, config->scriptCurve6);
|
2021-11-04 20:22:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-14 04:52:58 -07:00
|
|
|
void initScriptImpl() {
|
2021-11-14 07:39:47 -08:00
|
|
|
scriptTable1.init(config->scriptTable1, config->scriptTable1LoadBins,
|
|
|
|
config->scriptTable1RpmBins);
|
|
|
|
scriptTable2.init(config->scriptTable2, config->scriptTable2LoadBins,
|
|
|
|
config->scriptTable2RpmBins);
|
|
|
|
scriptTable3.init(config->scriptTable3, config->scriptTable3LoadBins,
|
|
|
|
config->scriptTable3RpmBins);
|
|
|
|
scriptTable4.init(config->scriptTable4, config->scriptTable4LoadBins,
|
|
|
|
config->scriptTable4RpmBins);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|