From 30ad9964f62df00b40298f8410bf34bca8ad7555 Mon Sep 17 00:00:00 2001 From: edwin Date: Sat, 10 Apr 2021 12:45:55 +0100 Subject: [PATCH] work onmemberfunctions --- MCP4725/mcp4725.cpp | 35 +++++++++++++++++++++++++++++++++-- MCP4725/mcp4725.hpp | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/MCP4725/mcp4725.cpp b/MCP4725/mcp4725.cpp index 022bf11..be4c001 100644 --- a/MCP4725/mcp4725.cpp +++ b/MCP4725/mcp4725.cpp @@ -16,7 +16,7 @@ MCP4725::MCP4725(pwrd_md power_down_mode, temp[4] = temp[1]; temp[5] = temp[2]; - i2c_write(temp,6); + i2c_write(address, temp,6); } MCP4725::MCP4725(i2c_addr address, @@ -34,7 +34,7 @@ MCP4725::MCP4725(i2c_addr address, temp[4] = temp[1]; temp[5] = temp[2]; - i2c_write(temp,6); + i2c_write(address, temp, 6); } MCP4725::~MCP4725() @@ -42,4 +42,35 @@ MCP4725::~MCP4725() } +void MCP4725::operator=(uint16_t dac_value) +{ + uint8_t temp[3]; + this.dac_value = dac_value; + + temp[0] = write_dac | (power_down_mode << 1); + temp[1] = static_cast(dac_value >> 4); + temp[2] = static_cast(dac_value << 4); + + i2c_write(address, temp, 3); +} + +void MCP4725::operator==(uint16_t dac_and_eeprom_value) +{ + uint8_t temp[6]; + dac_value = dac_and_eeprom_value; + eeprom_value = dac_value; + + temp[0] = write_dac_and_eeprom | (power_down_mode << 1); +} + +void MCP4725::write_dac(uint16_t dac_value) +{ + &this = dac_value; +} + +void MCP4725::write_dac_and_eeprom(uint16_t dac_and_eeprom_value) +{ + &this == dac_and_eeprom_value; +} + diff --git a/MCP4725/mcp4725.hpp b/MCP4725/mcp4725.hpp index 6effe30..60f653c 100644 --- a/MCP4725/mcp4725.hpp +++ b/MCP4725/mcp4725.hpp @@ -31,7 +31,7 @@ class MCP4725 //using std::functional i2c_read_n_t; - using std::functional i2c_write_n_t; + using i2c_write_n_t = std::functional; MCP4725(pwrd_md power_down_mode, i2c_addr address,