Skip to content

Commit

Permalink
Changed comments
Browse files Browse the repository at this point in the history
Removed extraneous code, standardized internal variable names
  • Loading branch information
SV-Zanshin committed Aug 21, 2017
1 parent db9b651 commit 3be894d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
28 changes: 18 additions & 10 deletions Cubigel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/*******************************************************************************************************************
** This program defines the Cubigel class. See the "Cubigel.h" file for program documentation and versions **
** This file defines the Cubigel class, see the "Cubigel.h" file for program documentation & version information. **
** **
** This program is free software: you can redistribute it and/or modify it under the terms of the GNU General **
** Public License as published by the Free Software Foundation, either version 3 of the License, or (at your **
** option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY **
** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU General Public License for more details. You should have received a copy of the GNU General Public License **
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
** **
*******************************************************************************************************************/
#include <SoftwareSerial.h> // Include the software serial lib //
#include "Cubigel.h" // Include the header file //
Expand All @@ -16,7 +24,7 @@ CubigelClass::CubigelClass( SoftwareSerial *ser1) { //
ClassPtr = this; // pointer to current instance //
devices[0].serialSW = ser1; // point to the appropriate port //
devices[0].serialSW->begin(CUBIGEL_BAUD_RATE); // Set baud rate to Cubigel speed //
deviceCount = 1; // Store the number of devices //
_deviceCount = 1; // Store the number of devices //
StartTimer(); // Enable timer interrupts //
setMode(0,MODE_SETTINGS); // Retrieve settings on first call //
} // of class constructor // //
Expand All @@ -25,7 +33,7 @@ CubigelClass::CubigelClass( HardwareSerial *ser1) { //
ClassPtr = this; // pointer to current instance //
devices[0].serialHW = ser1; // point to the appropriate port //
devices[0].serialHW->begin(CUBIGEL_BAUD_RATE); // Set baud rate to Cubigel speed //
deviceCount = 1; // Store the number of devices //
_deviceCount = 1; // Store the number of devices //
StartTimer(); // Enable timer interrupts //
setMode(0,MODE_SETTINGS); // Retrieve settings on first call //
} // of class constructor //----------------------------------//
Expand All @@ -36,7 +44,7 @@ CubigelClass::CubigelClass( HardwareSerial *ser1, //
devices[0].serialHW->begin(CUBIGEL_BAUD_RATE); // Set baud rate to Cubigel speed //
devices[1].serialSW = ser2; // point to the appropriate port //
devices[1].serialSW->begin(CUBIGEL_BAUD_RATE); // Set baud rate to Cubigel speed //
deviceCount = 2; // Store the number of devices //
_deviceCount = 2; // Store the number of devices //
StartTimer(); // Enable timer interrupts //
setMode(0,MODE_SETTINGS); // Retrieve settings on first call //
setMode(1,MODE_SETTINGS); // Retrieve settings on first call //
Expand All @@ -48,7 +56,7 @@ CubigelClass::CubigelClass( SoftwareSerial *ser1, //
devices[0].serialSW->begin(CUBIGEL_BAUD_RATE); // Set baud rate to Cubigel speed //
devices[1].serialHW = ser2; // point to the appropriate port //
devices[1].serialHW->begin(CUBIGEL_BAUD_RATE); // Set baud rate to Cubigel speed //
deviceCount = 2; // Store the number of devices //
_deviceCount = 2; // Store the number of devices //
StartTimer(); // Enable timer interrupts //
setMode(0,MODE_SETTINGS); // Retrieve settings on first call //
setMode(1,MODE_SETTINGS); // Retrieve settings on first call //
Expand All @@ -60,7 +68,7 @@ CubigelClass::CubigelClass( HardwareSerial *ser1, //
devices[0].serialHW->begin(CUBIGEL_BAUD_RATE); // Set baud rate to Cubigel speed //
devices[1].serialHW = ser2; // point to the appropriate port //
devices[1].serialHW->begin(CUBIGEL_BAUD_RATE); // Set baud rate to Cubigel speed //
deviceCount = 2; // Store the number of devices //
_deviceCount = 2; // Store the number of devices //
StartTimer(); // Enable timer interrupts //
setMode(0,MODE_SETTINGS); // Retrieve settings on first call //
setMode(1,MODE_SETTINGS); // Retrieve settings on first call //
Expand Down Expand Up @@ -92,7 +100,7 @@ static void CubigelClass::TimerISR() {ClassPtr->TimerHandler();} //
** data in them are processed using the "processDevice"function, which does the heavy lifting. **
*******************************************************************************************************************/
void CubigelClass::TimerHandler() { // //
for (uint8_t idx=0;idx<deviceCount;idx++) { // For each defined device //
for (uint8_t idx=0;idx<_deviceCount;idx++) { // For each defined device //
if (devices[idx].serialSW) { // if we are using software serial, //
if (devices[idx].serialSW->available()) processDevice(idx); // check to see if there is any data//
} else { // otherwise we are using HW serial //
Expand All @@ -107,7 +115,7 @@ void CubigelClass::TimerHandler() { //
*******************************************************************************************************************/
uint16_t CubigelClass::readValues(const uint8_t idx,uint16_t &RPM,uint16_t &mA,// //
const bool resetReadings) { // //
if (idx>=deviceCount) return 0; // just return nothing if invalid //
if (idx>=_deviceCount) return 0; // just return nothing if invalid //
cli(); // Disable interrupts //
RPM = devices[idx].totalRPM/devices[idx].readings; // set the averaged RPM value //
mA = devices[idx].totalmA/devices[idx].readings; // set the averaged mA value //
Expand All @@ -129,7 +137,7 @@ uint16_t CubigelClass::readValues(const uint8_t idx,uint16_t &RPM,uint16_t &mA,/
uint16_t CubigelClass::readValues(const uint8_t idx,uint16_t &RPM,uint16_t &mA,// //
uint16_t &commsErrors, uint16_t errorStatus,// //
const bool resetReadings) { // //
if (idx>=deviceCount) return 0; // just return nothing if invalid //
if (idx>=_deviceCount) return 0; // just return nothing if invalid //
cli(); // Disable interrupts //
RPM = devices[idx].totalRPM/devices[idx].readings; // set the averaged RPM value //
mA = devices[idx].totalmA/devices[idx].readings; // set the averaged mA value //
Expand All @@ -153,7 +161,7 @@ uint16_t CubigelClass::readValues(const uint8_t idx,uint16_t &RPM,uint16_t &mA,/
void CubigelClass::setMode(const uint8_t idx, const uint8_t mode) { // Set Cubigel FDC1 mode //
uint8_t modeByte = 0; // Byte to set state, default is 0 //
if (mode==1) modeByte = 192; // Mode 0 is the default //
if (idx>=deviceCount) return 0; // just return nothing if invalid //
if (idx>=_deviceCount) return 0; // just return nothing if invalid //
if (devices[idx].serialSW) { // if we are using software serial, //
devices[idx].serialSW->write((uint8_t)72); // Write control information //
devices[idx].serialSW->write((uint8_t)80); // Write control information //
Expand Down
16 changes: 10 additions & 6 deletions Cubigel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
** accessed using this library. The detailed protocol description can be downloaded as a PDF file from **
** https://www.sv-zanshin.com/r/manuals/cubigel_fdc1_communication_protocol.pdf **
** **
** The most recent version of the library is at https://github.com/SV-Zanshin/Cubigel/archive/master.zip and the **
** library wiki is to be found https://github.com/SV-Zanshin/Cubigel/wiki. **
** **
** This library uses the Arduino SoftwareSerial library, and it is important to only use those pins which support **
** pin change interrupts for the fridge and freezer inputs. A good description of the pins and their uses can be **
** found at https://www.arduino.cc/en/Reference/AttachInterrupt. **
Expand Down Expand Up @@ -31,6 +34,7 @@
** **
** Vers. Date Developer Comments **
** ====== ========== =================== ======================================================================== **
** 1.0.2 2017-08-21 Arnd@SV-Zanshin.Com Removed extraneous code, changed comments **
** 1.0.1 2017-07-31 Arnd@SV-Zanshin.Com Prototypes contain optional parameter definitions, functions no longer **
** have them declared as non-Windows compilers fail when they do **
** 1.0.0 2017-04-19 Arnd@SV-Zanshin.Com Cleaned up debugging code and ready for first release **
Expand All @@ -42,10 +46,10 @@
#include "SoftwareSerial.h" // Software serial port emulation //
#ifndef Cubigel_h // Guard code definition //
#define Cubigel_h // Define the name inside guard code//
const uint16_t CUBIGEL_BAUD_RATE = 1200; // Cubigel has a fixed baud rate //
const uint8_t CUBIGEL_MAX_DEVICES = 2; // Max number of devices supported //
const uint8_t MODE_DEFAULT = 0; // Default output mode //
const uint8_t MODE_SETTINGS = 1; // Output settings mode //
const uint16_t CUBIGEL_BAUD_RATE = 1200; // Cubigel has a fixed baud rate //
const uint8_t CUBIGEL_MAX_DEVICES = 2; // Max number of devices supported //
const uint8_t MODE_DEFAULT = 0; // Default output mode //
const uint8_t MODE_SETTINGS = 1; // Output settings mode //
/*****************************************************************************************************************
** This structure contains all of the variables stored per Cubigel device **
*****************************************************************************************************************/
Expand Down Expand Up @@ -108,8 +112,8 @@
void processDevice(const uint8_t deviceNumber); // read and store data for a device //
void TimerHandler(); // Called every millisecond for fade//
static CubigelClass* ClassPtr; // store pointer to class itself //
bool FreezerPresent = false; // Switch denoting if a freezer set //
uint8_t deviceCount = 0; // Number of devices instantiated //
bool _freezerPresent = false; // Switch denoting if a freezer set //
uint8_t _deviceCount = 0; // Number of devices instantiated //
volatile CubigelDataType devices[CUBIGEL_MAX_DEVICES]; // Declare storage for max devices //
}; // of class header definition for CubigelClass //----------------------------------//
#endif
Loading

0 comments on commit 3be894d

Please sign in to comment.