whitespace

This commit is contained in:
IOhannes m zmölnig 2022-03-21 09:40:46 +01:00
parent 36cff9839a
commit 7db31d1ae4
2 changed files with 37 additions and 36 deletions

View file

@ -1,10 +1,10 @@
/* /*
bird.c - PD externals, that controls and parses one flock of bird out of a comport bird.c - PD externals, that controls and parses one flock of bird out of a comport
Date: 16.01.97 Date: 16.01.97
Author: Winfried Ritsch (see LICENCE.txt) Author: Winfried Ritsch (see LICENCE.txt)
Institute for Electronic Music - Graz Institute for Electronic Music - Graz
Desc.: put the object in a correct parse state and send commands Desc.: put the object in a correct parse state and send commands
@ -25,7 +25,7 @@
#include <stdio.h> /* general I/O */ #include <stdio.h> /* general I/O */
#include <string.h> /* for string commands */ #include <string.h> /* for string commands */
#include "m_pd.h" #include "m_pd.h"
#define B_MAX_DATA 32 /* Maximal awaited data per record */ #define B_MAX_DATA 32 /* Maximal awaited data per record */
#define B_MAX_CMDDATA 6 /* Maximum of awaited cmd arguments */ #define B_MAX_CMDDATA 6 /* Maximum of awaited cmd arguments */
@ -50,7 +50,7 @@ typedef struct {
char *argname; char *argname;
int argc; int argc;
int argv[B_MAX_DATA]; int argv[B_MAX_DATA];
int verbose; int verbose;
} bird_t; } bird_t;
@ -77,9 +77,9 @@ typedef struct {
/* defines Modes for data receiving */ /* defines Modes for data receiving */
#define B_MODE_IGNORE 0 #define B_MODE_IGNORE 0
#define B_MODE_POINT 1 #define B_MODE_POINT 1
#define B_MODE_STREAM 2 #define B_MODE_STREAM 2
#define B_MODE_EXAM 3 #define B_MODE_EXAM 3
/*#define B_STREAM_ON 1 /*#define B_STREAM_ON 1
@ -93,10 +93,10 @@ typedef struct {
/* cmds accepted by the flock */ /* cmds accepted by the flock */
static bird_cmd cmds[]= { static bird_cmd cmds[]= {
/* cmd , value, nr of cmdatabytes, cmddatasize, nr datainbytes /* cmd , value, nr of cmdatabytes, cmddatasize, nr datainbytes
data modes, if change always point */ data modes, if change always point */
{"ANGLES", 'W', 0, 0, 6, B_MODE_POINT}, {"ANGLES", 'W', 0, 0, 6, B_MODE_POINT},
{"MATRIX", 'X', 0, 0, 18, B_MODE_POINT}, {"MATRIX", 'X', 0, 0, 18, B_MODE_POINT},
{"POSITION", 'V', 0, 0, 6, B_MODE_POINT}, {"POSITION", 'V', 0, 0, 6, B_MODE_POINT},
{"QUATER", 0x5C, 0, 0, 8, B_MODE_POINT}, {"QUATER", 0x5C, 0, 0, 8, B_MODE_POINT},
@ -156,11 +156,11 @@ int bird_data( bird_t *this, unsigned char data )
/* STREAM or POINT Mode */ /* STREAM or POINT Mode */
/* Phase was detected */ /* Phase was detected */
if(this->phase_wait == B_FOUND_PHASE && data < 0x80){ if(this->phase_wait == B_FOUND_PHASE && data < 0x80){
this->data[this->datacount] = data; /* store data */ this->data[this->datacount] = data; /* store data */
this->datacount++; /* increment counter */ this->datacount++; /* increment counter */
if(this->databytes <= this->datacount){ /* last byte of record */ if(this->databytes <= this->datacount){ /* last byte of record */
this->datacount = 0; this->datacount = 0;
this->phase_wait = B_WAIT_PHASE; this->phase_wait = B_WAIT_PHASE;
@ -181,8 +181,8 @@ int bird_data( bird_t *this, unsigned char data )
}; };
} }
else{ /* Phase wait */ else{ /* Phase wait */
if( (data & 0x80) == 0x00 ){ /* phase bit not found */ if( (data & 0x80) == 0x00 ){ /* phase bit not found */
if(this->phase_error == 0) if(this->phase_error == 0)
if(this->verbose)post("phase error:%x",data); if(this->verbose)post("phase error:%x",data);
this->phase_error++; this->phase_error++;
@ -193,7 +193,7 @@ int bird_data( bird_t *this, unsigned char data )
this->datacount = 1; /* wait for next */ this->datacount = 1; /* wait for next */
this->phase_error = 0; /* phase error reset */ this->phase_error = 0; /* phase error reset */
}; };
}; };
}; /* stream or point mode */ }; /* stream or point mode */
return 0; return 0;
@ -256,16 +256,16 @@ void bird_set(bird_t *this, const char *cmdname,long *cmddata)
bird_send(this,cmd->cmd); bird_send(this,cmd->cmd);
for(i=0; i < cmd->cmdbytes;i++){ for(i=0; i < cmd->cmdbytes;i++){
data = cmddata[i]; data = cmddata[i];
for(j=0; j < cmd->cmdsize;j++){ /* send it bytewise */ for(j=0; j < cmd->cmdsize;j++){ /* send it bytewise */
bird_send(this, (unsigned char) (data&0xFF)); bird_send(this, (unsigned char) (data&0xFF));
data >>= 8; data >>= 8;
}; };
}; };
} }
if(this->verbose)post("command %s (%c): databytes=%d, mode=%d, phase=%d", if(this->verbose)post("command %s (%c): databytes=%d, mode=%d, phase=%d",
@ -286,9 +286,9 @@ void bird_float(bird_t *x, t_floatarg f)
int n,i; int n,i;
if((n=bird_data(x,(unsigned char) f)) > 0){ if((n=bird_data(x,(unsigned char) f)) > 0){
/* make list and output */ /* make list and output */
for(i=0; i < x->argc ; i++){ for(i=0; i < x->argc ; i++){
x->x_vec[i].a_type = A_FLOAT; x->x_vec[i].a_type = A_FLOAT;
x->x_vec[i].a_w.w_float = x->argv[i]; x->x_vec[i].a_w.w_float = x->argv[i];
@ -342,26 +342,26 @@ void *bird_new(void)
bird_t *x; bird_t *x;
x = (bird_t *)pd_new(bird_class); x = (bird_t *)pd_new(bird_class);
outlet_new(&x->x_obj, &s_list); outlet_new(&x->x_obj, &s_list);
x->x_out2 = outlet_new(&x->x_obj, &s_float); x->x_out2 = outlet_new(&x->x_obj, &s_float);
x->x_vec = (t_atom *)getbytes((x->x_n=B_MAX_DATA) * sizeof(*x->x_vec)); x->x_vec = (t_atom *)getbytes((x->x_n=B_MAX_DATA) * sizeof(*x->x_vec));
bird_init(x); bird_init(x);
bird_setwritefun(x,bird_output); bird_setwritefun(x,bird_output);
bird_set(x,"RUN",NULL); bird_set(x,"RUN",NULL);
bird_set(x,"POSANG",NULL); bird_set(x,"POSANG",NULL);
// out_byte('W'); // out_byte('W');
bird_set(x,"POINT",NULL); bird_set(x,"POINT",NULL);
// out_byte(64); // out_byte(64);
x->verbose = 0; x->verbose = 0;
return (void *)x; return (void *)x;
} }
@ -371,11 +371,10 @@ void bird_setup(void)
(t_method)bird_free, sizeof(bird_t), 0, 0); (t_method)bird_free, sizeof(bird_t), 0, 0);
/* maximum commandatasize is 6*/ /* maximum commandatasize is 6*/
class_addmethod(bird_class, (t_method)bird_setting, gensym("set"), A_GIMME, 0); class_addmethod(bird_class, (t_method)bird_setting, gensym("set"), A_GIMME, 0);
class_addmethod(bird_class, (t_method)bird_verbose, gensym("verbose"), A_FLOAT, 0); class_addmethod(bird_class, (t_method)bird_verbose, gensym("verbose"), A_FLOAT, 0);
class_addbang(bird_class,bird_bang); class_addbang(bird_class,bird_bang);
class_addfloat(bird_class, bird_float); class_addfloat(bird_class, bird_float);
} }

View file

@ -61,9 +61,11 @@ typedef struct comport
struct termios oldcom_termio; /* save the old com config */ struct termios oldcom_termio; /* save the old com config */
struct termios com_termio; /* for the new com config */ struct termios com_termio; /* for the new com config */
#endif #endif
t_symbol *serial_device; t_symbol *serial_device;
char serial_device_prefix[FILENAME_MAX];/* the device name without the number */ char serial_device_prefix[FILENAME_MAX];/* the device name without the number */
short comport; /* holds the comport # */ short comport; /* holds the comport # */
t_float baud; /* holds the current baud rate */ t_float baud; /* holds the current baud rate */
t_float data_bits; /* holds the current number of data bits */ t_float data_bits; /* holds the current number of data bits */
t_float parity_bit; /* holds the current parity */ t_float parity_bit; /* holds the current parity */
@ -71,6 +73,7 @@ typedef struct comport
int xonxoff; /* nonzero if xonxoff handshaking is on */ int xonxoff; /* nonzero if xonxoff handshaking is on */
int ctsrts; /* nonzero if ctsrts handshaking is on */ int ctsrts; /* nonzero if ctsrts handshaking is on */
int hupcl; /* nonzero if hang-up on close is on */ int hupcl; /* nonzero if hang-up on close is on */
short rxerrors; /* holds the rx line errors */ short rxerrors; /* holds the rx line errors */
t_clock *x_clock; t_clock *x_clock;
int x_hit; int x_hit;
@ -1153,7 +1156,7 @@ static void comport_tick(t_comport *x)
* port gets interrupted, like if the USB gets yanked * port gets interrupted, like if the USB gets yanked
* out or a bluetooth connection drops */ * out or a bluetooth connection drops */
if(x->x_retry_count < x->x_retries) if(x->x_retry_count < x->x_retries)
{ {
t_atom retrying_atom; t_atom retrying_atom;
SETFLOAT(&retrying_atom, x->x_retry_count); SETFLOAT(&retrying_atom, x->x_retry_count);
outlet_anything(x->x_status_outlet, gensym("retrying"), 1, &retrying_atom); outlet_anything(x->x_status_outlet, gensym("retrying"), 1, &retrying_atom);
@ -1172,7 +1175,7 @@ static void comport_tick(t_comport *x)
comport_close(x); comport_close(x);
} }
} }
else else
whicherr = errno; whicherr = errno;
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
@ -1241,13 +1244,13 @@ static int write_serial(t_comport *x, unsigned char serial_byte)
if(x->comhandle == INVALID_HANDLE_VALUE) if(x->comhandle == INVALID_HANDLE_VALUE)
{ {
comport_verbose ("[comport]: Serial port is not open"); comport_verbose ("[comport]: Serial port is not open");
return 0; return 0;
} }
else if(x->x_outbuf_wr_index < x->x_outbuf_len) else if(x->x_outbuf_wr_index < x->x_outbuf_len)
{ {
x->x_outbuf[x->x_outbuf_wr_index++] = serial_byte; x->x_outbuf[x->x_outbuf_wr_index++] = serial_byte;
return 1; return 1;
} }
/* handle overrun error */ /* handle overrun error */
pd_error (x, "[comport]: buffer is full"); pd_error (x, "[comport]: buffer is full");
return 0; return 0;
@ -1259,7 +1262,7 @@ static int write_serials(t_comport *x, unsigned char *serial_buf, int buf_length
if(x->comhandle == INVALID_HANDLE_VALUE) if(x->comhandle == INVALID_HANDLE_VALUE)
{ {
pd_error (x, "[comport]: Serial port is not open"); pd_error (x, "[comport]: Serial port is not open");
return 0; return 0;
} }
for (i = 0; ((i < buf_length) && (x->x_outbuf_wr_index < x->x_outbuf_len)); ++x->x_outbuf_wr_index, ++i) for (i = 0; ((i < buf_length) && (x->x_outbuf_wr_index < x->x_outbuf_len)); ++x->x_outbuf_wr_index, ++i)
x->x_outbuf[x->x_outbuf_wr_index] = serial_buf[i]; x->x_outbuf[x->x_outbuf_wr_index] = serial_buf[i];
@ -2054,4 +2057,3 @@ void comport_setup(void)
"LGPL 1998-2015, Winfried Ritsch and others (see LICENSE.txt)\n" "LGPL 1998-2015, Winfried Ritsch and others (see LICENSE.txt)\n"
"Institute for Electronic Music - Graz"); "Institute for Electronic Music - Graz");
} }