Skip to content

Commit

Permalink
adding spi S7 class
Browse files Browse the repository at this point in the history
  • Loading branch information
mnr committed Nov 19, 2023
1 parent cf2ca6f commit a9ae0a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rpi_spi_open <- function(spiChan, spiBus = 0L, max_speed_hz = 32000000L) {
#' @return SPI identifier
#' @export
#'
rpi_spi_read <- function(spiDeviceID, speed, *buf, count) {
.Call(`_rpigpior_rpi_spi_read`, spiDeviceID, speed, *buf, count)
rpi_spi_read <- function(spiDeviceID) {
.Call(`_rpigpior_rpi_spi_read`, spiDeviceID)
}

19 changes: 19 additions & 0 deletions R/rpi_spi_class.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
spi <- new_class("spi", properties = list(
spiChan = class_integer,
spiBus = class_integer,
max_speed_hz = class_integer
),
validator = function(self) {
if (self@spiChan != 0 || self@spiChan != 1) {
"@spiChan must be zero or one"}
} else if (TRUE) {
"@spiBus must be something"}
)

method(open, spi) <- function(x) {}

method(write, spi) <- function(x) {}

method(read, spi) <- function(x) {}

method(close, spi) <- function(x) {}
11 changes: 4 additions & 7 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,21 @@ BEGIN_RCPP
END_RCPP
}
// rpi_spi_read
int rpi_spi_read(int spiDeviceID, unsigned speed, char *buf, unsigned count);
RcppExport SEXP _rpigpior_rpi_spi_read(SEXP spiDeviceIDSEXP, SEXP speedSEXP, SEXP *bufSEXP, SEXP countSEXP) {
int rpi_spi_read(int spiDeviceID);
RcppExport SEXP _rpigpior_rpi_spi_read(SEXP spiDeviceIDSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< int >::type spiDeviceID(spiDeviceIDSEXP);
Rcpp::traits::input_parameter< unsigned >::type speed(speedSEXP);
Rcpp::traits::input_parameter< char >::type *buf(*bufSEXP);
Rcpp::traits::input_parameter< unsigned >::type count(countSEXP);
rcpp_result_gen = Rcpp::wrap(rpi_spi_read(spiDeviceID, speed, *buf, count));
rcpp_result_gen = Rcpp::wrap(rpi_spi_read(spiDeviceID));
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_rpigpior_spiClose", (DL_FUNC) &_rpigpior_spiClose, 1},
{"_rpigpior_rpi_spi_open", (DL_FUNC) &_rpigpior_rpi_spi_open, 3},
{"_rpigpior_rpi_spi_read", (DL_FUNC) &_rpigpior_rpi_spi_read, 4},
{"_rpigpior_rpi_spi_read", (DL_FUNC) &_rpigpior_rpi_spi_read, 1},
{NULL, NULL, 0}
};

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-rpi_pwm.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ test_that("length(pin_number) > 3", {
skip_if_not(is.rpi())
expect_error(rpi_pwm(c(12,32,33), pwm_debug = TRUE))
})

test_that("real world test of pwm", {message("Testing PWM in real world")})

0 comments on commit a9ae0a9

Please sign in to comment.