clang-format: run clang-format on C/C++ code
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -26,7 +26,8 @@
|
||||
//! [Interesting]
|
||||
#include "mraa/aio.h"
|
||||
|
||||
int main ()
|
||||
int
|
||||
main()
|
||||
{
|
||||
mraa_aio_context adc_a0;
|
||||
uint16_t adc_value = 0;
|
||||
@@ -37,7 +38,7 @@ int main ()
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
adc_value = mraa_aio_read(adc_a0);
|
||||
adc_value_float = mraa_aio_read_float(adc_a0);
|
||||
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);
|
||||
|
||||
@@ -45,7 +45,7 @@ sig_handler(int signo)
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_result_t r = MRAA_SUCCESS;
|
||||
iopin = DEFAULT_IOPIN;
|
||||
@@ -57,14 +57,13 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
mraa_init();
|
||||
fprintf(stdout, "MRAA Version: %s\nStarting Blinking on IO%d\n",
|
||||
mraa_get_version(), iopin);
|
||||
fprintf(stdout, "MRAA Version: %s\nStarting Blinking on IO%d\n", mraa_get_version(), iopin);
|
||||
|
||||
mraa_gpio_context gpio;
|
||||
gpio = mraa_gpio_init(iopin);
|
||||
if (gpio == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", iopin);
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
printf("Initialised pin%d\n", iopin);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "mraa/gpio.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_platform_t platform = mraa_get_platform_type();
|
||||
mraa_gpio_context gpio, gpio_in = NULL;
|
||||
@@ -40,18 +40,17 @@ main(int argc, char **argv)
|
||||
case MRAA_INTEL_GALILEO_GEN1:
|
||||
gpio = mraa_gpio_init_raw(3);
|
||||
break;
|
||||
case MRAA_INTEL_MINNOWBOARD_MAX:
|
||||
// there is no onboard LED that we can flash on the minnowboard max
|
||||
// but on the calamari lure pin 21 is an LED. If you don't have the
|
||||
// lure put an LED on pin 21
|
||||
gpio = mraa_gpio_init(21);
|
||||
case MRAA_INTEL_MINNOWBOARD_MAX:
|
||||
// there is no onboard LED that we can flash on the minnowboard max
|
||||
// but on the calamari lure pin 21 is an LED. If you don't have the
|
||||
// lure put an LED on pin 21
|
||||
gpio = mraa_gpio_init(21);
|
||||
break;
|
||||
default:
|
||||
gpio = mraa_gpio_init(13);
|
||||
}
|
||||
|
||||
fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n",
|
||||
mraa_get_version(), board_name);
|
||||
fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);
|
||||
|
||||
|
||||
if (gpio == NULL) {
|
||||
@@ -62,7 +61,7 @@ main(int argc, char **argv)
|
||||
// on platforms with physical button use gpio_in
|
||||
if (platform == MRAA_INTEL_MINNOWBOARD_MAX) {
|
||||
gpio_in = mraa_gpio_init(14);
|
||||
if (gpio_in != NULL) {
|
||||
if (gpio_in != NULL) {
|
||||
mraa_gpio_dir(gpio_in, MRAA_GPIO_IN);
|
||||
// S1 on minnowboardmax's calamari lure maps to pin 14, SW1 != S1
|
||||
fprintf(stdout, "Press and hold S1 to stop, Press SW1 to shutdown!\n");
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
//! [Interesting]
|
||||
#include "mraa.hpp"
|
||||
|
||||
int main ()
|
||||
int
|
||||
main()
|
||||
{
|
||||
uint16_t adc_value;
|
||||
float adc_value_float;
|
||||
@@ -36,7 +37,7 @@ int main ()
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
adc_value = a0->read();
|
||||
adc_value_float = a0->readFloat();
|
||||
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);
|
||||
|
||||
@@ -43,7 +43,8 @@ sig_handler(int signo)
|
||||
running = -1;
|
||||
}
|
||||
}
|
||||
int main (int argc, char **argv)
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("Provide an int arg if you want to flash on something other than %d\n", DEFAULT_IOPIN);
|
||||
@@ -54,7 +55,7 @@ int main (int argc, char **argv)
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
mraa::Gpio* gpio = new mraa::Gpio(iopin);
|
||||
if (gpio == NULL) {
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
@@ -73,5 +74,5 @@ int main (int argc, char **argv)
|
||||
}
|
||||
delete gpio;
|
||||
return response;
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
#define MAX_BUFFER_LENGTH 6
|
||||
#define HMC5883L_I2C_ADDR 0x1E
|
||||
|
||||
//configuration registers
|
||||
// configuration registers
|
||||
#define HMC5883L_CONF_REG_A 0x00
|
||||
#define HMC5883L_CONF_REG_B 0x01
|
||||
|
||||
//mode register
|
||||
// mode register
|
||||
#define HMC5883L_MODE_REG 0x02
|
||||
|
||||
//data register
|
||||
// data register
|
||||
#define HMC5883L_X_MSB_REG 0
|
||||
#define HMC5883L_X_LSB_REG 1
|
||||
#define HMC5883L_Z_MSB_REG 2
|
||||
@@ -48,10 +48,10 @@
|
||||
#define HMC5883L_Y_LSB_REG 5
|
||||
#define DATA_REG_SIZE 6
|
||||
|
||||
//status register
|
||||
// status register
|
||||
#define HMC5883L_STATUS_REG 0x09
|
||||
|
||||
//ID registers
|
||||
// ID registers
|
||||
#define HMC5883L_ID_A_REG 0x0A
|
||||
#define HMC5883L_ID_B_REG 0x0B
|
||||
#define HMC5883L_ID_C_REG 0x0C
|
||||
@@ -59,7 +59,7 @@
|
||||
#define HMC5883L_CONT_MODE 0x00
|
||||
#define HMC5883L_DATA_REG 0x03
|
||||
|
||||
//scales
|
||||
// scales
|
||||
#define GA_0_88_REG 0x00 << 5
|
||||
#define GA_1_3_REG 0x01 << 5
|
||||
#define GA_1_9_REG 0x02 << 5
|
||||
@@ -69,7 +69,7 @@
|
||||
#define GA_5_6_REG 0x06 << 5
|
||||
#define GA_8_1_REG 0x07 << 5
|
||||
|
||||
//digital resolutions
|
||||
// digital resolutions
|
||||
#define SCALE_0_73_MG 0.73
|
||||
#define SCALE_0_92_MG 0.92
|
||||
#define SCALE_1_22_MG 1.22
|
||||
@@ -91,13 +91,14 @@ sig_handler(int signo)
|
||||
}
|
||||
}
|
||||
|
||||
int main ()
|
||||
int
|
||||
main()
|
||||
{
|
||||
float direction = 0;
|
||||
int16_t x = 0, y = 0, z = 0;
|
||||
uint8_t rx_tx_buf[MAX_BUFFER_LENGTH];
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
mraa::I2c* i2c;
|
||||
i2c = new mraa::I2c(0);
|
||||
|
||||
@@ -105,7 +106,7 @@ int main ()
|
||||
rx_tx_buf[0] = HMC5883L_CONF_REG_B;
|
||||
rx_tx_buf[1] = GA_1_3_REG;
|
||||
i2c->write(rx_tx_buf, 2);
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
i2c->address(HMC5883L_I2C_ADDR);
|
||||
rx_tx_buf[0] = HMC5883L_MODE_REG;
|
||||
@@ -121,19 +122,20 @@ int main ()
|
||||
i2c->address(HMC5883L_I2C_ADDR);
|
||||
i2c->read(rx_tx_buf, DATA_REG_SIZE);
|
||||
|
||||
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_X_LSB_REG] ;
|
||||
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Z_LSB_REG] ;
|
||||
y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Y_LSB_REG] ;
|
||||
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8) | rx_tx_buf[HMC5883L_X_LSB_REG];
|
||||
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Z_LSB_REG];
|
||||
y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Y_LSB_REG];
|
||||
|
||||
//scale and calculate direction
|
||||
// scale and calculate direction
|
||||
direction = atan2(y * SCALE_0_92_MG, x * SCALE_0_92_MG);
|
||||
|
||||
//check if the signs are reversed
|
||||
// check if the signs are reversed
|
||||
if (direction < 0)
|
||||
direction += 2 * M_PI;
|
||||
|
||||
printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG, z * SCALE_0_92_MG) ;
|
||||
printf("Heading : %f\n", direction * 180/M_PI);
|
||||
printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG,
|
||||
z * SCALE_0_92_MG);
|
||||
printf("Heading : %f\n", direction * 180 / M_PI);
|
||||
sleep(1);
|
||||
}
|
||||
delete i2c;
|
||||
|
||||
@@ -38,10 +38,11 @@ sig_handler(int signo)
|
||||
}
|
||||
}
|
||||
|
||||
int main ()
|
||||
int
|
||||
main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
mraa::Pwm* pwm;
|
||||
|
||||
pwm = new mraa::Pwm(3);
|
||||
@@ -61,7 +62,7 @@ int main ()
|
||||
}
|
||||
}
|
||||
delete pwm;
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -39,26 +39,27 @@ sig_handler(int signo)
|
||||
}
|
||||
}
|
||||
|
||||
int main ()
|
||||
int
|
||||
main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
mraa::Spi* spi;
|
||||
|
||||
spi = new mraa::Spi(0);
|
||||
|
||||
uint8_t data[] = {0x00, 100};
|
||||
uint8_t data[] = { 0x00, 100 };
|
||||
uint8_t rxBuf[2];
|
||||
uint8_t *recv;
|
||||
uint8_t* recv;
|
||||
while (running == 0) {
|
||||
int i;
|
||||
for (i = 90; i < 130; i++) {
|
||||
data[1] = i;
|
||||
recv = spi->write(data, 2);
|
||||
printf("Writing -%i",i);
|
||||
printf("Writing -%i", i);
|
||||
if (recv) {
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
printf("RECIVED-%i-%i\n", recv[0], recv[1]);
|
||||
free(recv);
|
||||
}
|
||||
usleep(100000);
|
||||
@@ -66,15 +67,14 @@ int main ()
|
||||
for (i = 130; i > 90; i--) {
|
||||
data[1] = i;
|
||||
if (spi->transfer(data, rxBuf, 2) == MRAA_SUCCESS) {
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",rxBuf[0],rxBuf[1]);
|
||||
printf("Writing -%i", i);
|
||||
printf("RECIVED-%i-%i\n", rxBuf[0], rxBuf[1]);
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
}
|
||||
delete spi;
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
#include "mraa.h"
|
||||
|
||||
int
|
||||
main ()
|
||||
main()
|
||||
{
|
||||
mraa_init();
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
mraa_pwm_context pwm;
|
||||
pwm = mraa_pwm_init(3);
|
||||
if (pwm == NULL) {
|
||||
@@ -50,6 +50,6 @@ main ()
|
||||
}
|
||||
float output = mraa_pwm_read(pwm);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -29,17 +29,19 @@
|
||||
#include "mraa/gpio.h"
|
||||
|
||||
struct gpio_source {
|
||||
int pin;
|
||||
mraa_gpio_context context;
|
||||
int pin;
|
||||
mraa_gpio_context context;
|
||||
};
|
||||
|
||||
void
|
||||
print_version() {
|
||||
print_version()
|
||||
{
|
||||
fprintf(stdout, "Version %s on %s\n", mraa_get_version(), mraa_get_platform_name());
|
||||
}
|
||||
|
||||
void
|
||||
print_help() {
|
||||
print_help()
|
||||
{
|
||||
fprintf(stdout, "list List pins\n");
|
||||
fprintf(stdout, "set pin level Set pin to level (0/1)\n");
|
||||
fprintf(stdout, "setraw pin level Set pin to level (0/1) via mmap (if available)\n");
|
||||
@@ -50,13 +52,15 @@ print_help() {
|
||||
}
|
||||
|
||||
void
|
||||
print_command_error() {
|
||||
print_command_error()
|
||||
{
|
||||
fprintf(stdout, "Invalid command, options are:\n");
|
||||
print_help();
|
||||
}
|
||||
|
||||
void
|
||||
list_pins() {
|
||||
list_pins()
|
||||
{
|
||||
int pin_count = mraa_get_pin_count();
|
||||
if (pin_count == 0) {
|
||||
fprintf(stdout, "No Pins\n");
|
||||
@@ -64,7 +68,7 @@ list_pins() {
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < pin_count; ++i) {
|
||||
if (strcmp(mraa_get_pin_name(i),"INVALID") != 0) {
|
||||
if (strcmp(mraa_get_pin_name(i), "INVALID") != 0) {
|
||||
fprintf(stdout, "%02d ", i);
|
||||
fprintf(stdout, "%8s: ", mraa_get_pin_name(i));
|
||||
if (mraa_pin_mode_test(i, MRAA_PIN_GPIO))
|
||||
@@ -85,13 +89,15 @@ list_pins() {
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
gpio_set(int pin, int level, mraa_boolean_t raw) {
|
||||
gpio_set(int pin, int level, mraa_boolean_t raw)
|
||||
{
|
||||
mraa_gpio_context gpio = mraa_gpio_init(pin);
|
||||
if (gpio != NULL) {
|
||||
mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
|
||||
if (raw != 0) {
|
||||
if (mraa_gpio_use_mmaped(gpio, 1) != MRAA_SUCCESS) {
|
||||
fprintf(stdout, "mmapped access to gpio not supported, falling back to normal mode\n", pin);
|
||||
fprintf(stdout,
|
||||
"mmapped access to gpio not supported, falling back to normal mode\n", pin);
|
||||
}
|
||||
}
|
||||
mraa_gpio_write(gpio, level);
|
||||
@@ -101,13 +107,15 @@ gpio_set(int pin, int level, mraa_boolean_t raw) {
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
gpio_get(int pin, int *level, mraa_boolean_t raw) {
|
||||
gpio_get(int pin, int* level, mraa_boolean_t raw)
|
||||
{
|
||||
mraa_gpio_context gpio = mraa_gpio_init(pin);
|
||||
if (gpio != NULL) {
|
||||
mraa_gpio_dir(gpio, MRAA_GPIO_IN);
|
||||
if (raw != 0) {
|
||||
if (mraa_gpio_use_mmaped(gpio, 1) != MRAA_SUCCESS) {
|
||||
fprintf(stdout, "mmapped access to gpio not supported, falling back to normal mode\n", pin);
|
||||
fprintf(stdout,
|
||||
"mmapped access to gpio not supported, falling back to normal mode\n", pin);
|
||||
}
|
||||
}
|
||||
*level = mraa_gpio_read(gpio);
|
||||
@@ -117,14 +125,17 @@ gpio_get(int pin, int *level, mraa_boolean_t raw) {
|
||||
}
|
||||
|
||||
|
||||
void gpio_isr_handler(void * args) {
|
||||
struct gpio_source* gpio_info = (struct gpio_source*)args;
|
||||
int level = mraa_gpio_read(gpio_info->context);
|
||||
fprintf(stdout, "Pin %d = %d\n", gpio_info->pin, level);
|
||||
void
|
||||
gpio_isr_handler(void* args)
|
||||
{
|
||||
struct gpio_source* gpio_info = (struct gpio_source*) args;
|
||||
int level = mraa_gpio_read(gpio_info->context);
|
||||
fprintf(stdout, "Pin %d = %d\n", gpio_info->pin, level);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
gpio_isr_start(struct gpio_source* gpio_info) {
|
||||
gpio_isr_start(struct gpio_source* gpio_info)
|
||||
{
|
||||
gpio_info->context = mraa_gpio_init(gpio_info->pin);
|
||||
if (gpio_info->context != NULL) {
|
||||
mraa_result_t status = mraa_gpio_dir(gpio_info->context, MRAA_GPIO_IN);
|
||||
@@ -139,7 +150,8 @@ gpio_isr_start(struct gpio_source* gpio_info) {
|
||||
|
||||
|
||||
mraa_result_t
|
||||
gpio_isr_stop(struct gpio_source* gpio_info) {
|
||||
gpio_isr_stop(struct gpio_source* gpio_info)
|
||||
{
|
||||
mraa_gpio_isr_exit(gpio_info->context);
|
||||
mraa_gpio_close(gpio_info->context);
|
||||
return MRAA_SUCCESS;
|
||||
@@ -147,7 +159,7 @@ gpio_isr_stop(struct gpio_source* gpio_info) {
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
print_command_error();
|
||||
@@ -176,14 +188,13 @@ main(int argc, char **argv)
|
||||
mraa_boolean_t rawmode = strcmp(argv[1], "getraw") == 0;
|
||||
if (gpio_get(pin, &level, rawmode) == MRAA_SUCCESS) {
|
||||
fprintf(stdout, "Pin %d = %d\n", pin, level);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fprintf(stdout, "Could not initialize gpio %d\n", pin);
|
||||
}
|
||||
} else {
|
||||
print_command_error();
|
||||
}
|
||||
} else if (strcmp(argv[1], "monitor") == 0) {
|
||||
} else if (strcmp(argv[1], "monitor") == 0) {
|
||||
if (argc == 3) {
|
||||
int pin = atoi(argv[2]);
|
||||
struct gpio_source gpio_info;
|
||||
@@ -191,18 +202,18 @@ main(int argc, char **argv)
|
||||
if (gpio_isr_start(&gpio_info) == MRAA_SUCCESS) {
|
||||
fprintf(stdout, "Monitoring level changes to pin %d. Press RETURN to exit.\n", pin);
|
||||
gpio_isr_handler(&gpio_info);
|
||||
while (getchar() != '\n');
|
||||
while (getchar() != '\n')
|
||||
;
|
||||
gpio_isr_stop(&gpio_info);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fprintf(stdout, "Failed to register ISR for pin %d\n", pin);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print_command_error();
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
print_command_error();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -28,13 +28,12 @@
|
||||
#include "mraa.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_init();
|
||||
fprintf(stdout, "MRAA Version: %s\nStarting Read on IO6\n",
|
||||
mraa_get_version());
|
||||
fprintf(stdout, "MRAA Version: %s\nStarting Read on IO6\n", mraa_get_version());
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
mraa_gpio_context gpio;
|
||||
|
||||
gpio = mraa_gpio_init(6);
|
||||
@@ -47,7 +46,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
mraa_gpio_close(gpio);
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "mraa.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
mraa_platform_t platform_type = mraa_get_platform_type();
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "mraa.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
char* board_name = mraa_get_platform_name();
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@
|
||||
#define MAX_BUFFER_LENGTH 6
|
||||
#define HMC5883L_I2C_ADDR 0x1E
|
||||
|
||||
//configuration registers
|
||||
// configuration registers
|
||||
#define HMC5883L_CONF_REG_A 0x00
|
||||
#define HMC5883L_CONF_REG_B 0x01
|
||||
|
||||
//mode register
|
||||
// mode register
|
||||
#define HMC5883L_MODE_REG 0x02
|
||||
|
||||
//data register
|
||||
// data register
|
||||
#define HMC5883L_X_MSB_REG 0
|
||||
#define HMC5883L_X_LSB_REG 1
|
||||
#define HMC5883L_Z_MSB_REG 2
|
||||
@@ -44,10 +44,10 @@
|
||||
#define HMC5883L_Y_LSB_REG 5
|
||||
#define DATA_REG_SIZE 6
|
||||
|
||||
//status register
|
||||
// status register
|
||||
#define HMC5883L_STATUS_REG 0x09
|
||||
|
||||
//ID registers
|
||||
// ID registers
|
||||
#define HMC5883L_ID_A_REG 0x0A
|
||||
#define HMC5883L_ID_B_REG 0x0B
|
||||
#define HMC5883L_ID_C_REG 0x0C
|
||||
@@ -55,7 +55,7 @@
|
||||
#define HMC5883L_CONT_MODE 0x00
|
||||
#define HMC5883L_DATA_REG 0x03
|
||||
|
||||
//scales
|
||||
// scales
|
||||
#define GA_0_88_REG 0x00 << 5
|
||||
#define GA_1_3_REG 0x01 << 5
|
||||
#define GA_1_9_REG 0x02 << 5
|
||||
@@ -65,7 +65,7 @@
|
||||
#define GA_5_6_REG 0x06 << 5
|
||||
#define GA_8_1_REG 0x07 << 5
|
||||
|
||||
//digital resolutions
|
||||
// digital resolutions
|
||||
#define SCALE_0_73_MG 0.73
|
||||
#define SCALE_0_92_MG 0.92
|
||||
#define SCALE_1_22_MG 1.22
|
||||
@@ -76,14 +76,14 @@
|
||||
#define SCALE_4_35_MG 4.35
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_init();
|
||||
float direction = 0;
|
||||
int16_t x = 0, y = 0, z = 0;
|
||||
uint8_t rx_tx_buf[MAX_BUFFER_LENGTH];
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
mraa_i2c_context i2c;
|
||||
i2c = mraa_i2c_init(0);
|
||||
|
||||
@@ -91,14 +91,14 @@ main(int argc, char **argv)
|
||||
rx_tx_buf[0] = HMC5883L_CONF_REG_B;
|
||||
rx_tx_buf[1] = GA_1_3_REG;
|
||||
mraa_i2c_write(i2c, rx_tx_buf, 2);
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
|
||||
rx_tx_buf[0] = HMC5883L_MODE_REG;
|
||||
rx_tx_buf[1] = HMC5883L_CONT_MODE;
|
||||
mraa_i2c_write(i2c, rx_tx_buf, 2);
|
||||
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
#if 0
|
||||
int i = 0;
|
||||
//alternative, equivalent method which helps to understand exactly what
|
||||
@@ -118,18 +118,19 @@ main(int argc, char **argv)
|
||||
// this call behaves very similarly to the Wire receive() call
|
||||
mraa_i2c_read(i2c, rx_tx_buf, DATA_REG_SIZE);
|
||||
|
||||
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_X_LSB_REG] ;
|
||||
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Z_LSB_REG] ;
|
||||
y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Y_LSB_REG] ;
|
||||
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8) | rx_tx_buf[HMC5883L_X_LSB_REG];
|
||||
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Z_LSB_REG];
|
||||
y = (rx_tx_buf[HMC5883L_Y_MSB_REG] << 8) | rx_tx_buf[HMC5883L_Y_LSB_REG];
|
||||
|
||||
//scale and calculate direction
|
||||
// scale and calculate direction
|
||||
direction = atan2(y * SCALE_0_92_MG, x * SCALE_0_92_MG);
|
||||
|
||||
//check if the signs are reversed
|
||||
// check if the signs are reversed
|
||||
if (direction < 0)
|
||||
direction += 2 * M_PI;
|
||||
|
||||
printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG, z * SCALE_0_92_MG) ;
|
||||
printf("Heading : %f\n", direction * 180/M_PI) ;
|
||||
printf("Compass scaled data x : %f, y : %f, z : %f\n", x * SCALE_0_92_MG, y * SCALE_0_92_MG,
|
||||
z * SCALE_0_92_MG);
|
||||
printf("Heading : %f\n", direction * 180 / M_PI);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,14 @@
|
||||
static volatile int counter = 0;
|
||||
static volatile int oldcounter = 0;
|
||||
|
||||
void interrupt (void * args) {
|
||||
void
|
||||
interrupt(void* args)
|
||||
{
|
||||
++counter;
|
||||
}
|
||||
|
||||
int main ()
|
||||
int
|
||||
main()
|
||||
{
|
||||
mraa_init();
|
||||
mraa_gpio_context x;
|
||||
@@ -46,13 +49,13 @@ int main ()
|
||||
mraa_gpio_dir(x, MRAA_GPIO_IN);
|
||||
|
||||
gpio_edge_t edge = MRAA_GPIO_EDGE_BOTH;
|
||||
|
||||
|
||||
mraa_gpio_isr(x, edge, &interrupt, NULL);
|
||||
|
||||
for(;;) {
|
||||
if(counter != oldcounter) {
|
||||
fprintf(stdout, "timeout counter == %d\n", counter);
|
||||
oldcounter = counter;
|
||||
for (;;) {
|
||||
if (counter != oldcounter) {
|
||||
fprintf(stdout, "timeout counter == %d\n", counter);
|
||||
oldcounter = counter;
|
||||
}
|
||||
// got to relieve our poor CPU!
|
||||
sleep(1);
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
#include "mraa.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
fprintf(stdout, "hello mraa\n Version: %s\n", mraa_get_version());
|
||||
mraa_gpio_context gpio;
|
||||
gpio = mraa_gpio_init(2);
|
||||
@@ -38,10 +38,10 @@ main(int argc, char **argv)
|
||||
mraa_gpio_use_mmaped(gpio, 1);
|
||||
|
||||
for (;;) {
|
||||
mraa_gpio_write(gpio , 1);
|
||||
mraa_gpio_write(gpio, 1);
|
||||
usleep(50000);
|
||||
mraa_gpio_write(gpio, 0);
|
||||
usleep(50000);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
}
|
||||
|
||||
@@ -28,8 +28,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
//! [Interesting]
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
mraa_spi_context spi;
|
||||
spi = mraa_spi_init(1);
|
||||
if (spi == NULL) {
|
||||
@@ -48,26 +49,26 @@ main(int argc, char **argv) {
|
||||
exit(1);
|
||||
};
|
||||
|
||||
mraa_spi_write_word(spi, 0x0900); // Do not decode bits
|
||||
mraa_spi_write_word(spi, 0x0a05); // Brightness of LEDs
|
||||
mraa_spi_write_word(spi, 0x0b07); // Show all Scan Lines
|
||||
mraa_spi_write_word(spi, 0x0c01); // Display on
|
||||
mraa_spi_write_word(spi, 0x0f00); // Testmode off
|
||||
mraa_spi_write_word(spi, 0x0900); // Do not decode bits
|
||||
mraa_spi_write_word(spi, 0x0a05); // Brightness of LEDs
|
||||
mraa_spi_write_word(spi, 0x0b07); // Show all Scan Lines
|
||||
mraa_spi_write_word(spi, 0x0c01); // Display on
|
||||
mraa_spi_write_word(spi, 0x0f00); // Testmode off
|
||||
|
||||
// Display Pattern on the display
|
||||
uint16_t dataAA55[] = {0x01aa, 0x0255, 0x03aa, 0x0455, 0x05aa, 0x0655, 0x07aa, 0x0855};
|
||||
uint16_t dataAA55[] = { 0x01aa, 0x0255, 0x03aa, 0x0455, 0x05aa, 0x0655, 0x07aa, 0x0855 };
|
||||
mraa_spi_write_buf_word(spi, dataAA55, 16);
|
||||
|
||||
sleep(2);
|
||||
|
||||
// Display inverted Pattern
|
||||
uint16_t data55AA[] = {0x0155, 0x02aa, 0x0355, 0x04aa, 0x0555, 0x06aa, 0x0755, 0x08aa};
|
||||
uint16_t data55AA[] = { 0x0155, 0x02aa, 0x0355, 0x04aa, 0x0555, 0x06aa, 0x0755, 0x08aa };
|
||||
mraa_spi_write_buf_word(spi, data55AA, 16);
|
||||
|
||||
sleep(2);
|
||||
|
||||
// Clear the display
|
||||
uint16_t data[] = {0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800};
|
||||
uint16_t data[] = { 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800 };
|
||||
mraa_spi_write_buf_word(spi, data, 16);
|
||||
|
||||
int i;
|
||||
@@ -83,5 +84,5 @@ main(int argc, char **argv) {
|
||||
|
||||
mraa_spi_stop(spi);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
}
|
||||
|
||||
@@ -27,32 +27,32 @@
|
||||
#include <stdint.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_init();
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
mraa_spi_context spi;
|
||||
spi = mraa_spi_init(0);
|
||||
unsigned int response = 0;
|
||||
printf("Hello, SPI initialised\n");
|
||||
uint8_t data[] = {0x00, 100};
|
||||
uint8_t *recv;
|
||||
while(1) {
|
||||
uint8_t data[] = { 0x00, 100 };
|
||||
uint8_t* recv;
|
||||
while (1) {
|
||||
int i;
|
||||
for (i = 90; i < 130; i++) {
|
||||
data[1] = i;
|
||||
recv = mraa_spi_write_buf(spi, data, 2);
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
printf("Writing -%i", i);
|
||||
printf("RECIVED-%i-%i\n", recv[0], recv[1]);
|
||||
usleep(100000);
|
||||
}
|
||||
for (i = 130; i > 90; i--) {
|
||||
data[1] = i;
|
||||
recv = mraa_spi_write_buf(spi, data, 2);
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
printf("Writing -%i", i);
|
||||
printf("RECIVED-%i-%i\n", recv[0], recv[1]);
|
||||
usleep(100000);
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "mraa.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
mraa_uart_context uart;
|
||||
uart = mraa_uart_init(0);
|
||||
|
||||
Reference in New Issue
Block a user