Skip to content

Commit

Permalink
add rpi_i2c_dump
Browse files Browse the repository at this point in the history
  • Loading branch information
mnr committed Dec 7, 2023
1 parent 042a654 commit 6d079aa
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(is.rpi)
export(rpi_get)
export(rpi_i2c_dump)
export(rpi_i2c_get)
export(rpi_i2c_set)
export(rpi_monitor)
Expand Down
32 changes: 32 additions & 0 deletions R/rpi_i2c_dump.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Read the entire data block from an I2C device
#'
#' This is a wrapper to i2cdump.
#'
#' @param chip_address an integer between 0x03 and 0x77
#'
#' @return the entire memory block from the I2C device
#' @export
#'
#' @examplesIf is.rpi()
#' rpi_i2c_dump(0x77)
#'
rpi_i2c_dump <- function(chip_address) {
# Assumes Serial Data Line (SDA, board pin 3)
# ...and Serial Clock Line (SCL, board pin 5)
# ...therefore i2cbus = 1
i2cbus <- 1

# chip-address must be an integer between 0x03 and 0x77
if (missing(chip_address) ||
chip_address < 0x03 ||
chip_address > 0x77
) {
stop("You must specify a chip_address as an integer between 0x08 and 0x77")
}

gpio_sysCall <- paste("i2cdump -y",
i2cbus,
chip_address)

return(as.integer(system(gpio_sysCall, intern = TRUE)))
}
22 changes: 22 additions & 0 deletions man/rpi_i2c_dump.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/testthat/test-rpi_i2c_dump.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})

0 comments on commit 6d079aa

Please sign in to comment.