wt5001: Added functions that throw exceptions when failing to read from sensors. Added java exception handling, and modified examples.

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Stefan Andritoiu
2015-11-18 14:50:22 +02:00
committed by Mihai Tudor Panu
parent 7f7fdb8441
commit fcb36276b7
6 changed files with 137 additions and 18 deletions

View File

@ -3,6 +3,7 @@
%include "stdint.i"
%include "typemaps.i"
%include "../java_buffer.i"
%include "../java_exceptions.i"
%apply uint8_t *OUTPUT { uint8_t *vol };
%apply uint8_t *OUTPUT { uint8_t *ps };
@ -17,5 +18,17 @@
speed_t int_B9600 = B9600;
%}
%ignore getVolume(uint8_t *vol);
READDATA_EXCEPTION(getVolume())
%ignore getPlayState(uint8_t *ps);
READDATA_EXCEPTION(getPlayState())
%ignore getNumFiles(WT5001_PLAYSOURCE_T psrc, uint16_t *numf);
READDATA_EXCEPTION(getNumFiles(WT5001_PLAYSOURCE_T psrc))
%ignore getCurrentFile(uint16_t *curf);
READDATA_EXCEPTION(getCurrentFile())
%include "wt5001.h"
speed_t int_B9600 = B9600;

View File

@ -450,6 +450,15 @@ bool WT5001::getVolume(uint8_t *vol)
return true;
}
uint8_t WT5001::getVolume()
{
uint8_t vol = 0;
if (!getVolume(&vol))
throw std::runtime_error(std::string(__PRETTY_FUNCTION__) +
": readData() failed");
return vol;
}
bool WT5001::getPlayState(uint8_t *ps)
{
char pkt[4];
@ -473,6 +482,15 @@ bool WT5001::getPlayState(uint8_t *ps)
return true;
}
uint8_t WT5001::getPlayState()
{
uint8_t ps = 0;
if (!getPlayState(&ps))
throw std::runtime_error(std::string(__PRETTY_FUNCTION__) +
": readData() failed");
return ps;
}
bool WT5001::getNumFiles(WT5001_PLAYSOURCE_T psrc, uint16_t *numf)
{
char pkt[4];
@ -515,6 +533,15 @@ bool WT5001::getNumFiles(WT5001_PLAYSOURCE_T psrc, uint16_t *numf)
return true;
}
uint16_t WT5001::getNumFiles(WT5001_PLAYSOURCE_T psrc)
{
uint16_t numf = 0;
if (!getNumFiles(psrc, &numf))
throw std::runtime_error(std::string(__PRETTY_FUNCTION__) +
": readData() failed");
return numf;
}
bool WT5001::getCurrentFile(uint16_t *curf)
{
char pkt[4];
@ -541,6 +568,15 @@ bool WT5001::getCurrentFile(uint16_t *curf)
return true;
}
uint16_t WT5001::getCurrentFile()
{
uint16_t curf = 0;
if (!getCurrentFile(&curf))
throw std::runtime_error(std::string(__PRETTY_FUNCTION__) +
": readData() failed");
return curf;
}
bool WT5001::getDate(uint16_t *year, uint8_t *month, uint8_t *day)
{
char pkt[4];

View File

@ -292,6 +292,14 @@ namespace upm {
*/
bool getVolume(uint8_t *vol);
/**
* Gets the current volume
*
* @return Volume
* @throws std::runtime_error if reading from the sensor failed
*/
uint8_t getVolume();
/**
* Gets the current play state: 1 = playing, 2 = stopped, 3 = paused
*
@ -300,6 +308,14 @@ namespace upm {
*/
bool getPlayState(uint8_t *ps);
/**
* Gets the current play state: 1 = playing, 2 = stopped, 3 = paused
*
* @return Play state
* @throws std::runtime_error if reading from the sensor failed
*/
uint8_t getPlayState();
/**
* Gets the number of files present on the source device
*
@ -309,6 +325,15 @@ namespace upm {
*/
bool getNumFiles(WT5001_PLAYSOURCE_T psrc, uint16_t *numf);
/**
* Gets the number of files present on the source device
*
* @param psrc Storage source
* @return Number of files
* @throws std::runtime_error if reading from the sensor failed
*/
uint16_t getNumFiles(WT5001_PLAYSOURCE_T psrc);
/**
* Gets the index of the current file
*
@ -317,6 +342,14 @@ namespace upm {
*/
bool getCurrentFile(uint16_t *curf);
/**
* Gets the index of the current file
*
* @return Index of the curretn file
* @throws std::runtime_error if reading from the sensor failed
*/
uint16_t getCurrentFile();
/**
* Gets the device date
*