Skip to content

Question On Creating onStep function in Register #14

@yowakita

Description

@yowakita

Hello, first of all thank you for creating this module, it has been very useful for me. Pardon my lack of knowledge because a lot of this is still new to me, but I would love to learn more.

I am attempting to create an onStep function for the accelerometer that would utilize the constants you have in the accelerometer.js register file,

STEP_DETECTOR_INTERRUPT_ENABLE = 0x17;
STEP_DETECTOR_CONFIG    = 0x18;
STEP_DETECTOR_INTERRUPT = 0x19;
STEP_COUNTER_DATA       = 0x1a;
STEP_COUNTER_RESET      = 0x1b;

Attempting to emulate the code you have now on the onChange function, I wrote a function

Accelerometer.prototype.onStep = function (callback) {
    this.device.emitter.on( [MODULE_OPCODE, STEP_DETECTOR_INTERRUPT], function(buffer){
        callback();
    });
}

Ands added to the start function

    buffer = new Buffer(3);
    buffer[0] = MODULE_OPCODE;
    buffer[1] = STEP_DETECTOR_CONFIG;
    buffer[2] = 0x00;
    this.device.send(buffer);

When I write into the example accelerometer.js file,

accelerometer.onStep(function(){
     console.log("Test");
 })

I don't get an error but I also don't get anything console log. I am certain I am not understanding how buffers and MODULE_OPCODE work. Could you please help?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions