move to 8 bit communication

This commit is contained in:
Laila van Reenen 2024-08-10 19:23:18 +02:00
parent 43b23ec1ad
commit 259d4b91d8
Signed by: LailaTheElf
GPG Key ID: 1F4E6EE3E6DDF769
4 changed files with 7 additions and 7 deletions

View File

@ -90,7 +90,7 @@
} }
function send(x,y,angle){ function send(x,y,angle){
factor = (2**16-1)/400 factor = (2**8-1)/400;
x = Math.round((x + 200) * factor); x = Math.round((x + 200) * factor);
y = Math.round((y + 200) * factor); y = Math.round((y + 200) * factor);
var data = clientId + ";d;" + x.toString() + "," + y.toString(); var data = clientId + ";d;" + x.toString() + "," + y.toString();

View File

@ -59,8 +59,8 @@ int cmd_contrl(char* line, void* cli)
{ {
readInt(arg, &ch_d[1]); readInt(arg, &ch_d[1]);
servo_set(0, (uint16_t)ch_d[0]); servo_set(0, (uint8_t)ch_d[0]);
servo_set(1, (uint16_t)ch_d[1]); servo_set(1, (uint8_t)ch_d[1]);
snprintf(&msg[0], 40, "channel data: 0:%lu, 1:%lu\n", ch_d[0], ch_d[1]); snprintf(&msg[0], 40, "channel data: 0:%lu, 1:%lu\n", ch_d[0], ch_d[1]);
CLI_stringOut((CLI_t*)cli, &msg[0]); CLI_stringOut((CLI_t*)cli, &msg[0]);
} }

View File

@ -70,10 +70,10 @@ void servo_deinit(void)
} }
} }
void servo_set(uint8_t ch, uint16_t pos) void servo_set(uint8_t ch, uint8_t pos)
{ {
uint32_t duty = (uint32_t) ((double)pos * (double)SERVO_DUTY_DIFF/(double)INT16_MAX); uint32_t duty = (uint32_t) ((double)pos * (double)SERVO_DUTY_DIFF/(double)UINT8_MAX);
duty += (SERVO_DUTY_MIN + SERVO_DUTY_DIFF/2); duty += (SERVO_DUTY_MIN + (SERVO_DUTY_DIFF/2));
if (duty < SERVO_DUTY_MIN) if (duty < SERVO_DUTY_MIN)
{ {
duty = SERVO_DUTY_MIN; duty = SERVO_DUTY_MIN;

View File

@ -5,6 +5,6 @@
void servo_init(void); void servo_init(void);
void servo_deinit(void); void servo_deinit(void);
void servo_set(uint8_t ch, uint16_t pos); void servo_set(uint8_t ch, uint8_t pos);
#endif // SERVOS_H #endif // SERVOS_H