示例#1
0
// Turn pin on and off
void Switch::on_gcode_execute(void *argument)
{
    Gcode *gcode = static_cast<Gcode *>(argument);

    if(match_input_on_gcode(gcode)) {
        int v;
        this->switch_state = true;
        if (this->output_type == PWM) {
            // PWM output pin turn on
            if(gcode->has_letter('S')) {
                v = round(gcode->get_value('S') * output_pin.max_pwm() / 255.0); // scale by max_pwm so input of 255 and max_pwm of 128 would set value to 128
                this->output_pin.pwm(v);
            } else {
                this->output_pin.pwm(this->switch_value);
            }
        } else {
            // logic pin turn on
            this->output_pin.set(true);
        }
    } else if(match_input_off_gcode(gcode)) {
        this->switch_state = false;
        if (this->output_type == PWM) {
            // PWM output pin
            this->output_pin.set(false);
        } else {
            // logic pin turn off
            this->output_pin.set(false);
        }
    }
}
示例#2
0
void Switch::on_gcode_received(void *argument)
{
    Gcode *gcode = static_cast<Gcode *>(argument);
    // Add the gcode to the queue ourselves if we need it
    if (match_input_on_gcode(gcode) || match_input_off_gcode(gcode)) {
        THEKERNEL->conveyor->append_gcode(gcode);
    }
}
示例#3
0
void Switch::on_gcode_received(void *argument)
{
    Gcode *gcode = static_cast<Gcode *>(argument);
    // Add the gcode to the queue ourselves if we need it
    if (!(match_input_on_gcode(gcode) || match_input_off_gcode(gcode))) {
        return;
    }

    // drain queue
    THEKERNEL->conveyor->wait_for_empty_queue();

    if(match_input_on_gcode(gcode)) {
        int v;
        if (this->output_type == PWM) {
            // PWM output pin turn on (or off if S0)
            if(gcode->has_letter('S')) {
                v = round(gcode->get_value('S') * output_pin.max_pwm() / 255.0); // scale by max_pwm so input of 255 and max_pwm of 128 would set value to 128
                this->output_pin.pwm(v);
                this->switch_state= (v > 0);
            } else {
                this->output_pin.pwm(this->switch_value);
                this->switch_state= (this->switch_value > 0);
            }
        } else {
            // logic pin turn on
            this->output_pin.set(true);
            this->switch_state = true;
        }
    } else if(match_input_off_gcode(gcode)) {
        this->switch_state = false;
        if (this->output_type == PWM) {
            // PWM output pin
            this->output_pin.set(false);
        } else {
            // logic pin turn off
            this->output_pin.set(false);
        }
    }
}