mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Add data graph node for devices
Add the new inputDeviceNode class to be used in the data graph Add config variable for low batery level
This commit is contained in:
parent
a6110a606e
commit
ef7cc925c4
@ -36,6 +36,9 @@ NotifyCategoryDef(device, "");
|
|||||||
ConfigVariableBool asynchronous_clients
|
ConfigVariableBool asynchronous_clients
|
||||||
("asynchronous-clients", true);
|
("asynchronous-clients", true);
|
||||||
|
|
||||||
|
ConfigVariableInt low_battery_level
|
||||||
|
("low-battery-level", 15);
|
||||||
|
|
||||||
ConfigureFn(config_device) {
|
ConfigureFn(config_device) {
|
||||||
init_libdevice();
|
init_libdevice();
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,12 @@
|
|||||||
#include "pandabase.h"
|
#include "pandabase.h"
|
||||||
#include "notifyCategoryProxy.h"
|
#include "notifyCategoryProxy.h"
|
||||||
#include "configVariableBool.h"
|
#include "configVariableBool.h"
|
||||||
|
#include "configVariableInt.h"
|
||||||
|
|
||||||
NotifyCategoryDecl(device, EXPCL_PANDA_DEVICE, EXPTP_PANDA_DEVICE);
|
NotifyCategoryDecl(device, EXPCL_PANDA_DEVICE, EXPTP_PANDA_DEVICE);
|
||||||
|
|
||||||
extern ConfigVariableBool asynchronous_clients;
|
extern ConfigVariableBool asynchronous_clients;
|
||||||
|
extern ConfigVariableInt low_battery_level;
|
||||||
|
|
||||||
extern EXPCL_PANDA_DEVICE void init_libdevice();
|
extern EXPCL_PANDA_DEVICE void init_libdevice();
|
||||||
|
|
||||||
|
71
panda/src/device/inputDeviceNode.cxx
Normal file
71
panda/src/device/inputDeviceNode.cxx
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* PANDA 3D SOFTWARE
|
||||||
|
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||||
|
*
|
||||||
|
* All use of this software is subject to the terms of the revised BSD
|
||||||
|
* license. You should have received a copy of this license along
|
||||||
|
* with this source code in a file named "LICENSE."
|
||||||
|
*
|
||||||
|
* @file InputDeviceNode.cxx
|
||||||
|
* @author fireclaw
|
||||||
|
* @date 2016-07-14
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config_device.h"
|
||||||
|
#include "inputDeviceNode.h"
|
||||||
|
#include "dataNodeTransmit.h"
|
||||||
|
#include "inputDeviceManager.h"
|
||||||
|
|
||||||
|
TypeHandle InputDeviceNode::_type_handle;
|
||||||
|
|
||||||
|
InputDeviceNode::
|
||||||
|
InputDeviceNode(InputDevice *device, const string &name) :
|
||||||
|
DataNode(name),
|
||||||
|
_device(device)
|
||||||
|
{
|
||||||
|
_button_events_output = define_output("button_events", ButtonEventList::get_class_type());
|
||||||
|
_low_battery_event_output = define_output("low_battery_level_event", EventStoreInt::get_class_type());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects the class to get the data from a different device.
|
||||||
|
*/
|
||||||
|
void InputDeviceNode::
|
||||||
|
set_device(InputDevice *device) {
|
||||||
|
_device = device;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the associated device.
|
||||||
|
*/
|
||||||
|
PT(InputDevice) InputDeviceNode::
|
||||||
|
get_device() const {
|
||||||
|
return _device;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The virtual implementation of transmit_data(). This function receives an
|
||||||
|
* array of input parameters and should generate an array of output
|
||||||
|
* parameters. The input parameters may be accessed with the index numbers
|
||||||
|
* returned by the define_input() calls that were made earlier (presumably in
|
||||||
|
* the constructor); likewise, the output parameters should be set with the
|
||||||
|
* index numbers returned by the define_output() calls.
|
||||||
|
*/
|
||||||
|
void InputDeviceNode::
|
||||||
|
do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &,
|
||||||
|
DataNodeTransmit &output) {
|
||||||
|
// get all button events of the device and forward them to the data graph
|
||||||
|
if (_device->has_button_event()) {
|
||||||
|
PT(ButtonEventList) bel = _device->get_button_events();
|
||||||
|
output.set_data(_button_events_output, EventParameter(bel));
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate the battery level in percent and set a warning if the level is to low
|
||||||
|
if (_device->has_battery()) {
|
||||||
|
short bl = _device->get_battery_level();
|
||||||
|
short bl_percent = bl / (_device->get_max_battery_level() / (short)100);
|
||||||
|
if (bl_percent <= low_battery_level) {
|
||||||
|
output.set_data(_low_battery_event_output, EventParameter(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
panda/src/device/inputDeviceNode.h
Normal file
66
panda/src/device/inputDeviceNode.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* PANDA 3D SOFTWARE
|
||||||
|
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||||
|
*
|
||||||
|
* All use of this software is subject to the terms of the revised BSD
|
||||||
|
* license. You should have received a copy of this license along
|
||||||
|
* with this source code in a file named "LICENSE."
|
||||||
|
*
|
||||||
|
* @file InputDeviceNode.h
|
||||||
|
* @author fireclaw
|
||||||
|
* @date 2016-07-14
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INPUTDEVICENODE_H
|
||||||
|
#define INPUTDEVICENODE_H
|
||||||
|
|
||||||
|
#include "pandabase.h"
|
||||||
|
|
||||||
|
#include "dataNode.h"
|
||||||
|
#include "inputDeviceManager.h"
|
||||||
|
#include "linmath_events.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the controler data sent from the InputDeviceManager, and
|
||||||
|
* transmits it down the data graph.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class EXPCL_PANDA_DEVICE InputDeviceNode : public DataNode {
|
||||||
|
PUBLISHED:
|
||||||
|
InputDeviceNode(InputDevice *device, const string &name);
|
||||||
|
void set_device(InputDevice *device);
|
||||||
|
PT(InputDevice) get_device() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Inherited from DataNode
|
||||||
|
virtual void do_transmit_data(DataGraphTraverser *trav,
|
||||||
|
const DataNodeTransmit &input,
|
||||||
|
DataNodeTransmit &output);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// outputs
|
||||||
|
int _button_events_output;
|
||||||
|
int _low_battery_event_output;
|
||||||
|
|
||||||
|
PT(InputDevice) _device;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static TypeHandle get_class_type() {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type() {
|
||||||
|
DataNode::init_type();
|
||||||
|
register_type(_type_handle, "InputDeviceNode",
|
||||||
|
DataNode::get_class_type());
|
||||||
|
}
|
||||||
|
virtual TypeHandle get_type() const {
|
||||||
|
return get_class_type();
|
||||||
|
}
|
||||||
|
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static TypeHandle _type_handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INPUTDEVICENODE_H
|
@ -10,3 +10,4 @@
|
|||||||
#include "inputDeviceManager.cxx"
|
#include "inputDeviceManager.cxx"
|
||||||
#include "inputDeviceSet.cxx"
|
#include "inputDeviceSet.cxx"
|
||||||
#include "linuxJoystickDevice.cxx"
|
#include "linuxJoystickDevice.cxx"
|
||||||
|
#include "inputDeviceNode.cxx"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user