Skip to content

Commit

Permalink
Move static string definitions to .cpp
Browse files Browse the repository at this point in the history
Ref #66
  • Loading branch information
ddemidov committed Nov 8, 2021
1 parent 97bd166 commit b8a4c90
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 86 deletions.
86 changes: 43 additions & 43 deletions ev3dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,19 +583,19 @@ gyro_sensor::gyro_sensor(address_type address)
{ }

//-----------------------------------------------------------------------------
constexpr char infrared_sensor::mode_ir_prox[];
constexpr char infrared_sensor::mode_ir_seek[];
constexpr char infrared_sensor::mode_ir_remote[];
constexpr char infrared_sensor::mode_ir_rem_a[];
constexpr char infrared_sensor::mode_ir_cal[];
char infrared_sensor::mode_ir_prox[] = "IR-PROX";
char infrared_sensor::mode_ir_seek[] = "IR-SEEK";
char infrared_sensor::mode_ir_remote[] = "IR-REMOTE";
char infrared_sensor::mode_ir_rem_a[] = "IR-REM-A";
char infrared_sensor::mode_ir_cal[] = "IR-CAL";

infrared_sensor::infrared_sensor(address_type address)
: sensor(address, { ev3_infrared })
{ }

//-----------------------------------------------------------------------------
constexpr char sound_sensor::mode_db[];
constexpr char sound_sensor::mode_dba[];
char sound_sensor::mode_db[] = "DB";
char sound_sensor::mode_dba[] = "DBA";

sound_sensor::sound_sensor(address_type address)
: sensor(address, { nxt_sound, nxt_analog })
Expand All @@ -617,36 +617,36 @@ sound_sensor::sound_sensor(address_type address)
}

//-----------------------------------------------------------------------------
constexpr char light_sensor::mode_reflect[];
constexpr char light_sensor::mode_ambient[];
char light_sensor::mode_reflect[] = "REFLECT";
char light_sensor::mode_ambient[] = "AMBIENT";

light_sensor::light_sensor(address_type address)
: sensor(address, { nxt_light })
{ }

//-----------------------------------------------------------------------------
constexpr char motor::motor_large[];
constexpr char motor::motor_medium[];
constexpr char motor::motor_nxt[];
constexpr char motor::command_run_forever[];
constexpr char motor::command_run_to_abs_pos[];
constexpr char motor::command_run_to_rel_pos[];
constexpr char motor::command_run_timed[];
constexpr char motor::command_run_direct[];
constexpr char motor::command_stop[];
constexpr char motor::command_reset[];
constexpr char motor::encoder_polarity_normal[];
constexpr char motor::encoder_polarity_inversed[];
constexpr char motor::polarity_normal[];
constexpr char motor::polarity_inversed[];
constexpr char motor::state_running[];
constexpr char motor::state_ramping[];
constexpr char motor::state_holding[];
constexpr char motor::state_overloaded[];
constexpr char motor::state_stalled[];
constexpr char motor::stop_action_coast[];
constexpr char motor::stop_action_brake[];
constexpr char motor::stop_action_hold[];
char motor::motor_large[] = "lego-ev3-l-motor";
char motor::motor_medium[] = "lego-ev3-m-motor";
char motor::motor_nxt[] = "lego-nxt-motor";
char motor::command_run_forever[] = "run-forever";
char motor::command_run_to_abs_pos[] = "run-to-abs-pos";
char motor::command_run_to_rel_pos[] = "run-to-rel-pos";
char motor::command_run_timed[] = "run-timed";
char motor::command_run_direct[] = "run-direct";
char motor::command_stop[] = "stop";
char motor::command_reset[] = "reset";
char motor::encoder_polarity_normal[] = "normal";
char motor::encoder_polarity_inversed[] = "inversed";
char motor::polarity_normal[] = "normal";
char motor::polarity_inversed[] = "inversed";
char motor::state_running[] = "running";
char motor::state_ramping[] = "ramping";
char motor::state_holding[] = "holding";
char motor::state_overloaded[] = "overloaded";
char motor::state_stalled[] = "stalled";
char motor::stop_action_coast[] = "coast";
char motor::stop_action_brake[] = "brake";
char motor::stop_action_hold[] = "hold";

//-----------------------------------------------------------------------------
motor::motor(address_type address) {
Expand Down Expand Up @@ -696,14 +696,14 @@ dc_motor::dc_motor(address_type address) {
connect(_strClassDir, _strPattern, {{ "address", { address }}});
}

constexpr char dc_motor::command_run_forever[];
constexpr char dc_motor::command_run_timed[];
constexpr char dc_motor::command_run_direct[];
constexpr char dc_motor::command_stop[];
constexpr char dc_motor::polarity_normal[];
constexpr char dc_motor::polarity_inversed[];
constexpr char dc_motor::stop_action_coast[];
constexpr char dc_motor::stop_action_brake[];
char dc_motor::command_run_forever[] = "run-forever";
char dc_motor::command_run_timed[] = "run-timed";
char dc_motor::command_run_direct[] = "run-direct";
char dc_motor::command_stop[] = "stop";
char dc_motor::polarity_normal[] = "normal";
char dc_motor::polarity_inversed[] = "inversed";
char dc_motor::stop_action_coast[] = "coast";
char dc_motor::stop_action_brake[] = "brake";

//-----------------------------------------------------------------------------
servo_motor::servo_motor(address_type address) {
Expand All @@ -713,10 +713,10 @@ servo_motor::servo_motor(address_type address) {
connect(_strClassDir, _strPattern, {{ "address", { address }}});
}

constexpr char servo_motor::command_run[];
constexpr char servo_motor::command_float[];
constexpr char servo_motor::polarity_normal[];
constexpr char servo_motor::polarity_inversed[];
char servo_motor::command_run[] = "run";
char servo_motor::command_float[] = "float";
char servo_motor::polarity_normal[] = "normal";
char servo_motor::polarity_inversed[] = "inversed";

//-----------------------------------------------------------------------------
led::led(std::string name) {
Expand Down
86 changes: 43 additions & 43 deletions ev3dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,19 +517,19 @@ class infrared_sensor : public sensor {
infrared_sensor(address_type address = INPUT_AUTO);

// Proximity
static constexpr char mode_ir_prox[] = "IR-PROX";
static char mode_ir_prox[];

// IR Seeker
static constexpr char mode_ir_seek[] = "IR-SEEK";
static char mode_ir_seek[];

// IR Remote Control
static constexpr char mode_ir_remote[] = "IR-REMOTE";
static char mode_ir_remote[];

// IR Remote Control. State of the buttons is coded in binary
static constexpr char mode_ir_rem_a[] = "IR-REM-A";
static char mode_ir_rem_a[];

// Calibration ???
static constexpr char mode_ir_cal[] = "IR-CAL";
static char mode_ir_cal[];


// A measurement of the distance between the sensor and the remote,
Expand All @@ -548,10 +548,10 @@ class sound_sensor : public sensor {
sound_sensor(address_type address = INPUT_AUTO);

// Sound pressure level. Flat weighting
static constexpr char mode_db[] = "DB";
static char mode_db[];

// Sound pressure level. A weighting
static constexpr char mode_dba[] = "DBA";
static char mode_dba[];


// A measurement of the measured sound pressure level, as a
Expand All @@ -577,10 +577,10 @@ class light_sensor : public sensor {
light_sensor(address_type address = INPUT_AUTO);

// Reflected light. LED on
static constexpr char mode_reflect[] = "REFLECT";
static char mode_reflect[];

// Ambient light. LED off
static constexpr char mode_ambient[] = "AMBIENT";
static char mode_ambient[];


// A measurement of the reflected light intensity, as a percentage.
Expand Down Expand Up @@ -614,85 +614,85 @@ class motor : protected device {
motor(address_type);
motor(address_type, const motor_type&);

static constexpr char motor_large[] = "lego-ev3-l-motor";
static constexpr char motor_medium[] = "lego-ev3-m-motor";
static constexpr char motor_nxt[] = "lego-nxt-motor";
static char motor_large[];
static char motor_medium[];
static char motor_nxt[];

using device::connected;
using device::device_index;

// Run the motor until another command is sent.
static constexpr char command_run_forever[] = "run-forever";
static char command_run_forever[];

// Run to an absolute position specified by `position_sp` and then
// stop using the action specified in `stop_action`.
static constexpr char command_run_to_abs_pos[] = "run-to-abs-pos";
static char command_run_to_abs_pos[];

// Run to a position relative to the current `position` value.
// The new position will be current `position` + `position_sp`.
// When the new position is reached, the motor will stop using
// the action specified by `stop_action`.
static constexpr char command_run_to_rel_pos[] = "run-to-rel-pos";
static char command_run_to_rel_pos[];

// Run the motor for the amount of time specified in `time_sp`
// and then stop the motor using the action specified by `stop_action`.
static constexpr char command_run_timed[] = "run-timed";
static char command_run_timed[];

// Run the motor at the duty cycle specified by `duty_cycle_sp`.
// Unlike other run commands, changing `duty_cycle_sp` while running *will*
// take effect immediately.
static constexpr char command_run_direct[] = "run-direct";
static char command_run_direct[];

// Stop any of the run commands before they are complete using the
// action specified by `stop_action`.
static constexpr char command_stop[] = "stop";
static char command_stop[];

// Reset all of the motor parameter attributes to their default value.
// This will also have the effect of stopping the motor.
static constexpr char command_reset[] = "reset";
static char command_reset[];

// Sets the normal polarity of the rotary encoder.
static constexpr char encoder_polarity_normal[] = "normal";
static char encoder_polarity_normal[];

// Sets the inversed polarity of the rotary encoder.
static constexpr char encoder_polarity_inversed[] = "inversed";
static char encoder_polarity_inversed[];

// With `normal` polarity, a positive duty cycle will
// cause the motor to rotate clockwise.
static constexpr char polarity_normal[] = "normal";
static char polarity_normal[];

// With `inversed` polarity, a positive duty cycle will
// cause the motor to rotate counter-clockwise.
static constexpr char polarity_inversed[] = "inversed";
static char polarity_inversed[];

// Power is being sent to the motor.
static constexpr char state_running[] = "running";
static char state_running[];

// The motor is ramping up or down and has not yet reached a constant output level.
static constexpr char state_ramping[] = "ramping";
static char state_ramping[];

// The motor is not turning, but rather attempting to hold a fixed position.
static constexpr char state_holding[] = "holding";
static char state_holding[];

// The motor is turning, but cannot reach its `speed_sp`.
static constexpr char state_overloaded[] = "overloaded";
static char state_overloaded[];

// The motor is not turning when it should be.
static constexpr char state_stalled[] = "stalled";
static char state_stalled[];

// Power will be removed from the motor and it will freely coast to a stop.
static constexpr char stop_action_coast[] = "coast";
static char stop_action_coast[];

// Power will be removed from the motor and a passive electrical load will
// be placed on the motor. This is usually done by shorting the motor terminals
// together. This load will absorb the energy from the rotation of the motors and
// cause the motor to stop more quickly than coasting.
static constexpr char stop_action_brake[] = "brake";
static char stop_action_brake[];

// Does not remove power from the motor. Instead it actively try to hold the motor
// at the current position. If an external force tries to turn the motor, the motor
// will `push back` to maintain its position.
static constexpr char stop_action_hold[] = "hold";
static char stop_action_hold[];

// Address: read-only
// Returns the name of the port that this motor is connected to.
Expand Down Expand Up @@ -1007,37 +1007,37 @@ class dc_motor : protected device {
using device::device_index;

// Run the motor until another command is sent.
static constexpr char command_run_forever[] = "run-forever";
static char command_run_forever[];

// Run the motor for the amount of time specified in `time_sp`
// and then stop the motor using the action specified by `stop_action`.
static constexpr char command_run_timed[] = "run-timed";
static char command_run_timed[];

// Run the motor at the duty cycle specified by `duty_cycle_sp`.
// Unlike other run commands, changing `duty_cycle_sp` while running *will*
// take effect immediately.
static constexpr char command_run_direct[] = "run-direct";
static char command_run_direct[];

// Stop any of the run commands before they are complete using the
// action specified by `stop_action`.
static constexpr char command_stop[] = "stop";
static char command_stop[];

// With `normal` polarity, a positive duty cycle will
// cause the motor to rotate clockwise.
static constexpr char polarity_normal[] = "normal";
static char polarity_normal[];

// With `inversed` polarity, a positive duty cycle will
// cause the motor to rotate counter-clockwise.
static constexpr char polarity_inversed[] = "inversed";
static char polarity_inversed[];

// Power will be removed from the motor and it will freely coast to a stop.
static constexpr char stop_action_coast[] = "coast";
static char stop_action_coast[];

// Power will be removed from the motor and a passive electrical load will
// be placed on the motor. This is usually done by shorting the motor terminals
// together. This load will absorb the energy from the rotation of the motors and
// cause the motor to stop more quickly than coasting.
static constexpr char stop_action_brake[] = "brake";
static char stop_action_brake[];

// Address: read-only
// Returns the name of the port that this motor is connected to.
Expand Down Expand Up @@ -1167,18 +1167,18 @@ class servo_motor : protected device {
using device::device_index;

// Drive servo to the position set in the `position_sp` attribute.
static constexpr char command_run[] = "run";
static char command_run[];

// Remove power from the motor.
static constexpr char command_float[] = "float";
static char command_float[];

// With `normal` polarity, a positive duty cycle will
// cause the motor to rotate clockwise.
static constexpr char polarity_normal[] = "normal";
static char polarity_normal[];

// With `inversed` polarity, a positive duty cycle will
// cause the motor to rotate counter-clockwise.
static constexpr char polarity_inversed[] = "inversed";
static char polarity_inversed[];

// Address: read-only
// Returns the name of the port that this motor is connected to.
Expand Down

0 comments on commit b8a4c90

Please sign in to comment.