Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #10 from forno/update-v1.2.1
Browse files Browse the repository at this point in the history
Update v1.2.1
  • Loading branch information
forno authored Nov 3, 2016
2 parents 3d38e8f + f338d0d commit e752bc2
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(ics3 CXX)

SET(PROJECT_VER_MAJOR 1)
SET(PROJECT_VER_MINOR 2)
SET(PROJECT_VER_PATCH 0)
SET(PROJECT_VER_PATCH 1)
SET(PROJECT_VER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}")
SET(PROJECT_APIVER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")

Expand Down
12 changes: 6 additions & 6 deletions include/ics3/angle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ics {
constexpr rawType getRaw() const noexcept;
void setRaw(rawType);
private:
constexpr explicit Angle(type, type);
constexpr Angle(type, type); // non explicit, user cannot touch this
static constexpr rawType castToRaw(type, type) noexcept;
static constexpr rawType checkInvalidAngle(rawType);

Expand All @@ -37,19 +37,19 @@ namespace ics {
};

constexpr Angle Angle::newDegree(type angle) {
return Angle {800.0 / 27.0, angle};
return {800.0 / 27.0, angle};
}

constexpr Angle Angle::newRadian(type angle) {
return Angle {16000.0 / 3.0 / PI, angle};
return {16000.0 / 3.0 / PI, angle};
}

constexpr Angle Angle::newSameUnit(const Angle& unit, type angle) {
return Angle {unit.rawCalibration, angle};
return {unit.rawCalibration, angle};
}

constexpr Angle Angle::newCalibration(type calibration, type angle) {
return Angle {calibration, angle};
return {calibration, angle};
}

inline Angle& Angle::operator=(const Angle& rhs) noexcept {
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace ics {
{}

constexpr Angle::rawType Angle::castToRaw(type calibration, type angle) noexcept {
return static_cast<rawType>((calibration * angle) + MID);
return (calibration * angle) + MID;
}

constexpr Angle::rawType Angle::checkInvalidAngle(rawType raw) {
Expand Down
4 changes: 2 additions & 2 deletions include/ics3/baudrate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace ics {
constexpr operator type() const noexcept;
constexpr speed_t getSpeed() const noexcept;
private:
explicit constexpr Baudrate(type, speed_t) noexcept;
constexpr Baudrate(type, speed_t) noexcept; // non explicit, user cannot touch this

const type romdata;
const speed_t baudrate;
};

constexpr Baudrate Baudrate::RATE115200() noexcept {
return Baudrate {10, B115200};
return {10, B115200};
}

constexpr Baudrate::type Baudrate::get() const noexcept {
Expand Down
64 changes: 33 additions & 31 deletions include/ics3/eepparam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ics {
public:
using type = uint16_t;
using size_type = std::size_t;
using TargetContainer = std::array<uint8_t, 64>;
enum Flag : type {
REVERSE = 0x01,
FREE = 0x02,
Expand Down Expand Up @@ -45,10 +46,10 @@ namespace ics {
constexpr operator type() const noexcept;
void set(type);
EepParam& operator=(type);
void write(std::array<uint8_t, 64>&) const noexcept;
void read(const std::array<uint8_t, 64>&);
void read(const TargetContainer&);
void write(TargetContainer&) const noexcept;
private:
constexpr explicit EepParam(
constexpr EepParam( // non explicit, user cannot touch this
size_type,
size_type,
type,
Expand All @@ -70,79 +71,79 @@ namespace ics {
};

constexpr EepParam EepParam::stretch(type data) {
return EepParam {2, 2, 2, 254, &EepParam::checkInvalidEvenRange, data};
return {2, 2, 2, 254, &EepParam::checkInvalidEvenRange, data};
}

constexpr EepParam EepParam::speed(type data) {
return EepParam {4, 2, 1, 127, &EepParam::checkInvalidRange, data};
return {4, 2, 1, 127, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::punch(type data) {
return EepParam {6, 2, 0, 10, &EepParam::checkInvalidRange, data};
return {6, 2, 0, 10, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::deadBand(type data) {
return EepParam {8, 2, 0, 5, &EepParam::checkInvalidRange, data};
return {8, 2, 0, 5, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::dumping(type data) {
return EepParam {10, 2, 1, 255, &EepParam::checkInvalidRange, data};
return {10, 2, 1, 255, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::selfTimer(type data) {
return EepParam {12, 2, 10, 255, &EepParam::checkInvalidRange, data};
return {12, 2, 10, 255, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::flag(type data) {
return EepParam {14, 2, 0, 255, &EepParam::checkInvalidFlag, data};
return {14, 2, 0, 255, &EepParam::checkInvalidFlag, data};
}

constexpr EepParam EepParam::pulseMax(type data) {
return EepParam {16, 4, 3500, 11500, &EepParam::checkInvalidRange, data};
return {16, 4, 3500, 11500, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::pulseMin(type data) {
return EepParam {20, 4, 3500, 11500, &EepParam::checkInvalidRange, data};
return {20, 4, 3500, 11500, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::baudrate(type data) {
return EepParam {26, 2, 0, 10, &EepParam::checkInvalidBaudrate, data};
return {26, 2, 0, 10, &EepParam::checkInvalidBaudrate, data};
}

constexpr EepParam EepParam::temperature(type data) {
return EepParam {28, 2, 1, 127, &EepParam::checkInvalidRange, data};
return {28, 2, 1, 127, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::current(type data) {
return EepParam {30, 2, 1, 63, &EepParam::checkInvalidRange, data};
return {30, 2, 1, 63, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::response(type data) {
return EepParam {50, 2, 1, 5, &EepParam::checkInvalidRange, data};
return {50, 2, 1, 5, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::userOffset(type data) {
return EepParam {52, 2, 0x81, 127, &EepParam::checkInvalidOffset, data}; // 0x81 is -127 on uint8_t type
return {52, 2, 0x81, 127, &EepParam::checkInvalidOffset, data}; // 0x81 is -127 on uint8_t type
}

constexpr EepParam EepParam::id(type data) {
return EepParam {56, 2, 0, 31, &EepParam::checkInvalidRange, data};
return {56, 2, 0, 31, &EepParam::checkInvalidRange, data};
}

constexpr EepParam EepParam::strech1(type data) {
return EepParam {58, 2, 2, 254, &EepParam::checkInvalidEvenRange, data};
return {58, 2, 2, 254, &EepParam::checkInvalidEvenRange, data};
}

constexpr EepParam EepParam::strech2(type data) {
return EepParam {60, 2, 2, 254, &EepParam::checkInvalidEvenRange, data};
return {60, 2, 2, 254, &EepParam::checkInvalidEvenRange, data};
}

constexpr EepParam EepParam::strech3(type data) {
return EepParam {62, 2, 2, 254, &EepParam::checkInvalidEvenRange, data};
return {62, 2, 2, 254, &EepParam::checkInvalidEvenRange, data};
}

constexpr EepParam EepParam::newEepParam(const EepParam& paramType, type data) {
return EepParam {paramType.offset, paramType.length, paramType.min, paramType.max, paramType.setFunc, data};
return {paramType.offset, paramType.length, paramType.min, paramType.max, paramType.setFunc, data};
}

constexpr EepParam::type EepParam::get() const noexcept {
Expand All @@ -162,15 +163,7 @@ namespace ics {
return *this;
}

inline void EepParam::write(std::array<uint8_t, 64>& dest) const noexcept {
type nowData {data};
for (size_type i {offset + length - 1}; i >= offset; --i) {
dest[i] = nowData & mask;
nowData >>= byteSize;
}
}

inline void EepParam::read(const std::array<uint8_t, 64>& src) {
inline void EepParam::read(const TargetContainer& src) {
type result {0};
const size_type loopend = offset + length;
for (size_type i {offset}; i < loopend; ++i) {
Expand All @@ -179,6 +172,15 @@ namespace ics {
}
set(result); // throw std::invalid_argument, std::out_of_range
}

inline void EepParam::write(TargetContainer& dest) const noexcept {
type nowData {data};
for (size_type i {offset + length - 1}; i >= offset; --i) {
dest[i] = nowData & mask;
nowData >>= byteSize;
}
}

constexpr EepParam::EepParam(
size_type offset,
size_type length,
Expand Down
4 changes: 2 additions & 2 deletions include/ics3/eeprom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace ics {
template<typename Iter>
void write(Iter&&) const;
private:
explicit EepRom(const Container&);
EepRom(const Container&); // non explicit, user cannot touch this

std::array<uint8_t, length> data;
Container data;
};

inline ics::EepParam ics::EepRom::get(EepParam type) const {
Expand Down
12 changes: 6 additions & 6 deletions include/ics3/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ics {
Parameter& operator=(type);
constexpr type getSubcommand() const noexcept;
private:
explicit constexpr Parameter(type, type, type, type);
constexpr Parameter(type, type, type, type); // non explicit, user cannot touch this

const type sc;
const type min;
Expand All @@ -28,23 +28,23 @@ namespace ics {
};

constexpr Parameter Parameter::stretch(type data) {
return Parameter {0x01, 1, 127, data};
return {0x01, 1, 127, data};
}

constexpr Parameter Parameter::speed(type data) {
return Parameter {0x02, 1, 127, data};
return {0x02, 1, 127, data};
}

constexpr Parameter Parameter::current(type data) {
return Parameter {0x03, 0, 63, data};
return {0x03, 0, 63, data};
}

constexpr Parameter Parameter::temperature(type data) {
return Parameter {0x04, 1, 127, data};
return {0x04, 1, 127, data};
}

constexpr Parameter Parameter::newParameter(const Parameter& base, type data) {
return Parameter {base.sc, base.min, base.max, data};
return {base.sc, base.min, base.max, data};
}

constexpr Parameter::type Parameter::get() const noexcept {
Expand Down
8 changes: 4 additions & 4 deletions src/ics3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static inline ics::Angle::rawType getReceiveAngle(const ics::Core::Container& rx
return (rx[4] << 7) | rx[5];
}

static inline ics::Core::value getCmd(const int head, const ics::ID& id) {
static inline ics::Core::value getCmd(const ics::Core::value head, const ics::ID& id) {
return head | id.get();
}

Expand All @@ -19,7 +19,7 @@ ics::ICS3::ICS3(const std::string& path, const Baudrate& baudrate)

ics::Angle ics::ICS3::move(const ID& id, Angle angle) {
static Core::Container tx(3), rx(6); // cache for runtime speed
const uint16_t send {angle.getRaw()};
const auto send = angle.getRaw();
tx[0] = getCmd(0x80, id);
tx[1] = 0x7F & (send >> 7);
tx[2] = 0x7F & send;
Expand Down Expand Up @@ -55,7 +55,7 @@ ics::EepRom ics::ICS3::getRom(const ID& id) {
core->communicate(tx, rx); // throw std::runtime_error
EepRom::Container romData;
std::copy(rx.cbegin() + 4, rx.cend(), romData.begin());
return EepRom {romData}; // need friend
return {romData}; // need friend
}

void ics::ICS3::setRom(const ID& id, const EepRom& rom) {
Expand All @@ -69,7 +69,7 @@ ics::ID ics::ICS3::getID() {
constexpr Core::IDContainerTx tx {0xFF, 0x00, 0x00, 0x00};
Core::IDContainerRx rx;
core->communicateID(tx, rx);
return ID {static_cast<ID::type>(0x1F & rx[4])};
return {static_cast<ID::type>(0x1F & rx[4])};
}

void ics::ICS3::setID(const ID& id) {
Expand Down

0 comments on commit e752bc2

Please sign in to comment.