add dip switch reading
This commit is contained in:
parent
ac85394396
commit
c800ee85b2
|
@ -10,5 +10,13 @@ int main() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t dip = read_dip_switch(instance, NULL, 0);
|
||||||
|
|
||||||
|
printf("DIP switch reads: ");
|
||||||
|
for(uint8_t mask = 1; mask != 0; mask <<= 1) {
|
||||||
|
printf("%d", (dip & mask) == mask ? 1 : 0);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef COMMIT_HASH_H
|
#ifndef COMMIT_HASH_H
|
||||||
#define COMMIT_HASH_H
|
#define COMMIT_HASH_H
|
||||||
const char COMMIT_HASH[] = "c9b75ce062eab34b7b19a69e8b3206abf4ddfa3a";
|
const char COMMIT_HASH[] = "ac85394396b3757b39c81e6010b1d0b76442f74c";
|
||||||
#endif // COMMIT_HASH_H
|
#endif // COMMIT_HASH_H
|
||||||
|
|
|
@ -1,14 +1,37 @@
|
||||||
#include "b15f.h"
|
#include "b15f.h"
|
||||||
#include "../drv/b15f.h"
|
#include "../drv/b15f.h"
|
||||||
|
|
||||||
|
#define wrap(x) reinterpret_cast<b15f_t>(x)
|
||||||
|
#define unwrap(x) reinterpret_cast<B15F&>(x)
|
||||||
|
|
||||||
|
#define default_catch catch(DriverException& e) {\
|
||||||
|
if (err) { \
|
||||||
|
strncpy(err, e.what(), len); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
b15f_t get_instance(char* err, size_t len) {
|
b15f_t get_instance(char* err, size_t len) {
|
||||||
try {
|
try {
|
||||||
return reinterpret_cast<b15f_t>(&B15F::getInstance());
|
return wrap(&B15F::getInstance());
|
||||||
} catch(DriverException& e) {
|
} default_catch;
|
||||||
if (err) {
|
|
||||||
strncpy(err, e.what(), len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int reconnect(b15f_t drv, char* err, size_t len) {
|
||||||
|
try {
|
||||||
|
unwrap(drv).reconnect();
|
||||||
|
return 0;
|
||||||
|
} default_catch;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t read_dip_switch(b15f_t drv, char* err, size_t len) {
|
||||||
|
try {
|
||||||
|
return unwrap(drv).readDipSwitch();
|
||||||
|
} default_catch;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
#define _B15F_H_
|
#define _B15F_H_
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -10,7 +11,7 @@ extern "C" {
|
||||||
typedef void* b15f_t;
|
typedef void* b15f_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an instance of the B15F driver
|
* @brief Returns an instance of the B15 driver
|
||||||
*
|
*
|
||||||
* @param err Buffer to write the exception message to (can be NULL)
|
* @param err Buffer to write the exception message to (can be NULL)
|
||||||
* @param len Length of the error buffer
|
* @param len Length of the error buffer
|
||||||
|
@ -18,6 +19,26 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
b15f_t get_instance(char* err, size_t len);
|
b15f_t get_instance(char* err, size_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tries to reconnect to the B15
|
||||||
|
*
|
||||||
|
* @param drv Instance of the B15 driver
|
||||||
|
* @param err Error buffer
|
||||||
|
* @param len Size of the error buffer
|
||||||
|
* @return int 0 on success
|
||||||
|
*/
|
||||||
|
int reconnect(b15f_t drv, char* err, size_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads the values of the DIP switch
|
||||||
|
*
|
||||||
|
* @param drv Instance of the B15 driver
|
||||||
|
* @param err Error buffer
|
||||||
|
* @param len Size of the error buffer
|
||||||
|
* @return uint8_t values of the DIP switch as a bitfield
|
||||||
|
*/
|
||||||
|
uint8_t read_dip_switch(b15f_t drv, char* err, size_t len);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue