ddemidov / ev3dev-lang-cpp

C++ language bindings for http://ev3dev.org
MIT License
73 stars 38 forks source link

ev3dev-lang-cpp ready for ev3dev-stretch ? #47

Open cho934 opened 5 years ago

cho934 commented 5 years ago

Hello,

Is everything is generated and modified for ev3dev-stretch ?

The first thing which is crashing is the power_supply... aïe.

Is it possible to make the update as soon as possible, please ? I'm testing all my devices on stretch this weekend.

ddemidov commented 5 years ago

Hi, I did not use the library myself for a long time, so the answer is probably no. I guess to make it useable again with stretch, you would need to adjust a couple of string constants (paths to devices, addresses, etc). If you are willing to test the changes and propose a pull request with fixes, I will be glad to accept it.

cho934 commented 5 years ago

I just found a boring bug to set a variable IR-PROX using proximity() to the IR Sensor

Using the function set_attr_string,

void device::set_attr_string(const std::string &name, const std::string &value)
{
    using namespace std;

    if (_path.empty())
        throw system_error(make_error_code(errc::function_not_supported),
                "no device connected ; [set_attr_string] path=" + _path + " name=" + name + " value=" + value);

    ofstream &os = ofstream_open(_path + name);
    if (os.is_open()) {
        if (!(os << value))
            throw system_error(std::error_code(errno, std::system_category()));
        return;
    }
    throw system_error(make_error_code(errc::no_such_device), "ofstream_open ; [set_attr_string] " + _path + name);
}

I received the following error:

terminate called after throwing an instance of 'std::system_error'
  what():  ofstream_open ; [set_attr_string] /sys/class/lego-sensor/sensor41/mode: No such device
Aborted

If I used my program with sudo, no error If I used shell cmd echo "IR-PROX" > /sys/class/lego-sensor/sensor41/mode , no error

What's wrong ? permissions ?

ddemidov commented 5 years ago

Does not look like a problem with permissions, since you were able to modify the value from the shell without sudo. Could the device be in an uninitialized state when you ran your first test? Would a delay of 0.5 seconds before setting the mode help?

cho934 commented 5 years ago

I'm currently using the MUX, So I need to initialize the device as an ir sensor first. Then I tried without delay to set the mode to continue to configure it. I'm going to check if I have the same issue without the MUX, and try with a delay...

cho934 commented 5 years ago

Did someone already test the new release ev3dev-stretch-ev3-generic-2019-10-23 with ev3dev-lang-cpp ?