SENT glue to LUA (#4700)

* use tabs

* SENT: Lua glue: getSentValue returns ETB position now

Can be tested with following LUA script:
setTickRate(100)
function onTick()
	pos = getSentValue(1)
	setLuaGauge(1, 10000 * pos)
	print(pos)
end
This commit is contained in:
Andrey G 2022-10-26 13:42:14 +03:00 committed by GitHub
parent 1f6088e56b
commit 6411ef2021
3 changed files with 17 additions and 5 deletions

View File

@ -676,7 +676,7 @@ void configureRusefiLuaHooks(lua_State* l) {
#if EFI_SENT_SUPPORT
lua_register(l, "getSentValue",
[](lua_State* l) {
auto humanIndex = luaL_checkinteger(l, 1);
auto humanIndex = luaL_checkinteger(l, 1);
auto value = getSentValue(humanIndex - 1);
lua_pushnumber(l, value);
return 1;

View File

@ -605,9 +605,21 @@ static void printSentInfo()
}
}
float getSentValue(int index) {
// todo: just return ETB 0 to 100% for now?
return 23;
/* Don't be confused: this actually returns throttle body position */
float getSentValue(size_t index) {
if (index < SENT_CHANNELS_NUM) {
uint16_t sig0, sig1;
sent_channel &ch = channels[index];
if (ch.GetSignals(NULL, &sig0, &sig1) == 0) {
if (sig0 + sig1 == 0xfff) {
/* scale to 0.0 .. 1.0 */
return (float)sig1 / 0xfff;
}
}
}
return NAN;
}
/* Should be called once */

View File

@ -19,4 +19,4 @@ void SENT_ISR_Handler(uint8_t ch, uint16_t val_res);
void startSent(void);
void stopSent(void);
float getSentValue(int index);
float getSentValue(size_t index);