Compare commits

...

No commits in common. 'a93586b168c35d1ad4357accc7a46efef8598fda' and 'ad65ac86293e8d41c5b9261842f0562bd57b81d2' have entirely different histories.

  1. 26
      .Rbuildignore
  2. 1
      .codecov.yml
  3. 1
      .github/FUNDING.yaml
  4. 26
      .github/workflows/R-CMD-check.yaml
  5. 9
      .gitignore
  6. 12
      .travis.yml
  7. 25
      CONDUCT.md
  8. 33
      DESCRIPTION
  9. 2
      LICENSE
  10. 21
      LICENSE.md
  11. 15
      NAMESPACE
  12. 2
      NEWS.md
  13. 1
      R/aaa.R
  14. 61
      R/core.R
  15. 19
      R/tcam-package.R
  16. 14
      R/utils-pipe.R
  17. 43
      R/utils.R
  18. 93
      README.Rmd
  19. 117
      README.md
  20. 52
      appveyor.yml
  21. 4
      inst/tinytest/test_tcam.R
  22. BIN
      man/figures/README-ex-02-1.png
  23. 14
      man/get_image.Rd
  24. 14
      man/get_status.Rd
  25. 20
      man/pipe.Rd
  26. 26
      man/tcam.Rd
  27. 14
      man/tcam_connect.Rd
  28. 18
      man/tidy_radiometric.Rd
  29. 21
      tcam.Rproj
  30. 5
      tests/tinytest.R

26
.Rbuildignore

@ -0,0 +1,26 @@
^.vscode$
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
^README\.*Rmd$
^README\.*html$
^NOTES\.*Rmd$
^NOTES\.*html$
^\.codecov\.yml$
^README_files$
^doc$
^docs$
^tmp$
^notes$
^CONDUCT.*$
^CODE.*$
^\.gitlab-ci\.yml$
^\.vscode$
^CRAN-RELEASE$
^appveyor\.yml$
^tools$
^LICENSE\.md$
^bld$
^node_modules^
^package-lock\.json$
^\.github$

1
.codecov.yml

@ -0,0 +1 @@
comment: false

1
.github/FUNDING.yaml

@ -0,0 +1 @@
github: hrbrmstr

26
.github/workflows/R-CMD-check.yaml

@ -0,0 +1,26 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
push:
branches:
- batman
pull_request:
branches:
- batman
name: R-CMD-check
jobs:
R-CMD-check:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@master
- name: Install dependencies
run: |
install.packages(c("remotes", "rcmdcheck"))
remotes::install_deps(dependencies = TRUE)
shell: Rscript {0}
- name: Check
run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error")
shell: Rscript {0}

9
.gitignore

@ -0,0 +1,9 @@
.DS_Store
.Rproj.user
.Rhistory
.RData
.Rproj
README_cache
src/*.o
src/*.so
src/*.dll

12
.travis.yml

@ -0,0 +1,12 @@
language: R
sudo: false
cache: packages
before_install:
- echo "options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/__linux__/xenial/latest'))" >> ~/.Rprofile.site
- echo "options(HTTPUserAgent = paste0('R/', getRversion(), ' R (',
paste(getRversion(), R.version['platform'], R.version['arch'], R.version['os']),
')'))" >> ~/.Rprofile.site
after_success:
- Rscript -e 'covr::codecov()'

25
CONDUCT.md

@ -0,0 +1,25 @@
# Contributor Code of Conduct
As contributors and maintainers of this project, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.
We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression,
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
Examples of unacceptable behavior by participants include the use of sexual language or
imagery, derogatory comments or personal attacks, trolling, public or private harassment,
insults, or other unprofessional conduct.
Project maintainers have the right and responsibility to remove, edit, or reject comments,
commits, code, wiki edits, issues, and other contributions that are not aligned to this
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
from the project team.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
opening an issue or contacting one or more of the project maintainers.
This Code of Conduct is adapted from the Contributor Covenant
(http:contributor-covenant.org), version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/

33
DESCRIPTION

@ -0,0 +1,33 @@
Package: tcam
Type: Package
Title: Retrieve Radiometric Image Data from and Configure and Control tCam and
tCam-Mini Thermal Imaging Systems
Version: 0.1.0
Date: 2021-08-19
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640"))
)
Maintainer: Bob Rudis <bob@rud.is>
Description: The tCam and tCam-Mini (<https://github.com/danjulio/lepton/tree/master/ESP32>)
are two cameras designed around the ESP32 chipset and provide easy access to
radiometric data from Lepton 3.5 sensors. Tools are provided to configure, control,
and receive radiometric data from tCam systems.
URL: https://git.rud.is/hrbrmstr/tcam
BugReports: https://git.rud.is/hrbrmstr/tcam/issues
Encoding: UTF-8
License: MIT + file LICENSE
Suggests:
covr, tinytest
Depends:
R (>= 3.6.0)
Imports:
RcppSimdJson,
openssl,
tidyr,
dplyr,
magrittr,
stringi,
utils
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1

2
LICENSE

@ -0,0 +1,2 @@
YEAR: 2021
COPYRIGHT HOLDER: tcam authors

21
LICENSE.md

@ -0,0 +1,21 @@
# MIT License
Copyright (c) 2021 tcam authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

15
NAMESPACE

@ -0,0 +1,15 @@
# Generated by roxygen2: do not edit by hand
export("%>%")
export(get_image)
export(get_status)
export(tcam_connect)
export(tidy_radiometric)
importFrom(RcppSimdJson,fparse)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_at)
importFrom(magrittr,"%>%")
importFrom(openssl,base64_decode)
importFrom(stringi,stri_replace_all_regex)
importFrom(tidyr,gather)
importFrom(utils,hasName)

2
NEWS.md

@ -0,0 +1,2 @@
0.1.0
* Initial release

1
R/aaa.R

@ -0,0 +1 @@
utils::globalVariables(c("."))

61
R/core.R

@ -0,0 +1,61 @@
#' Make a socket connection to a tCam device
#'
#' @param host,port IP/hostname + port; defaults to the device defaults
#' @export
tcam_connect <- function(host = "192.168.4.1", port = 5001) {
socketConnection(
host = host,
port = port,
open = "a+b"
)
}
#' Returns a packet with camera status.
#'
#' @param con open socket connection from [tcam_connect()]
#' @export
get_status <- function(con) {
writeBin(
object = c(as.raw(0x02), charToRaw('{"cmd":"get_status"}'), as.raw(0x03)),
con = con,
useBytes = TRUE
) -> res
Sys.sleep(0.5)
readChar(
con = con,
nchars = 2048L,
useBytes = TRUE
) %>%
stri_replace_all_regex("\002|\003", "") %>%
fparse()
}
#' Returns a packet with metadata, radiometric (or AGC) image data and Lepton telemetry objects.
#'
#' @param con open socket connection from [tcam_connect()]
#' @export
get_image <- function(con) {
tmp <- get_status(con)
writeBin(
object = c(as.raw(0x02), charToRaw('{"cmd":"get_image"}'), as.raw(0x03)),
con = con,
useBytes = TRUE
) -> res
Sys.sleep(0.5)
readChar(
con = con,
nchars = 65536L,
useBytes = TRUE
) %>%
stri_replace_all_regex("\002|\003", "") %>%
fparse()
}

19
R/tcam-package.R

@ -0,0 +1,19 @@
#' Retrieve Radiometric Image Data from and Configure and Control tCam and tCam-Mini
#' Thermal Imaging Systems
#'
#' The tCam and tCam-Mini (<https://github.com/danjulio/lepton/tree/master/ESP32>)
#' are two cameras designed around the ESP32 chipset and provide easy access to
#' radiometric data from Lepton 3.5 sensors. Tools are provided to configure, control,
#' and receive radiometric data from tCam systems.
#'
#' @md
#' @name tcam
#' @keywords internal
#' @author Bob Rudis (bob@@rud.is)
#' @importFrom RcppSimdJson fparse
#' @importFrom openssl base64_decode
#' @importFrom tidyr gather
#' @importFrom dplyr mutate mutate_at
#' @importFrom stringi stri_replace_all_regex
#' @importFrom utils hasName
"_PACKAGE"

14
R/utils-pipe.R

@ -0,0 +1,14 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
#' @param lhs A value or the magrittr placeholder.
#' @param rhs A function call using the magrittr semantics.
#' @return The result of calling `rhs(lhs)`.
NULL

43
R/utils.R

@ -0,0 +1,43 @@
#' Return a tidy data frame of Lepton radiometric data retrieved with [get_image()]
#'
#' Converts the base64 16-bit coded Kelvin radiometric data to a tidy "XYZ"
#' data frame in Fahrenheit.
#'
#' @param img_data data structure retrieved with [get_image()]
#' @returns data frame of `x`, `y`, and `value`
#' @export
tidy_radiometric <- function(img_data) {
if (!hasName(img_data, "radiometric")) {
stop("Data structure does not seem to be tCam radiometric image data.", call.=FALSE)
}
openssl::base64_decode(img_data$radiometric) %>%
readBin(
what = "integer",
n = 19200,
size = 2
) %>%
matrix(
nrow = 120,
ncol = 160,
byrow = TRUE,
dimnames = list(120:1)
) -> m
as.data.frame(m) %>%
mutate(y = rownames(m)) %>%
gather(x, value, -y) %>%
mutate_at(
vars(x),
~sub("V", "", .)
) %>%
mutate(
x = as.integer(x),
y = as.integer(y),
value = ((value / 100) * 1.8) - 459.67 # convert to degrees F b/c I'm a brutish Murican
) -> xdf
xdf[,c("x", "y", "value")]
}

93
README.Rmd

@ -0,0 +1,93 @@
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```
```{r badges, results='asis', echo=FALSE, cache=FALSE, eval=FALSE}
hrbrpkghelpr::stinking_badges()
```
```{r description, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::yank_title_and_description()
```
## What's Inside The Tin
The following functions are implemented:
```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::describe_ingredients()
```
## Installation
```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::install_block()
```
## Usage
```{r lib-ex}
library(tcam)
library(ggplot2) # for plotting
# current version
packageVersion("tcam")
```
Open a connection and get the status of the tCam:
```{r ex-01}
con <- tcam_connect()
get_status(con)
```
Take a picture and plot it:
```{r ex-02, cache=TRUE}
img <- get_image(con)
ggplot(tidy_radiometric(img)) +
geom_tile(
aes(x, y, fill = value),
color = NA
) +
scale_fill_viridis_c(
name = "°F",
option = "magma"
) +
coord_fixed() +
labs(
x = NULL, y = NULL
) +
theme_minimal() +
theme(
axis.text.x.bottom = element_blank(),
axis.text.y.left = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
```
Done, so we close the connection.
```{r ex-99}
close(con)
```
## tcam Metrics
```{r cloc, echo=FALSE}
cloc::cloc_pkg_md()
```
## Code of Conduct
Please note that this project is released with a Contributor Code of Conduct.
By participating in this project you agree to abide by its terms.

117
README.md

@ -1,2 +1,119 @@
# tcam
Retrieve Radiometric Image Data from and Configure and Control tCam and
tCam-Mini Thermal Imaging Systems
## Description
The tCam and tCam-Mini
(<https://github.com/danjulio/lepton/tree/master/ESP32>) are two cameras
designed around the ESP32 chipset and provide easy access to radiometric
data from Lepton 3.5 sensors. Tools are provided to configure, control,
and receive radiometric data from tCam systems.
## What’s Inside The Tin
The following functions are implemented:
- `get_image`: Returns a packet with metadata, radiometric (or AGC)
image data and Lepton telemetry objects.
- `get_status`: Returns a packet with camera status.
- `tcam_connect`: Make a socket connection to a tCam device
- `tidy_radiometric`: Return a tidy data frame of Lepton radiometric
data retrieved with get_image()
## Installation
``` r
remotes::install_git("https://git.rud.is/hrbrmstr/tcam.git")
```
NOTE: To use the ‘remotes’ install options you will need to have the
[{remotes} package](https://github.com/r-lib/remotes) installed.
## Usage
``` r
library(tcam)
library(ggplot2) # for plotting
# current version
packageVersion("tcam")
## [1] '0.1.0'
```
Open a connection and get the status of the tCam:
``` r
con <- tcam_connect()
get_status(con)
## $status
## $status$Camera
## [1] "tCam-Mini-B3CD"
##
## $status$Model
## [1] 2
##
## $status$Version
## [1] "1.3"
##
## $status$Time
## [1] "2:02:48.364"
##
## $status$Date
## [1] "1/1/-30"
```
Take a picture and plot it:
``` r
img <- get_image(con)
ggplot(tidy_radiometric(img)) +
geom_tile(
aes(x, y, fill = value),
color = NA
) +
scale_fill_viridis_c(
name = "°F",
option = "magma"
) +
coord_fixed() +
labs(
x = NULL, y = NULL
) +
theme_minimal() +
theme(
axis.text.x.bottom = element_blank(),
axis.text.y.left = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
```
<img src="man/figures/README-ex-02-1.png" width="672" />
Done, so we close the connection.
``` r
close(con)
```
## tcam Metrics
| Lang | # Files | (%) | LoC | (%) | Blank lines | (%) | # Lines | (%) |
|:-----|--------:|-----:|----:|-----:|------------:|-----:|--------:|-----:|
| R | 6 | 0.33 | 74 | 0.28 | 18 | 0.21 | 51 | 0.28 |
| Rmd | 1 | 0.06 | 33 | 0.13 | 23 | 0.27 | 37 | 0.21 |
| YAML | 2 | 0.11 | 23 | 0.09 | 2 | 0.02 | 2 | 0.01 |
| SUM | 9 | 0.50 | 130 | 0.50 | 43 | 0.50 | 90 | 0.50 |
clock Package Metrics for tcam
## Code of Conduct
Please note that this project is released with a Contributor Code of
Conduct. By participating in this project you agree to abide by its
terms.

52
appveyor.yml

@ -0,0 +1,52 @@
# DO NOT CHANGE the "init" and "install" sections below
# Download script file from GitHub
init:
ps: |
= "Stop"
Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1"
Import-Module '..\appveyor-tool.ps1'
install:
ps: Bootstrap
cache:
- C:\RLibrary
environment:
NOT_CRAN: true
# env vars that may need to be set, at least temporarily, from time to time
# see https://github.com/krlmlr/r-appveyor#readme for details
# USE_RTOOLS: true
# R_REMOTES_STANDALONE: true
# Adapt as necessary starting from here
build_script:
- travis-tool.sh install_deps
test_script:
- travis-tool.sh run_tests
on_failure:
- 7z a failure.zip *.Rcheck\*
- appveyor PushArtifact failure.zip
artifacts:
- path: '*.Rcheck\**\*.log'
name: Logs
- path: '*.Rcheck\**\*.out'
name: Logs
- path: '*.Rcheck\**\*.fail'
name: Logs
- path: '*.Rcheck\**\*.Rout'
name: Logs
- path: '\*_*.tar.gz'
name: Bits
- path: '\*_*.zip'
name: Bits

4
inst/tinytest/test_tcam.R

@ -0,0 +1,4 @@
# Placeholder with simple test
expect_equal(1 + 1, 2)

BIN
man/figures/README-ex-02-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

14
man/get_image.Rd

@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/core.R
\name{get_image}
\alias{get_image}
\title{Returns a packet with metadata, radiometric (or AGC) image data and Lepton telemetry objects.}
\usage{
get_image(con)
}
\arguments{
\item{con}{open socket connection from \code{\link[=tcam_connect]{tcam_connect()}}}
}
\description{
Returns a packet with metadata, radiometric (or AGC) image data and Lepton telemetry objects.
}

14
man/get_status.Rd

@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/core.R
\name{get_status}
\alias{get_status}
\title{Returns a packet with camera status.}
\usage{
get_status(con)
}
\arguments{
\item{con}{open socket connection from \code{\link[=tcam_connect]{tcam_connect()}}}
}
\description{
Returns a packet with camera status.
}

20
man/pipe.Rd

@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-pipe.R
\name{\%>\%}
\alias{\%>\%}
\title{Pipe operator}
\usage{
lhs \%>\% rhs
}
\arguments{
\item{lhs}{A value or the magrittr placeholder.}
\item{rhs}{A function call using the magrittr semantics.}
}
\value{
The result of calling \code{rhs(lhs)}.
}
\description{
See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
}
\keyword{internal}

26
man/tcam.Rd

@ -0,0 +1,26 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tcam-package.R
\docType{package}
\name{tcam}
\alias{tcam}
\alias{tcam-package}
\title{Retrieve Radiometric Image Data from and Configure and Control tCam and tCam-Mini
Thermal Imaging Systems}
\description{
The tCam and tCam-Mini (\url{https://github.com/danjulio/lepton/tree/master/ESP32})
are two cameras designed around the ESP32 chipset and provide easy access to
radiometric data from Lepton 3.5 sensors. Tools are provided to configure, control,
and receive radiometric data from tCam systems.
}
\seealso{
Useful links:
\itemize{
\item \url{https://git.rud.is/hrbrmstr/tcam}
\item Report bugs at \url{https://git.rud.is/hrbrmstr/tcam/issues}
}
}
\author{
Bob Rudis (bob@rud.is)
}
\keyword{internal}

14
man/tcam_connect.Rd

@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/core.R
\name{tcam_connect}
\alias{tcam_connect}
\title{Make a socket connection to a tCam device}
\usage{
tcam_connect(host = "192.168.4.1", port = 5001)
}
\arguments{
\item{host, port}{IP/hostname + port; defaults to the device defaults}
}
\description{
Make a socket connection to a tCam device
}

18
man/tidy_radiometric.Rd

@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{tidy_radiometric}
\alias{tidy_radiometric}
\title{Return a tidy data frame of Lepton radiometric data retrieved with \code{\link[=get_image]{get_image()}}}
\usage{
tidy_radiometric(img_data)
}
\arguments{
\item{img_data}{data structure retrieved with \code{\link[=get_image]{get_image()}}}
}
\value{
data frame of \code{x}, \code{y}, and \code{value}
}
\description{
Converts the base64 16-bit coded Kelvin radiometric data to a tidy "XYZ"
data frame in Fahrenheit.
}

21
tcam.Rproj

@ -0,0 +1,21 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --resave-data
PackageRoxygenize: rd,collate,namespace

5
tests/tinytest.R

@ -0,0 +1,5 @@
if ( requireNamespace("tinytest", quietly=TRUE) ){
tinytest::test_package("tcam")
}
Loading…
Cancel
Save