Private
Public Access
2
0

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:
Brendan Le Foll
2015-03-23 14:39:12 +00:00
parent 2174ee1673
commit ffcf3d7d07
46 changed files with 1630 additions and 1455 deletions

View File

@@ -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);

View File

@@ -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]
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}