11 #include <argos3/core/wrappers/lua/lua_utility.h>
26 int LuaLEDSetSingleColor(lua_State* pt_lua_state) {
28 if(lua_gettop(pt_lua_state) != 2 && lua_gettop(pt_lua_state) != 4) {
29 return luaL_error(pt_lua_state,
"robot.leds.set_single_color() expects 2 or 4 arguments");
31 luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
32 size_t unIdx = lua_tonumber(pt_lua_state, 1);
34 CCI_LEDsActuator* pcAct = CLuaUtility::GetDeviceInstance<CCI_LEDsActuator>(pt_lua_state,
"leds");
35 if(unIdx < 1 || unIdx > pcAct->GetNumLEDs()) {
36 return luaL_error(pt_lua_state,
"passed index %d out of bounds [1,%d]", unIdx, pcAct->GetNumLEDs());
40 if(lua_gettop(pt_lua_state) == 2) {
41 luaL_checktype(pt_lua_state, 2, LUA_TSTRING);
43 cColor.Set(lua_tostring(pt_lua_state, 2));
45 catch(CARGoSException& ex) {
46 return luaL_error(pt_lua_state, ex.what());
50 luaL_checktype(pt_lua_state, 2, LUA_TNUMBER);
51 luaL_checktype(pt_lua_state, 3, LUA_TNUMBER);
52 luaL_checktype(pt_lua_state, 4, LUA_TNUMBER);
53 cColor.Set(lua_tonumber(pt_lua_state, 2),
54 lua_tonumber(pt_lua_state, 3),
55 lua_tonumber(pt_lua_state, 4));
58 pcAct->SetSingleColor(unIdx - 1, cColor);
67 int LuaLEDSetAllColors(lua_State* pt_lua_state) {
69 if(lua_gettop(pt_lua_state) != 1 && lua_gettop(pt_lua_state) != 3) {
70 return luaL_error(pt_lua_state,
"robot.leds.set_all_colors() expects 1 or 3 arguments");
74 if(lua_gettop(pt_lua_state) == 1) {
75 luaL_checktype(pt_lua_state, 1, LUA_TSTRING);
77 cColor.Set(lua_tostring(pt_lua_state, 1));
79 catch(CARGoSException& ex) {
80 return luaL_error(pt_lua_state, ex.what());
84 luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
85 luaL_checktype(pt_lua_state, 2, LUA_TNUMBER);
86 luaL_checktype(pt_lua_state, 3, LUA_TNUMBER);
87 cColor.Set(lua_tonumber(pt_lua_state, 1),
88 lua_tonumber(pt_lua_state, 2),
89 lua_tonumber(pt_lua_state, 3));
92 CLuaUtility::GetDeviceInstance<CCI_LEDsActuator>(pt_lua_state,
"leds")->
133 UInt8 un_intensity) {
149 #ifdef ARGOS_WITH_LUA
150 void CCI_LEDsActuator::CreateLuaState(lua_State* pt_lua_state) {
unsigned int UInt32
32-bit unsigned integer.
unsigned char UInt8
8-bit unsigned integer.
The namespace containing all the ARGoS related code.
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 OpenRobotStateTable(lua_State *pt_state, const std::string &str_key)
Opens a table in the robot state, creating it if it does not exist.
static void CloseRobotStateTable(lua_State *pt_state)
Closes a table in the robot state.
size_t GetNumLEDs() const
Returns the number of LEDs.
virtual void SetAllColors(const CColor &c_color)
Sets the color of the whole LED ring.
virtual void SetAllIntensities(UInt8 un_intensity)
Sets the intensity of all the LEDs in the ring.
virtual void SetSingleColor(UInt32 un_led_number, const CColor &c_color)
Sets the color of a single LED.
virtual void SetSingleIntensity(UInt32 un_led_number, UInt8 un_intensity)
Sets the intensity of a single LED in the ring.
std::vector< CColor > TSettings