Pages: 1 [2]   Go Down
Author Topic: Is there an easier way to do all of this?  (Read 1554 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
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
}
Logged

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

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8621
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pennsylvania
Offline Offline
Newbie
*
Karma: 0
Posts: 42
"There is no try. There is only do, and do not."
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
« Last Edit: September 11, 2012, 01:09:45 pm by AWOL » Logged

"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.

Pennsylvania
Offline Offline
Newbie
*
Karma: 0
Posts: 42
"There is no try. There is only do, and do not."
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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;
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.

Logged

"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.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
r = chan/3;
g = r + 1;
b = g + 1;
Logged

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Pennsylvania
Offline Offline
Newbie
*
Karma: 0
Posts: 42
"There is no try. There is only do, and do not."
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
chan = atoi(chan);
?
« Last Edit: September 11, 2012, 04:16:39 pm by AWOL » Logged

"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.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8621
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

  smiley-red
Logged

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

Pages: 1 [2]   Go Up
Jump to: