Go Down

Topic: Is there an easier way to do all of this? (Read 1 time) previous topic - next topic

PeterH



No, I'm so used to HTML that this is the structure I am used to seeing, and makes it easier for me to read my own code... Even my java looks like that...



It's your code at the end of the day, but I think you're making a mistake. 'C'/C++ and Java are not HTML/XML. In particular, they are not validated XML. Using an indenting scheme that makes it easy to validate the actual control structure (defined by the braces) against the apparent control structure (implied by the indentation) is much more important for these languages than it is for HTML/XML. Your coding style doesn't really do that, because the matching pairs of { and } do not stand out.


I have no idea what a bounds check is...

I mean check the number of elements already used in the array before appending a new element, to ensure that you don't try to use more elements than the array contains. The way I recommend to do that is to define a constant defining the number of character the array will hold, and declare the array as that size + 1, where the '+1' is the space reserved for the final terminating character. Then you can do something like:
Code: [Select]

const int BufferLength = 32; // or whatever the length is - I forget
char buffer[BufferLength+1]; // allow space for a null terminator
...
if(serialIn < BufferLength)
{
   buffer[serialIn++] = incomingByte;
   buffer[serialIn] = 0; // reterminate the string
}
else
{
   // buffer is full - discard the character
}

I only provide help via the forum - please do not contact me for private consultancy.

Graynomad

Quote
"Sorry, the lines are too clutter, could you please correct it and resend to pcb@seeedstudio.com ."

Nice of them to point out the problem in unambiguous terms :)

I assume they are referring to the clearances, but where? It looks OK from what I can tell at that resolution. You say it passes DRC, using their values I assume? Maybe you could post the design files if they are in a format some of us have.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

dpmattox

http://pastebin.com/Fpy9ZTdj

I have updated the code to remove the repitition, still haven't finished saving, or all of the modes. I will be goign through and adding in the suggestions I have gotten later this evening or tomorrow(back and forth between this and the android app).
Quote
Maybe you could post the design files if they are in a format some of us have.

I have Eagle, and gerbers, but these are not images, my server has no domain, and it would be an abuse of my corporate hosting account to put anything personal up. How do you suggest sharing my files?

AWOL

#18
Sep 11, 2012, 08:07 pm Last Edit: Sep 11, 2012, 08:09 pm by AWOL Reason: 1
Code: [Select]
switch(chan)
181. {
182. case 0:
183. r = 0;
184. g = r++;
185. b = g++;
186. break;
187. case 1:
188. r = 3;
189. g = r++;
190. b = g++;
191. break;
etc..

This should be simple arithmetic, or a table, not a switch/case.

I'm not even sure your arithmetic is correct.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dpmattox

they are the output pins of the TLC5940
Red, Green, and Blue
channel 0 is ouptuts 0,1,2
channel 1 is outputs 3,4,5
channel 2 is outputs 6,7,8
channel 3 is outputs 9,10,11
channel 4 is outputs 12,13,14

so

Code: [Select]
switch(chan)
181. {
182. case 0:
183. r = 0; // 0
184. g = r++; // 1
185. b = g++; // 2
186. break; // I'll admit, I thought the increments looked a lot cooler than r=0, g=1, b=2 (yes, I am a bit immature)
187. case 1:
188. r = 3; // I know you really like tables, matrices, 2d arrays; but, I am sure 100% sure that looking these simple values up like
189. g = r++; // that would be slower than this, even if there is a better way than this...
190. b = g++;
191. break;

AWOL

Code: [Select]
channel 0 is ouptuts 0,1,2 channel 1 is outputs 3,4,5 channel 2 is outputs 6,7,8 channel 3 is outputs 9,10,11 channel 4 is outputs 12,13,14
There's a very simple formula in there, screaming to be let out.

Increments may look cool, but they have a nasty side-effect, which you'll find when you come to try the code out.
Best to anticipate it though.

Yes, you're right, I do like tables.
They allow a degree of flexibility if you decide to change your wiring that arithmetic may not.
And I really would not worry about speed where these values are concerned.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PeterH


Code: [Select]

switch(chan)
181. {
182. case 0:
183. r = 0; // 0
184. g = r++; // 1
185. b = g++; // 2
186. break; // I'll admit, I thought the increments looked a lot cooler than r=0, g=1, b=2 (yes, I am a bit immature)


The uncool version does have the advantage of giving you the right answer, though.
Fortunately, when you get fed up with debugging the 'cool' version you can replace the whole thing with :
Code: [Select]

r = chan/3;
g = r + 1;
b = g + 1;
I only provide help via the forum - please do not contact me for private consultancy.

AWOL

And when you get bored of debugging that, use a multiplication instead of a division
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dpmattox

Got rid of that ugly math, thanks guys, and sortData() is a result of complaints about invalid Char to int conversions. data[chan][0] = atoi(red); doesn't work.

AWOL

#24
Sep 11, 2012, 11:13 pm Last Edit: Sep 11, 2012, 11:16 pm by AWOL Reason: 1
Quote
data[chan][0] = atoi(red); doesn't work.

What does that mean?
It doesn't like data because rows and cols are declared after you used them?

Or because of this
Code: [Select]
chan = atoi(chan); ?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Graynomad

Quote
I have Eagle, ... How do you suggest sharing my files?

Just attach them to a post here if they are < 4Mb.

Otherwise you'll need a host somewhere.

_______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

PeterH


And when you get bored of debugging that, use a multiplication instead of a division


  :smiley-red:
I only provide help via the forum - please do not contact me for private consultancy.

Go Up