Blink-IO.cpp: use mraa_result_t instead of int
[contrib/mraa.git] / examples / c++ / I2c-compass.cpp
index 2c3aecd..a17cb68 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 #include <signal.h>
 
-#include "i2c.hpp"
+#include "mraa.hpp"
 #include "math.h"
 
 #define MAX_BUFFER_LENGTH 6
@@ -86,29 +86,37 @@ void
 sig_handler(int signo)
 {
     if (signo == SIGINT) {
-        printf("closing PWM nicely\n");
+        printf("closing nicely\n");
         running = -1;
     }
 }
 
 int main ()
 {
-    maa::I2c* i2c;
-    i2c = new maa::I2c(0);
     float direction = 0;
     int16_t x = 0, y = 0, z = 0;
     char rx_tx_buf[MAX_BUFFER_LENGTH];
 
+//! [Interesting]
+    mraa::I2c* i2c;
+    i2c = new mraa::I2c(0);
+
     i2c->address(HMC5883L_I2C_ADDR);
     rx_tx_buf[0] = HMC5883L_CONF_REG_B;
     rx_tx_buf[1] = GA_1_3_REG;
     i2c->write(rx_tx_buf, 2);
+//! [Interesting]
+
+    i2c->address(HMC5883L_I2C_ADDR);
+    rx_tx_buf[0] = HMC5883L_MODE_REG;
+    rx_tx_buf[1] = HMC5883L_CONT_MODE;
+    i2c->write(rx_tx_buf, 2);
 
     signal(SIGINT, sig_handler);
 
     while (running == 0) {
         i2c->address(HMC5883L_I2C_ADDR);
-        i2c->write_byte(HMC5883L_DATA_REG);
+        i2c->write(HMC5883L_DATA_REG);
 
         i2c->address(HMC5883L_I2C_ADDR);
         i2c->read(rx_tx_buf, DATA_REG_SIZE);
@@ -130,5 +138,5 @@ int main ()
     }
     delete i2c;
 
-    return MAA_SUCCESS;
+    return MRAA_SUCCESS;
 }