HELP DISCRIBE REST OF CODE -- URGENT

#if defined(ARDUINO) && ARDUINO >= 100
#include “Arduino.h”
#include “SoftwareSerial.h”
SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
#include “WProgram.h”
#include “NewSoftSerial.h”
NewSoftSerial port(12,13);
#endif

#include “EasyVR.h”
#include <Servo.h>

#define SND_Access_denied 1
#define SND_Access_granted 2
#define SND_Hello 3
#define SND_Please_repeat 4
#define SND_Please_say_your_password 5
#define SND_Please_talk_louder 6

Servo myservo;
EasyVR easyvr(port);
EasyVRBridge bridge;

uint32_t mask = 0;
int8_t group = 0;
uint8_t train = 0;
char name[32];

void setup()
{
// bridge mode?
if (bridge.check())
{
cli();
bridge.loop(0, 1, 12, 13);
}

Serial.begin(9600);
port.begin(9600);

myservo.attach(9);
myservo.write(90);

if (!easyvr.detect())
{
Serial.println(“EasyVR not detected!”);
for (;;);
}

easyvr.setPinOutput(EasyVR::IO1, LOW);
Serial.println(“EasyVR detected!”);
easyvr.setTimeout(5);
easyvr.setLanguage(EasyVR::ITALIAN);

int16_t count = 0;

if (easyvr.getGroupMask(mask)) // get trained user names and passwords
{
uint32_t msk = mask;
for (group = 0; group <= EasyVR::PASSWORD; ++group, msk >>= 1)
{
if (!(msk & 1)) continue;
if (group == EasyVR::TRIGGER)
Serial.print("Trigger: ");
else if (group == EasyVR::PASSWORD)
Serial.print("Password: “);
else
{
Serial.print(“Group “);
Serial.print(group);
Serial.print(”: “);
}
count = easyvr.getCommandCount(group);
Serial.println(count);
for (int8_t idx = 0; idx < count; ++idx)
{
if (easyvr.dumpCommand(group, idx, name, train))
{
Serial.print(idx);
Serial.print(” = “);
Serial.print(name);
Serial.print(”, Trained “);
Serial.print(train, DEC);
if (!easyvr.isConflict())
Serial.println(” times, OK”);
else
{
int8_t confl = easyvr.getWord();
if (confl >= 0)
Serial.print(” times, Similar to Word “);
else
{
confl = easyvr.getCommand();
Serial.print(” times, Similar to Command ");
}
Serial.println(confl);
}
}
}
}
}
easyvr.setLevel(EasyVR::HARDER);
easyvr.playSound(SND_Hello, EasyVR::VOL_FULL);
}

void loop()
{
int idx_cmd;
int idx_pwd;

easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)

Serial.println(“Say a name in Group 1”);
easyvr.recognizeCommand(1); // recognise command in group 1
while (!easyvr.hasFinished()); // wait for user name

easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

idx_cmd = easyvr.getCommand(); // get recognised user name

if (idx_cmd >= 0)
{
Serial.print("Name: ");
if (easyvr.dumpCommand(1, idx_cmd, name, train))
Serial.println(name);
else
Serial.println();

easyvr.playSound(SND_Please_say_your_password , EasyVR::VOL_FULL); // ask for password

easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)

Serial.println(“Say the password”);
easyvr.recognizeCommand(EasyVR::PASSWORD); // set group 16
while (!easyvr.hasFinished()); // wait for password

easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

idx_pwd = easyvr.getCommand(); // get recognised password

if (idx_pwd >= 0)
{
Serial.print("Password: ");

if (easyvr.dumpCommand(EasyVR::PASSWORD, idx_pwd, name, train))
{
Serial.print(" = ");
Serial.println(name);
}
else
Serial.println();

if ( idx_pwd == idx_cmd) // index of username and password are the same, access granted
{

Serial.println(“Access granted”);
easyvr.playSound(SND_Access_granted , EasyVR::VOL_FULL);

myservo.write(180); // move servo
delay(2500); // wait a while
myservo.write(90); // move servo
}
else // index of username and password differ, access is denied
{
Serial.println(“Access denied”);
easyvr.playSound(SND_Access_denied , EasyVR::VOL_FULL);
}

}

int16_t err = easyvr.getError();

if (easyvr.isTimeout() || (err >= 0)) // password timeout, access is denied
{

Serial.println(“Error, try again…”);
easyvr.playSound(SND_Access_denied , EasyVR::VOL_FULL);

}
}

else
{
if (easyvr.isTimeout())
Serial.println(“Timed out, try again…”);

int16_t err = easyvr.getError();
if (err >= 0)
{
Serial.print("Error ");
Serial.println(err, HEX);
}
}
}

WTF

always use code tags.

Mark

Hi ,

if you need help, you should :

1 - say "Hello" (or "Hi") // not mandatory, but 8) 2 - read this http://forum.arduino.cc/index.php?topic=97455.0 3 - describe why you need help, what do you expect from people here ? 4 - post your whole code, using code tags ... as described in point 2 5 - not SHOUT, it won't make the answers come faster

You have to be shitting me, shouting the title, no code tags, no real question, and 500 lines of code you want us to "discribe". It ain't urgent for us.


Rob

"Urgent" as in my homework is overdue? Otherwise known as "OK so I've ripped off this code I found on the internet, but if I can't explain how it works then my teacher isn't going to believe I wrote it ..."

I'd be happy to!

      Serial.println(err, HEX);         
    }
  }
}

Prints an error code in hexadecimal to the Serial port. end of an if statement. end of an else statement end of loop()

Glad I could be of assistance.

I tried to compile the code you posted but it failed.

OK a few words about comments.

If you use good variable and function names then you do not need comments. (OK minimal) A few reasons why: - it saves you time when you write it, - it saves the compiler time when she parses it, - it saves a reader of the code time when he reads it, - it prevents mismatches between code and comment, due to not updating

from your code two commented lines, that conflict

while (!easyvr.hasFinished()); // wait for user name
while (!easyvr.hasFinished()); // wait for password

suppose you had written

 while( waitForUserName());
 while( waitForPassword());

it would be self documenting and probably correct,

Comments when used explain the WHY of the code, not the HOW or the WHAT. (comment can be the bridge between requirements and implementation)

Example:

// need to fetch the username and password to give only privileged people access to the system
 while( waitForUserName());
 while( waitForPassword());

Another common mistake, this comment repeats the code, why? The command itself explains itself for 90%

easyvr.recognizeCommand(1); // recognise command in group 1

to get 95% it should be something like:

#define GROUP1   1
easyvr.recognizeCommand(GROUP1);

to get 100% you give the GROUP1 a descriptive name

#define  DATABASE_COMMANDS 1
easyvr.recognizeCommand(DATABASE_COMMANDS );

This comment is my favorite from the code

delay(2500);      // wait a while

the comment does not explain anything, (OK a while takes 2500 milliseconds?)

In short, If you document the WHY in your code you will be ready in 15-30 minutes..

Ah.... so compilers are female Rob?

All is explained!

it saves a reader of the code time when he reads it,

and the readers are male.

I was wondering who would be the first to comment ;)

So compilers are female, programmers are (mostly) male, no bloody wonder programs hardly ever work without a lot of grief.


Rob

Alas the OP is nowhere to be seen ....

...R

Funny about that :slight_smile:

I can't help you until you:

Maybe then people will help you. [/code][/code]

Wait a second...why should we describe this? If you coded it, you would know what it was...

[u]DISCRIBE[/u] is actually spelt Describe! Wow!

robtillaart: - it saves the compiler time when she parses it, - it saves a reader of the code time when he reads it,

Whoooo, compilers are SHES? OH...MY...GAWD.... And why are you telling this guy about comments? If he wrote the code, he would know how it works without a "DISCRIBTION."

This is an example of exactly what NOT to do. Lawl. :grin:

Hey, check this out:

OOOO!!! WHATS THIS?

waterlubber: ...

robtillaart: - it saves the compiler time when she parses it, - it saves a reader of the code time when he reads it,

Whoooo, compilers are SHES? OH...MY...GAWD.... And why are you telling this guy about comments? If he wrote the code, he would know how it works without a "DISCRIBTION."

I am telling this guy about comments as it is imho the better way to educate him how to do it. It is relative easy to point out bad comments, it is much harder to write good ones. According to Uncle Bob Martin* "code should read like prose" and then you will not need comments.

*) - http://www.youtube.com/watch?v=asLUTiJJqdE - and - http://cleancoders.com/ -

robtillaart: Comments when used explain the WHY of the code, not the HOW or the WHAT.

I disagree slightly - comments can usefully explain [u]why[/u] something is done (describing what's happening in the context of higher level use cases) and [u]how[/u] something is being done (relating it to lower level use cases).

robtillaart:

waterlubber: ...

robtillaart: - it saves the compiler time when she parses it, - it saves a reader of the code time when he reads it,

Whoooo, compilers are SHES? OH...MY...GAWD.... And why are you telling this guy about comments? If he wrote the code, he would know how it works without a "DISCRIBTION."

I am telling this guy about comments as it is imho the better way to educate him how to do it. It is relative easy to point out bad comments, it is much harder to write good ones. According to Uncle Bob Martin* "code should read like prose" and then you will not need comments.

Okay you win it wasn't directed to you is was directed at the forum poster more. :3

Trying to 'speed' up the compilation up by deleting comments is misplaced optimization. The part of the compiler that skips comments is such a small part of normal compilation time, that unless you have megabytes of comments in a very simple source, you likely would not notice any difference in the speed of compilation comparing your code with comments and without. If you didn't optimize at all, you might have a slightly better chance of noticing a difference, but the IDE uses the -Os level, which is -O2 with adjustments made to save space instead of generating faster code.

BTW, I have worked on the GCC compiler since 1988 (with about 2 years off on other compilers). Measuring things like compiler speed, depends on many, many, many different factors. I have not looked at the timings for AVR code generation, but in the past on the x86, the compiler typically spent about 50% of its time in register allocation when compiling C code, due to the small numbers of registers (which I believe the AVR has the same types of issues). On machines like the powerpc with more registers, the compiler spends a bit less time in the register allocator, but it is still a significant chunk.

On some C++ codes, the compiler does spend significant time in the C++ front end, but this is usually due to large projects that have massive amounts of include files, and large amounts of classes, inline functions, etc. in those include files, so the compiler spends quite a bit of time building all of the internal trees to represent this code.

A discussion about angels on the heads of pins would be more constructive than a discussion about how long the Arduino compiler spends on comments in code.

...R