Re: [tuxdroid-user] Daemon to USB connection
Status: Beta
Brought to you by:
ks156
From: David B. <da...@ja...> - 2007-06-02 20:59:17
|
On Sat, 02 Jun 2007 10:01:06 +0200, neimad <ror...@gm...> wrote= : > [...] I always put the comment on the line before the statement, so > I would write your example above as follows: > > /* wait 200ms for the pull-up to rise before next standalone > * behavior otherwise position switches signals are wrong */ > event_timer =3D 2; > Thanks, that's what I wanted to know, though I'm so used to it that I'll= = have a hard time ... ;-) What about defines, enums, etc., you'd put the comment/description of = define_1 on the right or on the line before? enum my_enum { define_1, define_2, } >> There's the same for function calls, should we do >> void my_long_function_call(parameter_1, parameter_2, parameter_= 3, >> parameter_4) >> or >> void my_long_function_call(parameter_1, parameter_2, parameter_= 3, >> parameter_4) > > Both styles are ok and I have used both. Depends on the coding style > conventions. (For the second one, it is advised to indent the second > part with two indentation levels.) > > I prefer the first one though, as I find it a bit cleaner (and it is > how Emacs indents C by default ;-)). vi defaults to the second, I think we'll never agree on this ;-) > [...] > Hmm, ok then. If you have pointers on embedded-specific programming > practices, I'd be very interested (if only to avoid committing code > considered bad from an embedded pov). Looking into this again (to find you some pointers), I'm not sure my = previous statement was right, I'll have to do some tests again. This was= = discussed on the avrlibc mailing list some time ago. But what I'm sure n= ow = is that a swicth can be very efficient if all cases are incremental as i= t = can use a lookup table, otherwise it generates a if-then-else sequence = which takes much more space. In i2c.c (tuxcore) I created the lookup tab= le = manually as the compiler never wanted to do it, and I saved more than 10= 0 = bytes doing so. I'll let you know if I find something interesting. > In commit r335: > > typedef enum > { > USB_CONNECTION_CONNECT =3D 1, > USB_CONNECTION_DISCONNECT =3D 2, > USB_CONNECTION_ID_LOOKUP =3D 3, > USB_CONNECTION_CHANGE_ID =3D 4, > USB_CONNECTION_WAKEUP =3D 5, > USB_CONNECTION_WIRELESS_CHANNEL =3D 6, > } USB_ID_PARAM1; > > The type is badly named: "USB_ID_PARAM1" is about its *use* whereas > its name should really be about what it *is*. Well, it *is* the first parameter of the USB ID command which I later = renamed USB connection command and probably forgot about it here. > > Thus I would rather have the following: > > typedef enum > { > USB_CONNECTION_CONNECT =3D 1, > USB_CONNECTION_DISCONNECT =3D 2, > USB_CONNECTION_ID_LOOKUP =3D 3, > USB_CONNECTION_CHANGE_ID =3D 4, > USB_CONNECTION_WAKEUP =3D 5, > USB_CONNECTION_WIRELESS_CHANNEL =3D 6, > } usb_connection_t; > > The type is in lower case suffixed instead of all-uppercase, it is > suffixed with _t (a widespread convention) and it is consistent with > its values: usb_connection_t / USB_CONNECTION_xxx Yep, my fault, I was probably asleep at the time I wrote that. I'll fix = = it, write it 100 times and go to sleep without eating ;-) Thanks, David |