From a9ae0a9306f9f14ecf5b3f4aa58bb34932182eb5 Mon Sep 17 00:00:00 2001 From: MNR Date: Sun, 19 Nov 2023 15:02:11 -0800 Subject: [PATCH] adding spi S7 class --- R/RcppExports.R | 4 ++-- R/rpi_spi_class.R | 19 +++++++++++++++++++ src/RcppExports.cpp | 11 ++++------- tests/testthat/test-rpi_pwm.R | 2 ++ 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 R/rpi_spi_class.R diff --git a/R/RcppExports.R b/R/RcppExports.R index 9b7619e..10f65f0 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -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) } diff --git a/R/rpi_spi_class.R b/R/rpi_spi_class.R new file mode 100644 index 0000000..73d943e --- /dev/null +++ b/R/rpi_spi_class.R @@ -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) {} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 4bc7b57..18b8b32 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -35,16 +35,13 @@ 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 } @@ -52,7 +49,7 @@ 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} }; diff --git a/tests/testthat/test-rpi_pwm.R b/tests/testthat/test-rpi_pwm.R index 26ec141..e5321fc 100644 --- a/tests/testthat/test-rpi_pwm.R +++ b/tests/testthat/test-rpi_pwm.R @@ -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")})