From b8a4c900fe5ee59bffbd634bd65ab3175dfe84ff Mon Sep 17 00:00:00 2001 From: Denis Demidov Date: Mon, 8 Nov 2021 21:24:24 +0300 Subject: [PATCH] Move static string definitions to .cpp Ref #66 --- ev3dev.cpp | 86 +++++++++++++++++++++++++++--------------------------- ev3dev.h | 86 +++++++++++++++++++++++++++--------------------------- 2 files changed, 86 insertions(+), 86 deletions(-) diff --git a/ev3dev.cpp b/ev3dev.cpp index f11d50c..1d027e5 100644 --- a/ev3dev.cpp +++ b/ev3dev.cpp @@ -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 }) @@ -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) { @@ -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) { @@ -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) { diff --git a/ev3dev.h b/ev3dev.h index 08b3ef3..b332704 100644 --- a/ev3dev.h +++ b/ev3dev.h @@ -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, @@ -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 @@ -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. @@ -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. @@ -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. @@ -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.