From 9d2d4679e85f89923ea0884252ed6e2f421d8dae Mon Sep 17 00:00:00 2001 From: yabezsh Date: Fri, 21 Jul 2017 13:54:19 +0200 Subject: [PATCH] added function to split 12 bits command in high/low registers. rewrite read_salt for it --- Salt.cpp | 20 ++++++++++++++++---- Salt.h | 5 +++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Salt.cpp b/Salt.cpp index 62265b3..54d7bc0 100644 --- a/Salt.cpp +++ b/Salt.cpp @@ -13,17 +13,29 @@ void Salt::find_device_address(int8_t high_reg_bits) this -> set_device_address(chip_id << 5 | high_reg_bits); } -/*void Salt::read_salt(int8_t high_reg_bits, int8_t low_reg_bits, uint8_t* command) +void Salt::read_salt(int8_t high_reg_bits, int8_t low_reg_bits, uint8_t* command) { this -> find_device_address(high_reg_bits); this -> get_bus_access(); this -> read_buffer(low_reg_bits,command); } -*/ + void Salt::read_salt(int8_t high_reg_bits, int8_t low_reg_bits, uint16_t* command){} void Salt::write_salt(int8_t high_reg_bits, int8_t low_reg_bits, uint16_t command) {} -void Salt::read_salt(int16_t low_reg_bits, uint16_t* command){} -void Salt::write_salt(int16_t low_reg_bits, uint16_t command) {} +void Salt::read_salt(int16_t full_reg_bits, uint16_t* command) +{ + int8_t high_reg_bits,low_reg_bits; + this->split_register(full_reg_bits, &high_reg_bits, &high_reg_bits); + this->read_salt(high_reg_bits,low_reg_bits,command); + +} + +void Salt::split_register(int16_t full_reg_bits,int8_t* high_reg_bits,int8_t* low_reg_bits) +{ + *high_reg_bits = (full_reg_bits >> 8); + *low_reg_bits = full_reg_bits & 0xFF; +} +void Salt::write_salt(int16_t full_reg_bits, uint16_t command) {} //void Salt::write_salt(int8_t high_reg_bits, int8_t low_reg_bits, uint8_t command) {} diff --git a/Salt.h b/Salt.h index 2804ed6..7f3fbbb 100644 --- a/Salt.h +++ b/Salt.h @@ -8,12 +8,13 @@ class Salt : public I2C { Salt(); ~Salt(); void find_device_address(int8_t); -// void read_salt(int8_t, int8_t, uint8_t*); + void read_salt(int8_t, int8_t, uint8_t*); void read_salt(int8_t, int8_t, uint16_t*); void read_salt(int16_t, uint16_t*); -// void write_salt(int8_t, int8_t, uint8_t); + void write_salt(int8_t, int8_t, uint8_t); void write_salt(int8_t, int8_t, uint16_t); void write_salt(int16_t, uint16_t); + void split_register(int16_t, int8_t*,int8_t*); private: int8_t chip_id;