<commit_before>/******************************************************************
 NCD PCA9634 8-channel PWM board control

 Up to 8 I2C boards can reside on a single I2C bus.
 
 Features:
 - PWM control
 - Smooth transitioning if duration specified

 http://www.github.com/rlisle/Patriot

 Written by <NAME>
 Based on NCD8Relay library.

 BSD license, check license.txt for more information.
 All text above must be included in any redistribution.

 Datasheets:

 Changelog:
 2020-02-11: Initial creation based on PatriotNCD8Relay and PatriotLight
 ******************************************************************/

#include "PatriotNCD8Light.h"

#define MILLIS_PER_SECOND 1000

/**
 * Constructor
 * @param address is the board address set by jumpers (0-7) 0x01 if low switch set
 * @param lightNum is the channel number on the NCD 8 Light board (0-7)
 * @param name String name used to address the light.
 * @param duration Optional seconds value to transition. 0 = immediate, no transition.
 */

NCD8Light::NCD8Light(int8_t address, int8_t lightNum, String name, int8_t duration)
    : Device(name, DeviceType::NCD8Light)
{
    _lightNum   = lightNum;
    // _percent is left uninitialized to pickup state from SRAM
    _currentPercent = _percent;
    _brightness = 100;      // Default to 100
    _dimmingDuration = 2.0; // Default to 2 seconds
    _targetPercent = _percent;
    _incrementPerMillisecond = 0.0;
    _lastUpdateTime = 0;
    _duration   = duration;
    _address = address;
    initializeBoard();
}

int8_t NCD8Light::initializeBoard() {
    int retries = 3;
    byte status;

    // Only the first light loaded needs to initialize the I2C link
    if(!Wire.isEnabled()) {
        Wire.begin();
    }

    do {
        Wire.beginTransmission(_address);
        status = Wire.endTransmission();
    } while( status != 0 && retries-- > 0);

    if(status == 0) {
        Wire.beginTransmission(_address);
        Wire.write(0);          // Mode1 register
        Wire.write(0);          // Osc on, disable AI, subaddrs, allcall
        Wire.endTransmission();

        Wire.beginTransmission(_address);
        Wire.write(1);          // Mode2 register
        Wire.write(0x04);       // Dimming, Not inverted, totem-pole
        Wire.endTransmission();

    } else {
        Serial.println("initializeBoard failed");
    }

    return status;
}<commit_msg>Update NCD write code<commit_after>/******************************************************************
 NCD PCA9634 8-channel PWM board control

 Up to 8 I2C boards can reside on a single I2C bus.
 
 Features:
 - PWM control
 - Smooth transitioning if duration specified

 http://www.github.com/rlisle/Patriot

 Written by <NAME>
 Based on NCD8Relay library.

 BSD license, check license.txt for more information.
 All text above must be included in any redistribution.

 Datasheets:

 Changelog:
 2020-02-11: Initial creation based on PatriotNCD8Relay and PatriotLight
 2020-11-05: Update based on testing with NCD8LightTest
 ******************************************************************/

#include "PatriotNCD8Light.h"

#define MILLIS_PER_SECOND 1000

/**
 * Constructor
 * @param address is the board address set by jumpers (0-7) 0x01 if low switch set, 0x40 if high
 * @param lightNum is the channel number on the NCD 8 Light board (0-7)
 * @param name String name used to address the light.
 * @param duration Optional seconds value to transition. 0 = immediate, no transition.
 */

NCD8Light::NCD8Light(int8_t address, int8_t lightNum, String name, int8_t duration)
    : Device(name, DeviceType::NCD8Light)
{
    _lightNum   = lightNum;
    // _percent is left uninitialized to pickup state from SRAM
    _currentPercent = _percent;
    _brightness = 100;      // Default to 100
    _dimmingDuration = 2.0; // Default to 2 seconds
    _targetPercent = _percent;
    _incrementPerMillisecond = 0.0;
    _lastUpdateTime = 0;
    _duration   = duration;
    _address = address;
    initializeBoard();
}

int8_t NCD8Light::initializeBoard() {
    int retries = 3;
    byte status;

    // Only the first light loaded needs to initialize the I2C link
    if(!Wire.isEnabled()) {
        Wire.begin();
    }

    do {
        Wire.beginTransmission(_address);
        status = Wire.endTransmission();
    } while( status != 0 && retries-- > 0);

    if(status == 0) {
        Wire.beginTransmission(_address);
        Wire.write(0);          // Control register - No AI, point to reg0 Mode1
        Wire.write(0);          // Mode1 reg. Osc on, disable AI, subaddrs, allcall
        Wire.endTransmission();

        Wire.beginTransmission(_address);
        Wire.write(1);          // Mode2 register
        Wire.write(0x04);       // Dimming, Not inverted, totem-pole
        Wire.endTransmission();

        Wire.beginTransmission(_address);
	    Wire.write(0x8c);       // AI + LEDOUT0
	    Wire.write(0xaa);       // LEDOUT0 LEDs 0-3 dimming 
	    Wire.write(0xaa);       // LEDOUT1 LEDS 4-7 dimming
        Wire.endTransmission();

    } else {
        Serial.println("initializeBoard failed");
    }

    return status;
}
{'fraction_non_alphanumeric': 0.14009000195656426, 'fraction_numerical': 0.030326746233613776, 'mean_word_length': 2.941403238242097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1783336', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1466, 'n_words': 472}