2012-01-09 21:55:55 +02:00
|
|
|
#ifndef _controllerframe__hpp__included__
|
|
|
|
#define _controllerframe__hpp__included__
|
|
|
|
|
|
|
|
#include <cstring>
|
2012-02-23 16:48:56 +02:00
|
|
|
#include <climits>
|
2012-02-23 23:05:48 +02:00
|
|
|
#include <cstdio>
|
2012-01-09 21:55:55 +02:00
|
|
|
#include <cstdlib>
|
2012-03-04 15:41:06 +02:00
|
|
|
#include <cstdio>
|
2012-01-09 21:55:55 +02:00
|
|
|
#include <cstdint>
|
2012-02-23 16:48:56 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <iostream>
|
2012-01-09 21:55:55 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2012-07-15 13:32:15 +03:00
|
|
|
#include <list>
|
2012-10-11 11:32:44 +03:00
|
|
|
#include "library/controller-data.hpp"
|
2012-01-09 21:55:55 +02:00
|
|
|
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Analog indices.
|
|
|
|
*/
|
|
|
|
#define MAX_ANALOG 3
|
|
|
|
|
2012-01-09 21:55:55 +02:00
|
|
|
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Controllers state.
|
|
|
|
*/
|
|
|
|
class controller_state
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
controller_state() throw();
|
|
|
|
/**
|
|
|
|
* Convert lcid (Logical Controller ID) into pcid (Physical Controler ID).
|
|
|
|
*
|
|
|
|
* Parameter lcid: The logical controller ID.
|
2012-10-11 20:06:40 +03:00
|
|
|
* Return: The physical controller ID, or <-1, -1> if no such controller exists.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
std::pair<int, int> lcid_to_pcid(unsigned lcid) throw();
|
2012-10-19 19:53:15 +03:00
|
|
|
/**
|
|
|
|
* Lookup (port,controller) pair corresponding to given legacy pcid.
|
|
|
|
*
|
|
|
|
* Parameter pcid: The legacy pcid.
|
|
|
|
* Returns: The controller index, or <-1, -1> if no such thing exists.
|
|
|
|
* Note: Even if this does return a valid index, it still may not exist.
|
|
|
|
*/
|
|
|
|
std::pair<int, int> legacy_pcid_to_pair(unsigned pcid) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
2012-07-08 12:57:22 +03:00
|
|
|
* Is given pcid present?
|
2012-01-11 23:07:31 +02:00
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-07-08 12:57:22 +03:00
|
|
|
* Returns: True if present, false if not.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool pcid_present(unsigned port, unsigned controller) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
2012-10-11 20:06:40 +03:00
|
|
|
* Set types of ports.
|
2012-01-11 23:07:31 +02:00
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter ptype: The new types for ports.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Throws std::runtime_error: Illegal port type.
|
|
|
|
*/
|
2013-01-05 09:19:09 +02:00
|
|
|
void set_ports(const port_type_set& ptype) throw(std::runtime_error);
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Get status of current controls (with autohold/autofire factored in).
|
|
|
|
*
|
|
|
|
* Parameter framenum: Number of current frame (for evaluating autofire).
|
2012-01-13 06:51:47 +02:00
|
|
|
* Returns: The current controls.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
|
|
|
controller_frame get(uint64_t framenum) throw();
|
2012-01-13 06:51:47 +02:00
|
|
|
/**
|
|
|
|
* Commit given controls (autohold/autofire is factored in).
|
|
|
|
*
|
|
|
|
* Parameter framenum: Number of current frame (for evaluating autofire).
|
|
|
|
* Returns: The committed controls.
|
|
|
|
*/
|
|
|
|
controller_frame commit(uint64_t framenum) throw();
|
|
|
|
/**
|
|
|
|
* Commit given controls (autohold/autofire is ignored).
|
|
|
|
*
|
|
|
|
* Parameter controls: The controls to commit
|
|
|
|
* Returns: The committed controls.
|
|
|
|
*/
|
|
|
|
controller_frame commit(controller_frame controls) throw();
|
|
|
|
/**
|
|
|
|
* Get status of committed controls.
|
|
|
|
* Returns: The committed controls.
|
|
|
|
*/
|
|
|
|
controller_frame get_committed() throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Get blank frame.
|
|
|
|
*/
|
|
|
|
controller_frame get_blank() throw();
|
|
|
|
/**
|
2012-10-11 20:06:40 +03:00
|
|
|
* Send analog input to given controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port to send input to.
|
|
|
|
* Parameter controller: The controller to send input to.
|
2013-01-04 20:41:11 +02:00
|
|
|
* Parameter control: The control to send.
|
|
|
|
* Parameter x: The coordinate to send.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
2013-01-04 20:41:11 +02:00
|
|
|
void analog(unsigned port, unsigned controller, unsigned control, short x) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Manipulate autohold.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter newstate: The new state for autohold.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
void autohold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Query autohold.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of autohold.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool autohold2(unsigned port, unsigned controller, unsigned pbid) throw();
|
2012-05-11 19:37:06 +03:00
|
|
|
/**
|
|
|
|
* Reset all frame holds.
|
|
|
|
*/
|
|
|
|
void reset_framehold() throw();
|
|
|
|
/**
|
|
|
|
* Manipulate hold for frame.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-05-11 19:37:06 +03:00
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter newstate: The new state for framehold.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
void framehold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
|
2012-05-11 19:37:06 +03:00
|
|
|
/**
|
|
|
|
* Query hold for frame.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-05-11 19:37:06 +03:00
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of framehold.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool framehold2(unsigned port, unsigned controller, unsigned pbid) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Manipulate button.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter newstate: The new state for button.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
void button2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
|
|
|
* Query button.
|
|
|
|
*
|
2012-10-11 20:06:40 +03:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
2012-01-11 23:07:31 +02:00
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of button.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool button2(unsigned port, unsigned controller, unsigned pbid) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
/**
|
2013-03-14 00:15:43 +02:00
|
|
|
* Manipulate autofire.
|
2012-01-11 23:07:31 +02:00
|
|
|
*
|
2013-03-14 00:15:43 +02:00
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
|
|
|
* Parameter pbid: The physical button ID to manipulate.
|
|
|
|
* Parameter duty: The new duty cycle for autofire.
|
|
|
|
* Parameter cyclelen: The new cycle length.
|
|
|
|
*/
|
|
|
|
void autofire2(unsigned port, unsigned controller, unsigned pbid, unsigned duty, unsigned cyclelen) throw();
|
|
|
|
/**
|
|
|
|
* Query autofire.
|
|
|
|
*
|
|
|
|
* Parameter port: The port.
|
|
|
|
* Parameter controller: The controller.
|
|
|
|
* Parameter pbid: The physical button ID to query.
|
|
|
|
* Returns: The state of autofire.
|
2012-01-11 23:07:31 +02:00
|
|
|
*/
|
2013-03-14 00:15:43 +02:00
|
|
|
std::pair<unsigned, unsigned> autofire2(unsigned port, unsigned controller, unsigned pbid) throw();
|
2012-07-08 12:57:22 +03:00
|
|
|
/**
|
|
|
|
* TODO: Document.
|
|
|
|
*/
|
2012-10-11 20:06:40 +03:00
|
|
|
bool is_present(unsigned port, unsigned controller) throw();
|
2012-01-11 23:07:31 +02:00
|
|
|
private:
|
2013-03-14 00:15:43 +02:00
|
|
|
struct autofire_info
|
|
|
|
{
|
|
|
|
uint64_t first_frame;
|
|
|
|
unsigned duty;
|
|
|
|
unsigned cyclelen;
|
|
|
|
bool eval_at(uint64_t frame);
|
|
|
|
};
|
2012-10-11 20:06:40 +03:00
|
|
|
const port_type_set* types;
|
2012-01-11 23:07:31 +02:00
|
|
|
controller_frame _input;
|
|
|
|
controller_frame _autohold;
|
2012-05-11 19:37:06 +03:00
|
|
|
controller_frame _framehold;
|
2013-03-14 00:15:43 +02:00
|
|
|
std::map<unsigned, autofire_info> _autofire;
|
2012-01-13 06:51:47 +02:00
|
|
|
controller_frame _committed;
|
2012-01-11 23:07:31 +02:00
|
|
|
};
|
|
|
|
|
2012-10-19 20:44:19 +03:00
|
|
|
/**
|
|
|
|
* Generic port controller name function.
|
|
|
|
*/
|
2013-01-03 11:12:08 +02:00
|
|
|
template<unsigned controllers, const char** name>
|
2012-10-19 20:44:19 +03:00
|
|
|
inline const char* generic_controller_name(unsigned controller)
|
|
|
|
{
|
|
|
|
if(controller >= controllers)
|
|
|
|
return NULL;
|
2013-01-03 11:12:08 +02:00
|
|
|
return *name;
|
2012-10-19 20:44:19 +03:00
|
|
|
}
|
|
|
|
|
2012-01-09 21:55:55 +02:00
|
|
|
#endif
|