mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
Conforming to CLANG 2
This commit is contained in:
parent
543a4ba7a4
commit
9b3fd47247
3 changed files with 9 additions and 21 deletions
|
@ -20,15 +20,14 @@ void MCP3204::dump_config() {
|
|||
}
|
||||
|
||||
float MCP3204::read_data(uint8_t channel, bool differential) {
|
||||
|
||||
uint8_t command, sgldiff;
|
||||
uint8_t b0, b1, b2;
|
||||
|
||||
sgldiff = differential ? 0 : 1;
|
||||
|
||||
command = ((0x01 << 7) | // start bit
|
||||
(sgldiff << 6) | // single or differential
|
||||
((channel & 0x07) << 3)); // channel number
|
||||
command = ((0x01 << 7) | // start bit
|
||||
(sgldiff << 6) | // single or differential
|
||||
((channel & 0x07) << 3)); // channel number
|
||||
|
||||
this->enable();
|
||||
b0 = this->transfer_byte(command);
|
||||
|
@ -37,7 +36,7 @@ float MCP3204::read_data(uint8_t channel, bool differential) {
|
|||
this->disable();
|
||||
|
||||
uint16_t digital_value = 0xFFF & ((b0 & 0x01) << 11 | (b1 & 0xFF) << 3 | (b2 & 0xE0) >> 5);
|
||||
return float(digital_value) / 4096.000 * this->reference_voltage_; // in V
|
||||
return float(digital_value) / 4096.000 * this->reference_voltage_; // in V
|
||||
}
|
||||
|
||||
} // namespace mcp3204
|
||||
|
|
|
@ -8,17 +8,12 @@ namespace esphome {
|
|||
namespace mcp3204 {
|
||||
|
||||
class MCP3204 : public Component,
|
||||
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST,
|
||||
spi::CLOCK_POLARITY_LOW,
|
||||
spi::CLOCK_PHASE_LEADING,
|
||||
spi::DATA_RATE_1MHZ> {
|
||||
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
|
||||
spi::DATA_RATE_1MHZ> {
|
||||
public:
|
||||
MCP3204() = default;
|
||||
|
||||
void set_reference_voltage(float reference_voltage)
|
||||
{
|
||||
this->reference_voltage_ = reference_voltage;
|
||||
}
|
||||
void set_reference_voltage(float reference_voltage) { this->reference_voltage_ = reference_voltage; }
|
||||
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
|
|
@ -17,14 +17,8 @@ void MCP3204Sensor::dump_config() {
|
|||
ESP_LOGCONFIG(TAG, " DIFFERENTIAL MODE: %u", this->diffmode_);
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
float MCP3204Sensor::sample()
|
||||
{
|
||||
return this->parent_->read_data(this->pin_, this->diffmode_);
|
||||
}
|
||||
void MCP3204Sensor::update()
|
||||
{
|
||||
this->publish_state(this->sample());
|
||||
}
|
||||
float MCP3204Sensor::sample() { return this->parent_->read_data(this->pin_, this->diffmode_); }
|
||||
void MCP3204Sensor::update() { this->publish_state(this->sample()); }
|
||||
|
||||
} // namespace mcp3204
|
||||
} // namespace esphome
|
||||
|
|
Loading…
Reference in a new issue