Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sailfish v4.7 compatibility #44

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 96 additions & 15 deletions src/gpx/gpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <stdint.h>

#include <libgen.h>

Expand Down Expand Up @@ -484,6 +483,40 @@ static uint32_t read_32(Gpx *gpx)
return le32toh(u.i);
}

static void write_64(Gpx *gpx, uint64_t value)
{
union {
uint64_t i;
unsigned char b[8];
} u;
u.i = htole64(value);
*gpx->buffer.ptr++ = u.b[0];
*gpx->buffer.ptr++ = u.b[1];
*gpx->buffer.ptr++ = u.b[2];
*gpx->buffer.ptr++ = u.b[3];
*gpx->buffer.ptr++ = u.b[4];
*gpx->buffer.ptr++ = u.b[5];
*gpx->buffer.ptr++ = u.b[6];
*gpx->buffer.ptr++ = u.b[7];
}

static uint64_t read_64(Gpx *gpx)
{
union {
uint64_t i;
unsigned char b[8];
} u;
u.b[0] = *gpx->buffer.ptr++;
u.b[1] = *gpx->buffer.ptr++;
u.b[2] = *gpx->buffer.ptr++;
u.b[3] = *gpx->buffer.ptr++;
u.b[4] = *gpx->buffer.ptr++;
u.b[5] = *gpx->buffer.ptr++;
u.b[6] = *gpx->buffer.ptr++;
u.b[7] = *gpx->buffer.ptr++;
return le64toh(u.i);
}

static void write_fixed_16(Gpx *gpx, float value)
{
unsigned char b = (unsigned char)value;
Expand Down Expand Up @@ -2593,7 +2626,7 @@ int read_eeprom_8(Gpx *gpx, Sio *sio, unsigned address, unsigned char *value)
return SUCCESS;
}

int write_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, unsigned short value)
int write_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, uint16_t value)
{
int rval;
gpx->buffer.ptr = sio->response.eeprom.buffer;
Expand All @@ -2602,7 +2635,7 @@ int write_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, unsigned short value)
return SUCCESS;
}

int read_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, unsigned short *value)
int read_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, uint16_t *value)
{
int rval;
CALL( read_eeprom(gpx, address, 2) );
Expand All @@ -2629,7 +2662,7 @@ int read_eeprom_fixed_16(Gpx *gpx, Sio *sio, unsigned address, float *value)
return SUCCESS;
}

int write_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, unsigned long value)
int write_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, uint32_t value)
{
int rval;
gpx->buffer.ptr = sio->response.eeprom.buffer;
Expand All @@ -2638,7 +2671,7 @@ int write_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, unsigned long value)
return SUCCESS;
}

int read_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, unsigned long *value)
int read_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, uint32_t *value)
{
int rval;
CALL( read_eeprom(gpx, address, 4) );
Expand All @@ -2647,6 +2680,24 @@ int read_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, unsigned long *value)
return SUCCESS;
}

int write_eeprom_64(Gpx *gpx, Sio *sio, unsigned address, uint64_t value)
{
int rval;
gpx->buffer.ptr = sio->response.eeprom.buffer;
write_64(gpx, value);
CALL( write_eeprom(gpx, address, sio->response.eeprom.buffer, 8) );
return SUCCESS;
}

int read_eeprom_64(Gpx *gpx, Sio *sio, unsigned address, uint64_t *value)
{
int rval;
CALL( read_eeprom(gpx, address, 8) );
gpx->buffer.ptr = sio->response.eeprom.buffer;
*value = read_64(gpx);
return SUCCESS;
}

int write_eeprom_float(Gpx *gpx, Sio *sio, unsigned address, float value)
{
int rval;
Expand Down Expand Up @@ -2838,7 +2889,7 @@ static int read_eeprom_name(Gpx *gpx, char *name)
}

case et_ushort: {
unsigned short us;
uint16_t us;
CALL( read_eeprom_16(gpx, gpx->sio, pem->address, &us) );
gcodeResult(gpx, "EEPROM value %s @ 0x%x is %u %s (0x%x)\n", pem->id, pem->address, us, unit, us);
break;
Expand All @@ -2853,14 +2904,31 @@ static int read_eeprom_name(Gpx *gpx, char *name)

case et_long:
case et_ulong: {
unsigned long ul;
uint32_t ul;
CALL( read_eeprom_32(gpx, gpx->sio, pem->address, &ul) );
double result;
if(pem->et == et_long) {
gcodeResult(gpx, "EEPROM value %s @ 0x%x is %d %s (0x%lx)\n", pem->id, pem->address, ul, unit, ul);
result = (int32_t) ul / pem->unitScaleFactor;
}
else {
result = ul / pem->unitScaleFactor;
}
gcodeResult(gpx, "EEPROM value %s @ 0x%x is %g %s (0x%lx)\n", pem->id, pem->address, result, unit, ul);
break;
}

case et_long_long:
case et_ulong_long: {
uint64_t ull;
CALL( read_eeprom_64(gpx, gpx->sio, pem->address, &ull) );
double result;
if(pem->et == et_long_long) {
result = (int64_t) ull / pem->unitScaleFactor;
}
else {
gcodeResult(gpx, "EEPROM value %s @ 0x%x is %u %s (0x%lx)\n", pem->id, pem->address, ul, unit, ul);
result = ull / pem->unitScaleFactor;
}
gcodeResult(gpx, "EEPROM value %s @ 0x%x is %g %s (0x%llx)\n", pem->id, pem->address, result, unit, ull);
break;
}

Expand Down Expand Up @@ -2888,7 +2956,7 @@ static int read_eeprom_name(Gpx *gpx, char *name)
}

// write an eeprom value via a defined mapping
static int write_eeprom_name(Gpx *gpx, char *name, char *string_value, unsigned long hex, float value)
static int write_eeprom_name(Gpx *gpx, char *name, char *string_value, uint64_t hex, double value)
{
int rval = SUCCESS;

Expand All @@ -2907,7 +2975,7 @@ static int write_eeprom_name(Gpx *gpx, char *name, char *string_value, unsigned
}

if(value != 0.0)
hex = (unsigned long)value;
hex = (uint64_t)(int64_t) (value * pem->unitScaleFactor);

}

Expand All @@ -2930,7 +2998,7 @@ static int write_eeprom_name(Gpx *gpx, char *name, char *string_value, unsigned
gcodeResult(gpx, "(line %u) Error: parameter out of range for eeprom setting %s\n", gpx->lineNumber, pem->id);
return ERROR;
}
unsigned short us = (unsigned short)hex;
uint16_t us = (uint16_t)hex;
CALL( write_eeprom_16(gpx, gpx->sio, pem->address, us) );
gcodeResult(gpx, "EEPROM wrote 16-bits, %u to address 0x%x\n", us, pem->address);
break;
Expand All @@ -2946,8 +3014,19 @@ static int write_eeprom_name(Gpx *gpx, char *name, char *string_value, unsigned

case et_long:
case et_ulong:
CALL( write_eeprom_32(gpx, gpx->sio, pem->address, hex) );
gcodeResult(gpx, "EEPROM wrote 32-bits, %lu to address 0x%x\n", hex, pem->address);
if(value > 0 && hex > 2147483648) {
gcodeResult(gpx, "(line %u) Error: parameter out of range for eeprom setting %s\n", gpx->lineNumber, pem->id);
return ERROR;
}
uint32_t ul = (uint32_t)hex;
CALL( write_eeprom_32(gpx, gpx->sio, pem->address, ul) );
gcodeResult(gpx, "EEPROM wrote 32-bits, %lu to address 0x%x\n", ul, pem->address);
break;

case et_long_long:
case et_ulong_long:
CALL( write_eeprom_64(gpx, gpx->sio, pem->address, hex) );
gcodeResult(gpx, "EEPROM wrote 64-bits, %llu to address 0x%x\n", hex, pem->address);
break;

case et_float:
Expand Down Expand Up @@ -3288,6 +3367,8 @@ EepromType eepromTypeFromTypeName(char *type_name)
case 'H': return et_ushort;
case 'i': return et_long;
case 'I': return et_ulong;
case 'L': return et_long_long;
case 'K': return et_ulong_long;
case 'f': return et_fixed;
case 's': return et_string;
}
Expand Down Expand Up @@ -3421,7 +3502,7 @@ static int parse_macro(Gpx *gpx, const char* macro, char *p)
while(*p && (isalnum(*p) || *p == '_')) p++;
if(*p) *p++ = 0;
}
else if(isdigit(*p)) {
else if(isdigit(*p) || *p == '-') {
char *t = p;
while(*p && !isspace(*p)) p++;
if(*(p - 1) == 'm') {
Expand Down
11 changes: 7 additions & 4 deletions src/gpx/gpx.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern "C" {
#include <stdarg.h>
#include <time.h>
#include "vector.h"
#include <stdint.h>
#include "config.h"

#if defined(SERIAL_SUPPORT)
Expand Down Expand Up @@ -655,12 +656,14 @@ typedef long speed_t;
int write_eeprom(Gpx *gpx, unsigned address, char *data, unsigned length);
int write_eeprom_8(Gpx *gpx, Sio *sio, unsigned address, unsigned char value);
int read_eeprom_8(Gpx *gpx, Sio *sio, unsigned address, unsigned char *value);
int write_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, unsigned short value);
int read_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, unsigned short *value);
int write_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, uint16_t value);
int read_eeprom_16(Gpx *gpx, Sio *sio, unsigned address, uint16_t *value);
int write_eeprom_fixed_16(Gpx *gpx, Sio *sio, unsigned address, float value);
int read_eeprom_fixed_16(Gpx *gpx, Sio *sio, unsigned address, float *value);
int write_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, unsigned long value);
int read_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, unsigned long *value);
int write_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, uint32_t value);
int read_eeprom_32(Gpx *gpx, Sio *sio, unsigned address, uint32_t *value);
int write_eeprom_64(Gpx *gpx, Sio *sio, unsigned address, uint64_t value);
int read_eeprom_64(Gpx *gpx, Sio *sio, unsigned address, uint64_t *value);
int write_eeprom_float(Gpx *gpx, Sio *sio, unsigned address, float value);
int read_eeprom_float(Gpx *gpx, Sio *sio, unsigned address, float *value);

Expand Down
2 changes: 1 addition & 1 deletion src/gpx/tests/eepromtest.gcode
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(@loadmap)
(@load_eeprom_map)
(@eread LED_CUSTOM_COLOR_R)
(@eread LED_CUSTOM_COLOR_G)
(@eread LED_CUSTOM_COLOR_B)
Expand Down
46 changes: 46 additions & 0 deletions src/gpx/tests/eepromtest_sailfish_4_7.gcode
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(@load_eeprom_map)
(@eread ACCELERATION_ACTIVE)
(@eread MAX_ACCELERATION_EXTRUDER_MOVE)
(@eread MAX_SPEED_CHANGE_X)
(@eread MAX_SPEED_CHANGE_Y)
(@eread MAX_SPEED_CHANGE_Z)
(@eread MAX_SPEED_CHANGE_A)
(@eread MAX_SPEED_CHANGE_B)
(@eread MAX_ACCELERATION_AXIS_X)
(@eread MAX_ACCELERATION_AXIS_Y)
(@eread MAX_ACCELERATION_AXIS_Z)
(@eread MAX_ACCELERATION_AXIS_A)
(@eread MAX_ACCELERATION_AXIS_B)
(@eread EXTRUDER_DEPRIME_ON_TRAVEL)
(@eread ALEVEL_MAX_ZPROBE_HITS)
(@eread PREHEAT_PREHEAT_RIGHT_TEMP)
(@eread PREHEAT_PREHEAT_PLATFORM_TEMP)
(@eread PREHEAT_PREHEAT_LEFT_TEMP)
(@eread JKN_ADVANCE_K2)
(@eread JKN_ADVANCE_K)
(@eread EXTRUDER_DEPRIME_STEPS_A)
(@eread EXTRUDER_DEPRIME_STEPS_B)
(@eread SLOWDOWN_FLAG)
(@eread MACHINE_NAME)
(@eread ALEVEL_MAX_ZDELTA)
(@eread PSTOP_ENABLE)
(@eread DITTO_PRINT_ENABLED)
(@eread SD_USE_CRC)
(@eread CLEAR_FOR_ESTOP)
(@eread AXIS_HOME_POSITIONS_STEPS_X)
(@eread AXIS_HOME_POSITIONS_STEPS_Y)
(@eread AXIS_HOME_POSITIONS_STEPS_Z)
(@eread AXIS_HOME_POSITIONS_STEPS_A)
(@eread AXIS_HOME_POSITIONS_STEPS_B)
(@eread AXIS_STEPS_PER_MM_X)
(@eread AXIS_STEPS_PER_MM_Y)
(@eread AXIS_STEPS_PER_MM_Z)
(@eread AXIS_STEPS_PER_MM_A)
(@eread AXIS_STEPS_PER_MM_B)
(@eread ENDSTOP_INVERSION)
(@eread TOOL_COUNT)
(@eread AXIS_INVERSION)
(@eread TOOLHEAD_OFFSET_SYSTEM)
(@eread TOOLHEAD_OFFSET_SETTINGS_X)
(@eread TOOLHEAD_OFFSET_SETTINGS_Y)
(@eread EXTRUDER_HOLD)
Loading