and especially of course: hey John!
The cards have to be shuffled - so new game, new luck!
In order not to fall into the same traps as by NXC, I would venture to propose the following new features for a new API:
Currently it's very complicated if not impossible to make different sensor settings or to get different sensor readings at different ports in a loop or to pass them to a function or to get sensor values returned by a remote function.
So my suggestion is to revive the ancient syntax of NQC and initial NXC providing a SetSensor(......) and a GetSensor(......) function.
- Code: Select all
SetSensor(char port, long SensorType)
SensorTypes coud be defined in a sensor header like
#define SENSOR_LEGO_TOUCH 1
#define SENSOR_LEGO_TOUCH_EDGE 2
#define SENSOR_LEGO_TOUCH_PULSE 3
#define SENSOR_ADC_RAW 10
#define SENSOR_LEGO_LIGHT10_PASSIVE 20
#define SENSOR_LEGO_LIGHT10_ACTIVE 21
#define SENSOR_LEGO_COLOR20_FULL 110
#define SENSOR_I2C_LEGO 1009 // Lego standard 9k
#define SENSOR_I2C_100k 1100 // i2c std 100k if possible by hardware
#define SENSOR_RS485 2000
and so on.
To poll all the sensor values in a similar systematic and logical way, both for single values and for arrays like color sensors or 3D accelerometers, I would appreciate the following way:
- Code: Select all
GetSensor(char port, long SensorType, long & values) // (in plain C: the pointer to the array)
Having this syntax, you are able to poll both the single value of a touch sensor and the sensor array of 3 dim accelerometers or 9 dim IMU sernsors by the same kind of function call.
again thinking about the implementation:
when passing the sensor types/modes to the GetSensor function, one may even drop the SetSensor initializing completely because then initializing is implicite.
Otherwise, using SetSensor() then one could drop the sensor types in the GetSensor function.
(to be continued)