<commit_before>/*

Copyright 2015-2019 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

#include "OpenDeck.h"
#include "core/src/general/Timing.h"
#include "core/src/general/Interrupt.h"
#include "interface/CInfo.h"

// clang-format off
ComponentInfo                       cinfo;
Database                            database(Board::eeprom::read, Board::eeprom::write, EEPROM_SIZE - 3);
MIDI                                midi;
Interface::digital::input::Common   digitalInputCommon;
#ifdef DISPLAY_SUPPORTED
Interface::Display                  display;
#endif
#ifdef TOUCHSCREEN_SUPPORTED
//assume sdw only for now
#include "interface/display/touch/model/sdw/SDW.h"
SDW                                 sdw;
Interface::Touchscreen              touchscreen(sdw);
#endif
#ifdef LEDS_SUPPORTED
Interface::digital::output::LEDs    leds(database);
#endif
#ifdef LEDS_SUPPORTED
#ifdef DISPLAY_SUPPORTED
Interface::analog::Analog           analog(database, midi, leds, display, cinfo);
#else
Interface::analog::Analog           analog(database, midi, leds, cinfo);
#endif
#else
#ifdef DISPLAY_SUPPORTED
Interface::analog::Analog           analog(database, midi, display, cinfo);
#else
Interface::analog::Analog           analog(database, midi, cinfo);
#endif
#endif
#ifdef LEDS_SUPPORTED
#ifdef DISPLAY_SUPPORTED
Interface::digital::input::Buttons  buttons(database, midi, leds, display, cinfo);
#else
Interface::digital::input::Buttons  buttons(database, midi, leds, cinfo);
#endif
#else
#ifdef DISPLAY_SUPPORTED
Interface::digital::input::Buttons  buttons(database, midi, display, cinfo);
#else
Interface::digital::input::Buttons  buttons(database, midi, cinfo);
#endif
#endif
#ifdef DISPLAY_SUPPORTED
Interface::digital::input::Encoders encoders(database, midi, display, cinfo);
#else
Interface::digital::input::Encoders encoders(database, midi, cinfo);
#endif
#ifdef LEDS_SUPPORTED
#ifdef DISPLAY_SUPPORTED
SysConfig                           sysConfig(database, midi, buttons, encoders, analog, leds, display);
#else
SysConfig                           sysConfig(database, midi, buttons, encoders, analog, leds);
#endif
#else
#ifdef DISPLAY_SUPPORTED
SysConfig                           sysConfig(database, midi, buttons, encoders, analog, display);
#else
SysConfig                           sysConfig(database, midi, buttons, encoders, analog);
#endif
#endif
// clang-format on

void OpenDeck::init()
{
    Board::init();
    database.init();
    sysConfig.init();

    sysConfig.configureMIDI();
    Board::io::ledFlashStartup(Board::checkNewRevision());

#ifdef LEDS_SUPPORTED
    leds.init();
#endif

    encoders.init();

#ifdef DISPLAY_SUPPORTED
    if (database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureEnable))
    {
        if (display.init(static_cast<displayController_t>(database.read(DB_BLOCK_DISPLAY, dbSection_display_hw, displayHwController)), static_cast<displayResolution_t>(database.read(DB_BLOCK_DISPLAY, dbSection_display_hw, displayHwResolution)), false))
        {
            display.setDirectWriteState(true);

            if (database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureWelcomeMsg))
                display.displayWelcomeMessage();

            if (database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureVInfoMsg))
                display.displayVinfo(false);

            display.setDirectWriteState(false);

            display.displayHome();
            display.setRetentionState(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDIeventRetention));
            display.setRetentionTime(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDIeventTime) * 1000);
            display.setAlternateNoteDisplay(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDInotesAlternate));
        }
    }
#endif

#ifdef TOUCHSCREEN_SUPPORTED
#ifdef OD_BOARD_BERGAMOT
    touchscreen.init();
    touchscreen.setScreen(1);
#endif
#endif

    cinfo.registerHandler([](dbBlockID_t dbBlock, SysExConf::sysExParameter_t componentID) {
        return sysConfig.sendCInfo(dbBlock, componentID);
    });

    analog.setButtonHandler([](uint8_t analogIndex, uint16_t adcValue) {
        buttons.processButton(analogIndex + MAX_NUMBER_OF_BUTTONS, buttons.getStateFromAnalogValue(adcValue));
    });

#ifdef TOUCHSCREEN_SUPPORTED
    touchscreen.setButtonHandler([](uint8_t index, bool state) {
        buttons.processButton(MAX_NUMBER_OF_BUTTONS + MAX_NUMBER_OF_ANALOG + index, state);
    });
#endif

    database.setPresetChangeHandler([](uint8_t preset) {
#ifdef LEDS_SUPPORTED
        leds.midiToState(MIDI::messageType_t::programChange, preset, 0, 0, true);
#endif

#ifdef DISPLAY_SUPPORTED
        display.init(static_cast<displayController_t>(database.read(DB_BLOCK_DISPLAY, dbSection_display_hw, displayHwController)), static_cast<displayResolution_t>(database.read(DB_BLOCK_DISPLAY, dbSection_display_hw, displayHwResolution)));
        display.setRetentionState(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDIeventRetention));
        display.setRetentionTime(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDIeventTime) * 1000);
        display.setAlternateNoteDisplay(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDInotesAlternate));
        display.displayMIDIevent(Interface::Display::eventType_t::in, Interface::Display::event_t::presetChange, preset, 0, 0);
#endif
    });
}

void OpenDeck::checkComponents()<commit_msg>indicate current program on startup via leds<commit_after>/*

Copyright 2015-2019 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

#include "OpenDeck.h"
#include "core/src/general/Timing.h"
#include "core/src/general/Interrupt.h"
#include "interface/CInfo.h"

// clang-format off
ComponentInfo                       cinfo;
Database                            database(Board::eeprom::read, Board::eeprom::write, EEPROM_SIZE - 3);
MIDI                                midi;
Interface::digital::input::Common   digitalInputCommon;
#ifdef DISPLAY_SUPPORTED
Interface::Display                  display;
#endif
#ifdef TOUCHSCREEN_SUPPORTED
//assume sdw only for now
#include "interface/display/touch/model/sdw/SDW.h"
SDW                                 sdw;
Interface::Touchscreen              touchscreen(sdw);
#endif
#ifdef LEDS_SUPPORTED
Interface::digital::output::LEDs    leds(database);
#endif
#ifdef LEDS_SUPPORTED
#ifdef DISPLAY_SUPPORTED
Interface::analog::Analog           analog(database, midi, leds, display, cinfo);
#else
Interface::analog::Analog           analog(database, midi, leds, cinfo);
#endif
#else
#ifdef DISPLAY_SUPPORTED
Interface::analog::Analog           analog(database, midi, display, cinfo);
#else
Interface::analog::Analog           analog(database, midi, cinfo);
#endif
#endif
#ifdef LEDS_SUPPORTED
#ifdef DISPLAY_SUPPORTED
Interface::digital::input::Buttons  buttons(database, midi, leds, display, cinfo);
#else
Interface::digital::input::Buttons  buttons(database, midi, leds, cinfo);
#endif
#else
#ifdef DISPLAY_SUPPORTED
Interface::digital::input::Buttons  buttons(database, midi, display, cinfo);
#else
Interface::digital::input::Buttons  buttons(database, midi, cinfo);
#endif
#endif
#ifdef DISPLAY_SUPPORTED
Interface::digital::input::Encoders encoders(database, midi, display, cinfo);
#else
Interface::digital::input::Encoders encoders(database, midi, cinfo);
#endif
#ifdef LEDS_SUPPORTED
#ifdef DISPLAY_SUPPORTED
SysConfig                           sysConfig(database, midi, buttons, encoders, analog, leds, display);
#else
SysConfig                           sysConfig(database, midi, buttons, encoders, analog, leds);
#endif
#else
#ifdef DISPLAY_SUPPORTED
SysConfig                           sysConfig(database, midi, buttons, encoders, analog, display);
#else
SysConfig                           sysConfig(database, midi, buttons, encoders, analog);
#endif
#endif
// clang-format on

void OpenDeck::init()
{
    Board::init();
    database.init();
    sysConfig.init();

    sysConfig.configureMIDI();
    Board::io::ledFlashStartup(Board::checkNewRevision());

#ifdef LEDS_SUPPORTED
    leds.init();
#endif

    encoders.init();

#ifdef DISPLAY_SUPPORTED
    if (database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureEnable))
    {
        if (display.init(static_cast<displayController_t>(database.read(DB_BLOCK_DISPLAY, dbSection_display_hw, displayHwController)), static_cast<displayResolution_t>(database.read(DB_BLOCK_DISPLAY, dbSection_display_hw, displayHwResolution)), false))
        {
            display.setDirectWriteState(true);

            if (database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureWelcomeMsg))
                display.displayWelcomeMessage();

            if (database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureVInfoMsg))
                display.displayVinfo(false);

            display.setDirectWriteState(false);

            display.displayHome();
            display.setRetentionState(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDIeventRetention));
            display.setRetentionTime(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDIeventTime) * 1000);
            display.setAlternateNoteDisplay(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDInotesAlternate));
        }
    }
#endif

#ifdef TOUCHSCREEN_SUPPORTED
#ifdef OD_BOARD_BERGAMOT
    touchscreen.init();
    touchscreen.setScreen(1);
#endif
#endif

    cinfo.registerHandler([](dbBlockID_t dbBlock, SysExConf::sysExParameter_t componentID) {
        return sysConfig.sendCInfo(dbBlock, componentID);
    });

    analog.setButtonHandler([](uint8_t analogIndex, uint16_t adcValue) {
        buttons.processButton(analogIndex + MAX_NUMBER_OF_BUTTONS, buttons.getStateFromAnalogValue(adcValue));
    });

#ifdef TOUCHSCREEN_SUPPORTED
    touchscreen.setButtonHandler([](uint8_t index, bool state) {
        buttons.processButton(MAX_NUMBER_OF_BUTTONS + MAX_NUMBER_OF_ANALOG + index, state);
    });
#endif

    database.setPresetChangeHandler([](uint8_t preset) {
#ifdef LEDS_SUPPORTED
        leds.midiToState(MIDI::messageType_t::programChange, preset, 0, 0, true);
#endif

#ifdef DISPLAY_SUPPORTED
        display.init(static_cast<displayController_t>(database.read(DB_BLOCK_DISPLAY, dbSection_display_hw, displayHwController)), static_cast<displayResolution_t>(database.read(DB_BLOCK_DISPLAY, dbSection_display_hw, displayHwResolution)));
        display.setRetentionState(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDIeventRetention));
        display.setRetentionTime(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDIeventTime) * 1000);
        display.setAlternateNoteDisplay(database.read(DB_BLOCK_DISPLAY, dbSection_display_features, displayFeatureMIDInotesAlternate));
        display.displayMIDIevent(Interface::Display::eventType_t::in, Interface::Display::event_t::presetChange, preset, 0, 0);
#endif
    });

#ifdef LEDS_SUPPORTED
    // on startup, indicate current program for all channels (if any leds have program change assigned as control mode)
    for (int i = 0; i < 16; i++)
        leds.midiToState(MIDI::messageType_t::programChange, 0, 0, i, false);
#endif
}

void OpenDeck::checkComponents()
{'fraction_non_alphanumeric': 0.10024154589371981, 'fraction_numerical': 0.005394524959742351, 'mean_word_length': 4.503322995126274, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2476670', 'n_tokens_mistral': 3790, 'n_tokens_neox': 3686, 'n_words': 768}