Skip to content

Problem new plugin to make the cnc works with dual x carrige like Idex #96

@Achraf-Jannen

Description

@Achraf-Jannen

I want to make the cnc works with dual x carrige like Idex So i tried to create a new plugin named Idex_plugin (two files .c and .h)

what are the steps to create a new plugin and this the code i created (got many errors )

Idex_plugin.c :
// Plugins/idex_plugin/idex_plugin.c
#include "driver.h"
#include "idex_plugin.h"
#include "grbl/stepper.h"
#include "grbl/gcode.h"
#include "grbl/system.h"
#include"grbl/nuts_bolts.h"

// IDEX Mode Enum
typedef enum {
IDEX_MODE_FULL_CONTROL = 0,
IDEX_MODE_AUTO_PARK,
IDEX_MODE_DUPLICATION,
IDEX_MODE_MIRRORED
} idex_mode_t;

// Global state
static idex_mode_t idex_mode = IDEX_MODE_FULL_CONTROL;
static uint8_t active_tool = 0; // 0 = X1 (X), 1 = X2 (A)
static float duplication_offset = 100.0f;
static float park_pos_x1 = 0.0f;
static float park_pos_x2 = 350.0f;

// Axis indices
#define AXIS_X 0
#define AXIS_A 3

extern const gpio_t enable_pins[];

static void switch_tool(uint8_t tool)
{
active_tool = tool;
if(tool == 0) {
gpio_set(&enable_pins[AXIS_X]); // Enable X
gpio_clear(&enable_pins[AXIS_A]); // Disable A
report_message("Switched to X1 (T0)");
} else {
gpio_clear(&enable_pins[AXIS_X]); // Disable X
gpio_set(&enable_pins[AXIS_A]); // Enable A
report_message("Switched to X2 (T1)");
}

if(idex_mode == IDEX_MODE_AUTO_PARK) {
    if(tool == 0) {
        gc_sync_position_axis('A', park_pos_x2);
    } else {
        gc_sync_position_axis('X', park_pos_x1);
    }
}

}

static status_code_t idex_mcode_handler(uint_fast16_t code, char *params)
{
if(code == 605) {
uint8_t mode;
if(sscanf(params, "S%hhu", &mode) == 1) {
if(mode <= 3) {
idex_mode = (idex_mode_t)mode;
char msg[40];
sprintf(msg, "IDEX Mode set to %u", mode);
report_message(msg);
return Status_OK;
} else {
return Status_InvalidStatement;
}
}
}
return Status_Unhandled;
}

static status_code_t idex_tcode_handler(uint_fast16_t code)
{
if(code == 0 || code == 1) {
switch_tool((uint8_t)code);
return Status_OK;
}
return Status_Unhandled;
}

void idex_plugin_init(void)
{
gc_register_mcode_handler(605, idex_mcode_handler);
gc_register_tool_select_handler(idex_tcode_handler);

report_message("IDEX Plugin Initialized");

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions