EIT-team / ScouseTom

Open Source EIT system using Keithley 6221 current source and EEG systems
GNU General Public License v3.0
26 stars 7 forks source link

Simplify Arduino code #22

Open raquelalegre opened 9 years ago

raquelalegre commented 9 years ago

I've detected a few things that can be simplified in the Arduino code to make it more readable and/or efficient. I thought I could list some of them in this issue as I run into them, we can then replace them together and hope you keep them in mind when you develop in the future.

raquelalegre commented 9 years ago

In CS_comm.ino:

As is now:

int CS_checkresponse(String Str_exp) {

    //compare intput string and string in input buffer
    int respflag = 0;
    /*
      Serial.print("This just in ... ");
      Serial.println(CS_inputBuffer);
      Serial.print("expected ");
      Serial.println(Str_exp);
      */
    if (Str_exp == CS_inputBuffer)
    {
        // Serial.println("they match");
        respflag = 1;
    }
    else
    {
        // Serial.println("they dont match");
        respflag = 0;
    }
    return respflag;
}

Could be something like:

/*
* Compares given string and CS input buffer.
* @param input Whatever this argument represents
* @return Strings match
*/
boolean CS_CheckResponse(String response) {

    return response == CS_InputBuffer;
}
raquelalegre commented 9 years ago

Some variables might benefit from being declared as volatile. The Arduino documentation explains why. Check variables involved in attachInterrupt calls in Stim.ino and CS_Pmark_Test.ino.

Jimbles commented 8 years ago

Started refactoring in libaries in branch Making Library 50ec7c0d0b8c9581a3646ebd373b35f74946393d and ran into loads of interdependency problems. Code has too many globals and stuff at the moment. So some refactoring would be needed along with simplification. Focusing on development for now