This page is for C language / Protobuf
# git clone repository git clone git@github.com:BrainCoTech/stark-serialport-example.git
typedef struct { /* Device ID range: 10~254, the default is 10, 254 is the broadcast address, broadcast is only applicable to control instructions */ int serial_device_id; /* Device ID */ int baudrate; /* Baud rate, default is 115200 */ } SerialPortCfg; StarkDevice* stark_create_serial_device(const char* uuid, const int device_id); // Serial port configuration reading typedef void (*SerialPortCfgCB)(const char *device_id, SerialPortCfg *cfg); void stark_get_serialport_cfg(StarkDevice* device, SerialPortCfgCB cb); // The serial port configuration is modified, and the device will automatically restart after the modification void stark_set_serial_baudrate(StarkDevice* device, int baudrate); // baudrate: 115200, 57600, 19200 void stark_set_serial_device_id(StarkDevice* device, int device_id); // device_id // Set the serial port read and write callback int stark_did_receive_data(StarkDevice* device, const uint8_t* data, int size); typedef int (*WriteDataCB)(const char *device_id, const uint8_t *data, int size); void stark_set_write_data_callback(WriteDataCB cb);
Key info:
typedef enum { MEDIUM_RIGHT = 1, MEDIUM_LEFT = 2, SMALL_RIGHT = 3, SMALL_LEFT = 4 } StarkHandType; typedef struct { int hand_type; /* Device Type */ char sn[20]; /* Serial Number */ char fw_version[20]; /* Firmware version */ } MotorboardInfo; // Get device information typedef void (*MotorboardInfoCB)(const char *device_id, MotorboardInfo *info); void stark_get_motorboard_info(StarkDevice* device, MotorboardInfoCB cb); // Get the hand type void stark_get_hand_type(StarkDevice* device, StarkIntValueCB cb); // Get voltage information void stark_get_voltage(StarkDevice* device, StarkFloatValueCB cb);
// Set the position, range: 0~100, 0 is maximum extension, 100 is maximum grip void stark_set_finger_position(StarkDevice *device, int finger_position); void stark_set_finger_positions(StarkDevice* device, const int finger_positions[6]);
// Strength typedef enum { STARK_FORCE_LEVEL_SMALL = 1, STARK_FORCE_LEVEL_NORMAL = 2, STARK_FORCE_LEVEL_FULL = 3, } StarkForceLevel; // Read the force setting void stark_get_force_level(StarkDevice* device, StarkIntValueCB cb); // Set the force void stark_set_force_level(StarkDevice* device, int force_level);
// Motor status typedef enum { MOTOR_IDLE = 0, /* Motor idle, indicating that the motor is not running */ MOTOR_RUNNING = 1, /* Motor running, indicating that the motor is running */ MOTOR_PROTECTED_ZONE = 2, /* Critical protection zone, indicating that the motor is running, starting or about to stop */ MOTOR_STALL = 3 /* Motor stalled */ } MotroState; typedef struct { int n_motor_status; int* motor_status; } MotorStatusData; // Get motor status typedef void (*MotroStatusCB)(const char *device_id, MotorStatusData *data); void stark_get_motor_status(StarkDevice* device, MotroStatusCB cb);
// Finger number typedef enum { FINGERID_THUMB = 1, FINGERID_THUMB_AUX = 2, FINGERID_INDEX = 3, FINGERID_MIDDLE = 4, FINGERID_RING = 5, FINGERID_PINKY = 6 } StarkFingerId; // Single finger information typedef struct { uint8_t finger_positions[6]; // 0 ~ 100 for each finger. 0 for fully open, 100 for fully close int8_t finger_speeds[6]; // -100 ~ +100 for each finger. 0 for stop, positive number for close finger, negative number for open finger. int8_t finger_currents[6]; // -100 ~ +100 for each finger. Fraction of max motor current, absolute number. int8_t finger_pwms[6]; // -100 ~ +100 for each motor. } StarkFingerStatus; // All finger information typedef struct { int n_finger_status; StarkFingerStatus** finger_status; } FingerStatusData; // Get finger information typedef void (*FingerStatusCB)(const char *device_id, FingerStatusData *data); void stark_get_finger_status(StarkDevice* device, FingerStatusCB cb);
// Write action sequence void stark_transfer_action_sequence(StarkDevice* device, int action_id, int action_num, uint16_t** action_sequence); // Save action sequence void stark_save_action_sequence(StarkDevice* device, int action_id); // Read action sequence void stark_get_action_sequence(StarkDevice* device, int action_id, ActionSequenceCB cb); // Run action sequence void stark_run_action_sequence(StarkDevice* device, int action_id);
// OTA upgrade typedef enum { STARK_DFU_STATE_IDLE = 0, STARK_DFU_STATE_ENABLING = 1, // Enabling OTA mode STARK_DFU_STATE_STARTED = 2, // Entered OTA mode STARK_DFU_STATE_TRANSFER = 3, // OTA update in progress STARK_DFU_STATE_COMPLETED = 4, // OTA upgrade completed STARK_DFU_STATE_ABORTED = 5, // OTA upgrade interruption } StarkDfuState; typedef void (*DfuReadCB)(const char *device_id); typedef void (*DfuStateCB)(const char *device_id, int state); typedef void (*DfuProgressCB)(const char *device_id, float progress); // progress: 0.0 ~ 1.0 const char* stark_dfu_state_to_string(int state); void stark_set_dfu_read_callback(StarkDevice* device, DfuReadCB cb); void stark_set_dfu_state_callback(StarkDevice* device, DfuStateCB cb); void stark_set_dfu_progress_callback(StarkDevice* device, DfuProgressCB cb); void stark_set_dfu_cfg(StarkDevice* device, uint8_t dfu_enabling_delay /* = 8 */, /* Delay time for enabling DFU (1~30 seconds) in */ uint8_t dfu_enabling_interval /* = 10 */, /* Retry interval for enabling DFU (1~30 seconds) */ uint8_t dfu_applying_delay /* = 10 */); /* Waiting time for applying new firmware (1~30 seconds) */ void stark_start_dfu(StarkDevice* device, const char* dfu_file_path); void stark_abort_dfu(StarkDevice* device);
To provide the best experience, we use technologies like cookies to improve the speed and performance of the website.