Skip to content

Commit

Permalink
change function name
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Chen authored and Spencer Chen committed Nov 16, 2022
1 parent 96bd1a5 commit 6dc2f85
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 9 deletions.
60 changes: 55 additions & 5 deletions src/VescUart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ VescUart::VescUart(uint32_t timeout_ms) : _TIMEOUT(timeout_ms)
nunchuck.valueY = 127;
nunchuck.lowerButton = false;
nunchuck.upperButton = false;

appData.dutyCycle=0;
appData.erpm=0;
appData.inputVoltage=0;
appData.loopTime=0;
appData.motorCurrent=0;
appData.pidOutput=0;
appData.pitch=0;
appData.roll=0;
appData.state=0;
appData.switchState=0;
appData.vescId=0;
}

void VescUart::setSerialPort(Stream *port)
Expand Down Expand Up @@ -260,6 +272,7 @@ bool VescUart::processReadPacket(uint8_t *message)
appData.dutyCycle = buffer_get_float16(message, 1e3, &index);//2byte
appData.erpm=buffer_get_float32(message, 1e0, &index); //4byte ;
appData.inputVoltage=buffer_get_float16(message, 1e1, &index); //2byte ;

return true;
break;
default:
Expand Down Expand Up @@ -568,9 +581,9 @@ void VescUart::printCustomValues()
* @return true
* @return false
*/
bool VescUart::getCustomValues()
bool VescUart::updateCustomValues()
{
return getCustomValues(0);
return updateCustomValues(0);

}

Expand All @@ -582,7 +595,7 @@ bool VescUart::getCustomValues()
* loop_time (uint32_t)
* State(uint16_t)
* Switch State(uint16_t)
* Other : Kill_sw_mode (uint16_t)
* Other : vesc id (uint16_t)
* duty cycle (float)
* erpm (float)
* input voltage(float)
Expand All @@ -591,7 +604,7 @@ bool VescUart::getCustomValues()
* @return true
* @return false
*/
bool VescUart::getCustomValues(uint8_t canId)
bool VescUart::updateCustomValues(uint8_t canId)
{
if (debugPort != NULL)
{
Expand All @@ -617,4 +630,41 @@ bool VescUart::getCustomValues(uint8_t canId)
return processReadPacket(message);
}
return false;
}
}


/**
* @brief Return PID OUTPUT
* should call updateCustomValues() first.
*/
float VescUart::getPidOUtput()
{
return appData.pidOutput;
}
/**
* @brief return erpm
* should call updateCustomValues() first.
*/
float VescUart::getErpm()
{

return appData.erpm;
}
/**
* @brief return Switch state
* should call updateCustomValues() first.
*/
uint16_t VescUart::getSwitchState()
{
return appData.switchState;
}
/**
* @brief return VESC ID to control Audio source
* should call updateCustomValues() first.
*/
uint16_t VescUart::getVescId()
{
return appData.vescId;
}


29 changes: 25 additions & 4 deletions src/VescUart.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class VescUart
/** Variabel to hold measurements returned from VESC */
dataPackage data;

customData appData;

/** Variabel to hold nunchuck values */
nunchuckPackage nunchuck;

Expand Down Expand Up @@ -211,15 +211,34 @@ class VescUart
* @brief get the balance data
*
*/
bool getCustomValues( uint8_t canId);
bool updateCustomValues( uint8_t canId);
/**
* @brief Get the Custom Config object
*
* @return true
* @return false
*/
bool getCustomValues( );

bool updateCustomValues( );
/**
* @brief Return PID OUTPUT
* should call updateCustomValues() first.
*/
float getPidOUtput();
/**
* @brief return erpm
* should call updateCustomValues() first.
*/
float getErpm();
/**
* @brief return Switch state
* should call updateCustomValues() first.
*/
uint16_t getSwitchState();
/**
* @brief return VESC ID to control Audio source
* should call updateCustomValues() first.
*/
uint16_t getVescId();


private:
Expand All @@ -230,6 +249,8 @@ bool getCustomValues( );
* Uses the class Stream instead of HarwareSerial */
Stream *debugPort = NULL;

customData appData;

/**
* @brief Packs the payload and sends it over Serial
*
Expand Down

0 comments on commit 6dc2f85

Please sign in to comment.