ci_battery_sensor.cpp
Go to the documentation of this file.
1 
7 #include "ci_battery_sensor.h"
8 
9 #ifdef ARGOS_WITH_LUA
10 #include <argos3/core/wrappers/lua/lua_utility.h>
11 #endif
12 
13 namespace argos {
14 
15  /****************************************/
16  /****************************************/
17 
19  return m_sReading;
20  }
21 
22  /****************************************/
23  /****************************************/
24 
25 #ifdef ARGOS_WITH_LUA
26  void CCI_BatterySensor::CreateLuaState(lua_State* pt_lua_state) {
27  CLuaUtility::StartTable(pt_lua_state, "battery");
28  CLuaUtility::AddToTable(pt_lua_state, "available_charge", m_sReading.AvailableCharge);
29  CLuaUtility::AddToTable(pt_lua_state, "time_left", m_sReading.TimeLeft);
30  CLuaUtility::EndTable(pt_lua_state);
31  }
32 #endif
33 
34  /****************************************/
35  /****************************************/
36 
37 #ifdef ARGOS_WITH_LUA
38  void CCI_BatterySensor::ReadingsToLuaState(lua_State* pt_lua_state) {
39  lua_getfield(pt_lua_state, -1, "battery");
40  lua_pushnumber(pt_lua_state, m_sReading.AvailableCharge);
41  lua_setfield(pt_lua_state, -2, "available_charge");
42  lua_pushnumber(pt_lua_state, m_sReading.TimeLeft);
43  lua_setfield(pt_lua_state, -2, "time_left");
44  lua_pop(pt_lua_state, 1);
45  }
46 #endif
47 
48  /****************************************/
49  /****************************************/
50 
51 }
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
static void EndTable(lua_State *pt_state)
Adds a table to the Lua stack.
static void AddToTable(lua_State *pt_state, const std::string &str_key, void *pt_data)
Adds a pointer to a chunk of data with the given string key to the table located at the top of the st...
static void StartTable(lua_State *pt_state, const std::string &str_key)
Adds a table with the given string key to the table located at the top of the stack.
const SReading & GetReading() const
Real AvailableCharge
Available charge, between 0 and 1.
Real TimeLeft
Time left in seconds.