Major formatting changes (breaks diffs). No code changes.

The changes made in this commit do not affect any actual code,
    they are purely aesthetic. I ran clang-format with google style
    over all .h/.cpp files in wpilibc that weren't in wpilibC++Sim
    or gtest, and the eclipse formatter over all of the Java files
    using the Google eclipse formatting configuration.

Change-Id: I9627bca0bc103c398ecc1c5ba17467193291ae63
This commit is contained in:
James Kuszmaul
2015-06-25 15:07:55 -04:00
parent bd64d9a7ef
commit 7eb8550bdb
470 changed files with 89798 additions and 77287 deletions

View File

@@ -1,5 +1,6 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
@@ -16,16 +17,18 @@
/**
* Pause the task for a specified time.
*
* Pause the execution of the program for a specified period of time given in seconds.
* Motors will continue to run at their last assigned values, and sensors will continue to
* update. Only the task containing the wait will pause until the wait time is expired.
* Pause the execution of the program for a specified period of time given in
* seconds.
* Motors will continue to run at their last assigned values, and sensors will
* continue to
* update. Only the task containing the wait will pause until the wait time is
* expired.
*
* @param seconds Length of time to pause, in seconds.
*/
void Wait(double seconds)
{
if (seconds < 0.0) return;
delaySeconds(seconds);
void Wait(double seconds) {
if (seconds < 0.0) return;
delaySeconds(seconds);
}
/**
@@ -33,90 +36,82 @@ void Wait(double seconds)
* This is deprecated and just forwards to Timer::GetFPGATimestamp().
* @return Robot running time in seconds.
*/
double GetClock()
{
return Timer::GetFPGATimestamp();
}
double GetClock() { return Timer::GetFPGATimestamp(); }
/**
* @brief Gives real-time clock system time with nanosecond resolution
* @return The time, just in case you want the robot to start autonomous at 8pm on Saturday.
* @return The time, just in case you want the robot to start autonomous at 8pm
* on Saturday.
*/
double GetTime()
{
struct timespec tp;
double GetTime() {
struct timespec tp;
clock_gettime(CLOCK_REALTIME,&tp);
double realTime = (double)tp.tv_sec + (double)((double)tp.tv_nsec*1e-9);
clock_gettime(CLOCK_REALTIME, &tp);
double realTime = (double)tp.tv_sec + (double)((double)tp.tv_nsec * 1e-9);
return (realTime);
return (realTime);
}
/**
* Create a new timer object.
*
* Create a new timer object and reset the time to zero. The timer is initially not running and
* Create a new timer object and reset the time to zero. The timer is initially
* not running and
* must be started.
*/
Timer::Timer()
: m_startTime (0.0)
, m_accumulatedTime (0.0)
, m_running (false)
, m_semaphore (0)
{
//Creates a semaphore to control access to critical regions.
//Initially 'open'
m_semaphore = initializeMutexNormal();
Reset();
: m_startTime(0.0),
m_accumulatedTime(0.0),
m_running(false),
m_semaphore(0) {
// Creates a semaphore to control access to critical regions.
// Initially 'open'
m_semaphore = initializeMutexNormal();
Reset();
}
Timer::~Timer()
{
deleteMutex(m_semaphore);
}
Timer::~Timer() { deleteMutex(m_semaphore); }
/**
* Get the current time from the timer. If the clock is running it is derived from
* the current system clock the start time stored in the timer class. If the clock
* Get the current time from the timer. If the clock is running it is derived
* from
* the current system clock the start time stored in the timer class. If the
* clock
* is not running, then return the time when it was last stopped.
*
* @return Current time value for this timer in seconds
*/
double Timer::Get() const
{
double result;
double currentTime = GetFPGATimestamp();
double Timer::Get() const {
double result;
double currentTime = GetFPGATimestamp();
Synchronized sync(m_semaphore);
if(m_running)
{
// If the current time is before the start time, then the FPGA clock
// rolled over. Compensate by adding the ~71 minutes that it takes
// to roll over to the current time.
if(currentTime < m_startTime) {
currentTime += kRolloverTime;
}
Synchronized sync(m_semaphore);
if (m_running) {
// If the current time is before the start time, then the FPGA clock
// rolled over. Compensate by adding the ~71 minutes that it takes
// to roll over to the current time.
if (currentTime < m_startTime) {
currentTime += kRolloverTime;
}
result = (currentTime - m_startTime) + m_accumulatedTime;
}
else
{
result = m_accumulatedTime;
}
result = (currentTime - m_startTime) + m_accumulatedTime;
} else {
result = m_accumulatedTime;
}
return result;
return result;
}
/**
* Reset the timer by setting the time to 0.
*
* Make the timer startTime the current time so new requests will be relative to now
* Make the timer startTime the current time so new requests will be relative to
* now
*/
void Timer::Reset()
{
Synchronized sync(m_semaphore);
m_accumulatedTime = 0;
m_startTime = GetFPGATimestamp();
void Timer::Reset() {
Synchronized sync(m_semaphore);
m_accumulatedTime = 0;
m_startTime = GetFPGATimestamp();
}
/**
@@ -124,14 +119,12 @@ void Timer::Reset()
* Just set the running flag to true indicating that all time requests should be
* relative to the system clock.
*/
void Timer::Start()
{
Synchronized sync(m_semaphore);
if (!m_running)
{
m_startTime = GetFPGATimestamp();
m_running = true;
}
void Timer::Start() {
Synchronized sync(m_semaphore);
if (!m_running) {
m_startTime = GetFPGATimestamp();
m_running = true;
}
}
/**
@@ -140,16 +133,14 @@ void Timer::Start()
* subsequent time requests to be read from the accumulated time rather than
* looking at the system clock.
*/
void Timer::Stop()
{
double temp = Get();
void Timer::Stop() {
double temp = Get();
Synchronized sync(m_semaphore);
if (m_running)
{
m_accumulatedTime = temp;
m_running = false;
}
Synchronized sync(m_semaphore);
if (m_running) {
m_accumulatedTime = temp;
m_running = false;
}
}
/**
@@ -160,17 +151,15 @@ void Timer::Stop()
* @param period The period to check for (in seconds).
* @return True if the period has passed.
*/
bool Timer::HasPeriodPassed(double period)
{
if (Get() > period)
{
Synchronized sync(m_semaphore);
// Advance the start time by the period.
m_startTime += period;
// Don't set it to the current time... we want to avoid drift.
return true;
}
return false;
bool Timer::HasPeriodPassed(double period) {
if (Get() > period) {
Synchronized sync(m_semaphore);
// Advance the start time by the period.
m_startTime += period;
// Don't set it to the current time... we want to avoid drift.
return true;
}
return false;
}
/**
@@ -181,16 +170,14 @@ bool Timer::HasPeriodPassed(double period)
* Rolls over after 71 minutes.
* @returns Robot running time in seconds.
*/
double Timer::GetFPGATimestamp()
{
// FPGA returns the timestamp in microseconds
// Call the helper GetFPGATime() in Utility.cpp
return GetFPGATime() * 1.0e-6;
double Timer::GetFPGATimestamp() {
// FPGA returns the timestamp in microseconds
// Call the helper GetFPGATime() in Utility.cpp
return GetFPGATime() * 1.0e-6;
}
// Internal function that reads the PPC timestamp counter.
extern "C"
{
uint32_t niTimestamp32(void);
uint64_t niTimestamp64(void);
extern "C" {
uint32_t niTimestamp32(void);
uint64_t niTimestamp64(void);
}