Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: KXSD9_2050.cpp
- Revision:
- 1:4dc1a0ac0cf1
- Parent:
- 0:809f34a09f98
--- a/KXSD9_2050.cpp Fri May 16 14:10:09 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-#include "KXSD9_2050.h"
-
-//constructor
-KXSD9_2050::KXSD9_2050(PinName sda, PinName scl, int addr1, int addr2)
- :i2c_k(sda, scl),
- addr_w(addr1),
- addr_r(addr2)
-{};
-
-
-//destructor
-/*
-KXSD9_2050::~KXSD9_2050()
-{
-
-}
-*/
-
-//initialization(default setting)
-void KXSD9_2050::init()
-{
- char cmd_c=0xE1;//Reset Value
- char cmd_b=0x40;//Reset Value
- i2c_k.write(CTRL_REGC, &cmd_c, 1);
- i2c_k.write(CTRL_REGB, &cmd_b, 1);
-}
-
-//read each axial acceleration(unit:g)
-void KXSD9_2050::read_xyz(double *x, double *y, double *z)
-{
- const char addr_x_h = XOUT_H;
- char data[6] = {};
- short int acc[3]={};
- i2c_k.write(addr_w, &addr_x_h, 1);
- wait_us(500);
- i2c_k.read(addr_r, data, 6);
- for(int i=0;i<6;i+=2)acc[i/2]=((short int)data[i] << 4) + (short int)data[i+1] - 2048;
-
- *x = ((double)acc[0])/SENSITIVITY;
- *y = ((double)acc[1])/SENSITIVITY;
- *z = ((double)acc[2])/SENSITIVITY;
-}
-
-
-//read the acceleration in x-axis(unit:g)
-double KXSD9_2050::read_x()
-{
- const char addr_x_h = XOUT_H;
- char data[2] = {};
- short int acc;
- i2c_k.write(addr_w, &addr_x_h, 1);
- wait_us(500);
- i2c_k.read(addr_r, data, 2);
- acc=((short int)data[0] << 4) + (short int)data[1] - 2048;
- return (double)acc/SENSITIVITY;
-}
-
-
-//read the acceleration in y-axis(unit:g)
-double KXSD9_2050::read_y()
-{
- const char addr_y_h = YOUT_H;
- char data[2] = {};
- short int acc;
- i2c_k.write(addr_w, &addr_y_h, 1);
- wait_us(500);
- i2c_k.read(addr_r, data, 2);
- acc=((short int)data[0] << 4) + (short int)data[1] - 2048;
- return (double)acc/SENSITIVITY;
-}
-
-
-//read the acceleration in z-axis(unit:g)
-double KXSD9_2050::read_z()
-{
-
- const char addr_z_h = ZOUT_H;
- char data[2] = {0,0};
- short int acc;
- i2c_k.write(addr_w, &addr_z_h, 1);
- wait_us(500);
- i2c_k.read(addr_r, data, 2);
- acc=((short int)data[0] << 4) + (short int)data[1] - 2048;
- return (double)acc/SENSITIVITY;
-}
-
-/*
-//read from KXSD9_2050 register
-char KXSD9_2050::read_reg(char addr)
-{
-
-}
-*/
-
-//write register
-/*
-void KXSD9_2050::write_reg(char addr, char data)
-{
-
-}
-*/
\ No newline at end of file