← back to lshaf__unigeek

Function bodies 879 total

All specs Real LLM only Function bodies
EncoderNavigation class · c · L12-L69 (58 LOC)
firmware/boards/m5stickcplus_11/core/EncoderNavigation.h
class EncoderNavigation : public INavigation
{
public:
  EncoderNavigation(AXP192* axp) : _axp(axp) {}

  void begin() override
  {
    encoder.begin();
  }

  void update() override
  {
    // BTN_A short press (< 3 s) = back; 3 s hold is handled in Device::boardHook()
    bool btnA = (digitalRead(BTN_A) == LOW);
    if (btnA && !_btnAWasLow) {
      _btnAStart  = millis();
      _btnAWasLow = true;
    } else if (!btnA && _btnAWasLow) {
      if (millis() - _btnAStart < 3000) _emitBack = true;
      _btnAWasLow = false;
    }
    if (_emitBack) { _emitBack = false; updateState(DIR_BACK); return; }

    // AXP M5 button = left
    if (_axp->GetBtnPress()) _emitLeft = true;
    if (_emitLeft) { _emitLeft = false; updateState(DIR_LEFT); return; }

    // BTN_B release = right
    bool btnB = (digitalRead(BTN_B) == LOW);
    if (btnB && !_btnBWasLow) {
      _btnBWasLow = true;
    } else if (!btnB && _btnBWasLow) {
      _emitRight  = true;
      _btnBWasLow = false;
    }
    if (_emi
begin method · c · L17-L21 (5 LOC)
firmware/boards/m5stickcplus_11/core/EncoderNavigation.h
  void begin() override
  {
    encoder.begin();
  }
update method · c · L22-L59 (38 LOC)
firmware/boards/m5stickcplus_11/core/EncoderNavigation.h
  void update() override
  {
    // BTN_A short press (< 3 s) = back; 3 s hold is handled in Device::boardHook()
    bool btnA = (digitalRead(BTN_A) == LOW);
    if (btnA && !_btnAWasLow) {
      _btnAStart  = millis();
      _btnAWasLow = true;
    } else if (!btnA && _btnAWasLow) {
      if (millis() - _btnAStart < 3000) _emitBack = true;
      _btnAWasLow = false;
    }
    if (_emitBack) { _emitBack = false; updateState(DIR_BACK); return; }

    // AXP M5 button = left
    if (_axp->GetBtnPress()) _emitLeft = true;
    if (_emitLeft) { _emitLeft = false; updateState(DIR_LEFT); return; }

    // BTN_B release = right
    bool btnB = (digitalRead(BTN_B) == LOW);
    if (btnB && !_btnBWasLow) {
      _btnBWasLow = true;
    } else if (!btnB && _btnBWasLow) {
      _emitRight  = true;
      _btnBWasLow = false;
    }
    if (_emitRight) { _emitRight = false; updateState(DIR_RIGHT); return; }

    // Encoder
    const bool rotLeft  = encoder.getEncoderValue() <= -2;
    const bool rotR
NavigationImpl class · c · L9-L29 (21 LOC)
firmware/boards/m5stickcplus_11/core/Navigation.h
class NavigationImpl : public INavigation
{
public:
  NavigationImpl(AXP192* axp) : _axp(axp) {}
  void begin() override {}

  void update() override
  {
    const bool btnUp = _axp->GetBtnPress();
    const bool btnDown = (digitalRead(BTN_B) == LOW);
    const bool btnSel = (digitalRead(BTN_A) == LOW);

    if (btnSel) updateState(DIR_PRESS);
    else if (btnUp) updateState(DIR_UP);
    else if (btnDown) updateState(DIR_DOWN);
    else updateState(DIR_NONE);
  }
private:
  AXP192* _axp;
};
update method · c · L15-L26 (12 LOC)
firmware/boards/m5stickcplus_11/core/Navigation.h
  void update() override
  {
    const bool btnUp = _axp->GetBtnPress();
    const bool btnDown = (digitalRead(BTN_B) == LOW);
    const bool btnSel = (digitalRead(BTN_A) == LOW);

    if (btnSel) updateState(DIR_PRESS);
    else if (btnUp) updateState(DIR_UP);
    else if (btnDown) updateState(DIR_DOWN);
    else updateState(DIR_NONE);
  }
PowerImpl class · c · L8-L36 (29 LOC)
firmware/boards/m5stickcplus_11/core/Power.h
class PowerImpl : public IPower
{
public:
  PowerImpl(AXP192* axp) : _axp(axp) {}
  void begin() override
  {
    _axp->begin();
  }
  uint8_t getBatteryPercentage() override
  {
    const float b = _axp->GetBatVoltage();
    const uint8_t percent = ((b - 3.0) / 1.2) * 100;
    return (percent < 0) ? 1 : (percent >= 100) ? 100 : percent;

  }

  void powerOff() override
  {
    _axp->PowerOff();
  }

  bool isCharging() override
  {
    return _axp->GetBatCurrent() > 20;
  }
private:
  AXP192* _axp;
};
begin method · c · L13-L16 (4 LOC)
firmware/boards/m5stickcplus_11/core/Power.h
  void begin() override
  {
    _axp->begin();
  }
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
getBatteryPercentage method · c · L17-L23 (7 LOC)
firmware/boards/m5stickcplus_11/core/Power.h
  uint8_t getBatteryPercentage() override
  {
    const float b = _axp->GetBatVoltage();
    const uint8_t percent = ((b - 3.0) / 1.2) * 100;
    return (percent < 0) ? 1 : (percent >= 100) ? 100 : percent;

  }
powerOff method · c · L24-L28 (5 LOC)
firmware/boards/m5stickcplus_11/core/Power.h
  void powerOff() override
  {
    _axp->PowerOff();
  }
isCharging method · c · L29-L33 (5 LOC)
firmware/boards/m5stickcplus_11/core/Power.h
  bool isCharging() override
  {
    return _axp->GetBatCurrent() > 20;
  }
SpeakerBuzzer class · c · L14-L142 (129 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
class SpeakerBuzzer : public ISpeaker {
public:
  void begin() override {
    ledcSetup(_ch, 1000, 8);
    ledcAttachPin(SPK_PIN, _ch);
    ledcWrite(_ch, 0);
    setVolume(Config.get(APP_CONFIG_VOLUME, APP_CONFIG_VOLUME_DEFAULT).toInt());
  }

  void tone(uint16_t freq, uint32_t durationMs) override {
    _stopTask();
    _freq     = freq;
    _duration = durationMs;
    xTaskCreate(_toneTask, "spkbzz", 1024, this, 2, &_taskHandle);
  }

  void noTone() override {
    _stopTask();
    ledcWrite(_ch, 0);
  }

  void setVolume(uint8_t vol) override {
    // buzzer has no meaningful volume control — piezo max is 50% duty (128).
    // keep _duty at max; silence is handled by noTone() / duty=0 in _playTone.
    (void)vol;
    _duty = 128;
  }

  void beep() override {
    if (!Config.get(APP_CONFIG_NAV_SOUND, APP_CONFIG_NAV_SOUND_DEFAULT).toInt()) return;
    if (_taskHandle) return;  // already playing — skip rapid beeps
    playRandomTone();
  }

  void playRandomTone(int semitoneShift
begin method · c · L16-L22 (7 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
public:
  void begin() override {
    ledcSetup(_ch, 1000, 8);
    ledcAttachPin(SPK_PIN, _ch);
    ledcWrite(_ch, 0);
    setVolume(Config.get(APP_CONFIG_VOLUME, APP_CONFIG_VOLUME_DEFAULT).toInt());
  }
tone method · c · L23-L29 (7 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void tone(uint16_t freq, uint32_t durationMs) override {
    _stopTask();
    _freq     = freq;
    _duration = durationMs;
    xTaskCreate(_toneTask, "spkbzz", 1024, this, 2, &_taskHandle);
  }
noTone method · c · L30-L34 (5 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void noTone() override {
    _stopTask();
    ledcWrite(_ch, 0);
  }
setVolume method · c · L35-L41 (7 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void setVolume(uint8_t vol) override {
    // buzzer has no meaningful volume control — piezo max is 50% duty (128).
    // keep _duty at max; silence is handled by noTone() / duty=0 in _playTone.
    (void)vol;
    _duty = 128;
  }
Want this analysis on your repo? https://repobility.com/scan/
beep method · c · L42-L47 (6 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void beep() override {
    if (!Config.get(APP_CONFIG_NAV_SOUND, APP_CONFIG_NAV_SOUND_DEFAULT).toInt()) return;
    if (_taskHandle) return;  // already playing — skip rapid beeps
    playRandomTone();
  }
playRandomTone method · c · L48-L54 (7 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void playRandomTone(int semitoneShift = 0, uint32_t durationMs = 150) override {
    static constexpr int scale[] = {60, 62, 64, 65, 67, 69, 71};
    int      midi = scale[random(0, 7)] + semitoneShift;
    uint16_t freq = (uint16_t)(440.0 * pow(2.0, (double)(midi - 69) / 12.0));
    tone(freq, durationMs);
  }
playWin method · c · L60-L68 (9 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void playWin() override {
    if (_taskHandle) return;
    _seq[0] = {523, 120, 50};
    _seq[1] = {659, 120, 50};
    _seq[2] = {784, 200, 0};
    _seqLen = 3;
    xTaskCreate(_seqTask, "spkseq", 1024, this, 2, &_taskHandle);
  }
playLose method · c · L69-L77 (9 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void playLose() override {
    if (_taskHandle) return;
    _seq[0] = {392, 120, 50};
    _seq[1] = {330, 120, 50};
    _seq[2] = {262, 200, 0};
    _seqLen = 3;
    xTaskCreate(_seqTask, "spkseq", 1024, this, 2, &_taskHandle);
  }
playCorrectAnswer method · c · L78-L85 (8 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void playCorrectAnswer() override {
    if (_taskHandle) return;
    _seq[0] = {523, 180, 100};
    _seq[1] = {784, 120, 0};
    _seqLen = 2;
    xTaskCreate(_seqTask, "spkseq", 1024, this, 2, &_taskHandle);
  }
playWrongAnswer method · c · L86-L93 (8 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void playWrongAnswer() override {
    if (_taskHandle) return;
    _seq[0] = {1109, 150, 100};
    _seq[1] = {1109, 150, 0};
    _seqLen = 2;
    xTaskCreate(_seqTask, "spkseq", 1024, this, 2, &_taskHandle);
  }
_stopTask method · c · L106-L113 (8 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void _stopTask() {
    if (_taskHandle) {
      vTaskDelete(_taskHandle);
      _taskHandle = nullptr;
      ledcWrite(_ch, 0);
    }
  }
_playTone method · c · L114-L119 (6 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  void _playTone(uint16_t freq) {
    if (freq == 0 || _duty == 0) { ledcWrite(_ch, 0); return; }
    ledcSetup(_ch, freq, 8);
    ledcWrite(_ch, _duty);
  }
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
_toneTask method · c · L120-L128 (9 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  static void _toneTask(void* arg) {
    auto* self = static_cast<SpeakerBuzzer*>(arg);
    self->_playTone(self->_freq);
    vTaskDelay(pdMS_TO_TICKS(self->_duration));
    ledcWrite(_ch, 0);
    self->_taskHandle = nullptr;
    vTaskDelete(nullptr);
  }
_seqTask method · c · L129-L141 (13 LOC)
firmware/boards/m5stickcplus_11/core/Speaker.h
  static void _seqTask(void* arg) {
    auto* self = static_cast<SpeakerBuzzer*>(arg);
    for (uint8_t n = 0; n < self->_seqLen; n++) {
      const Note& note = self->_seq[n];
      self->_playTone(note.freq);
      vTaskDelay(pdMS_TO_TICKS(note.durationMs));
      ledcWrite(_ch, 0);
      if (note.delayMs > 0) vTaskDelay(pdMS_TO_TICKS(note.delayMs));
    }
    self->_taskHandle = nullptr;
    vTaskDelete(nullptr);
  }
begin method · cpp · L4-L44 (41 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::begin(void) {
    Wire1.setClock(400000);
    // Set LDO2 & LDO3(TFT_LED & TFT) 3.0V
    Write1Byte(0x28, 0xcc);

    // Set ADC to All Enable
    Write1Byte(0x82, 0xff);

    // Bat charge voltage to 4.2, Current 100MA
    Write1Byte(0x33, 0xc0);

    // Enable Bat,ACIN,VBUS,APS adc
    Write1Byte(0x82, 0xff);

    // Enable Ext, LDO2, LDO3, DCDC1
    Write1Byte(0x12, Read8bit(0x12) | 0x4D);

    // 128ms power on, 4s power off
    Write1Byte(0x36, 0x0C);

    // Set RTC voltage to 3.3V
    Write1Byte(0x91, 0xF0);

    // Set GPIO0 to LDO
    Write1Byte(0x90, 0x02);

    // Disable vbus hold limit
    Write1Byte(0x30, 0x80);

    // Set temperature protection
    Write1Byte(0x39, 0xfc);

    // Enable RTC BAT charge
    Write1Byte(0x35, 0xa2);

    // Enable bat detection
    Write1Byte(0x32, 0x46);

    // ScreenBreath(80);
}
Write1Byte method · cpp · L45-L51 (7 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::Write1Byte(uint8_t Addr, uint8_t Data) {
    Wire1.beginTransmission(0x34);
    Wire1.write(Addr);
    Wire1.write(Data);
    Wire1.endTransmission();
}
Read8bit method · cpp · L52-L59 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint8_t AXP192::Read8bit(uint8_t Addr) {
    Wire1.beginTransmission(0x34);
    Wire1.write(Addr);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 1);
    return Wire1.read();
}
Read12Bit method · cpp · L60-L67 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::Read12Bit(uint8_t Addr) {
    uint16_t Data = 0;
    uint8_t buf[2];
    ReadBuff(Addr, 2, buf);
    Data = ((buf[0] << 4) + buf[1]);  //
    return Data;
}
Read13Bit method · cpp · L68-L75 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::Read13Bit(uint8_t Addr) {
    uint16_t Data = 0;
    uint8_t buf[2];
    ReadBuff(Addr, 2, buf);
    Data = ((buf[0] << 5) + buf[1]);  //
    return Data;
}
Read16bit method · cpp · L76-L88 (13 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::Read16bit(uint8_t Addr) {
    uint16_t ReData = 0;
    Wire1.beginTransmission(0x34);
    Wire1.write(Addr);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 2);
    for (int i = 0; i < 2; i++) {
        ReData <<= 8;
        ReData |= Wire1.read();
    }
    return ReData;
}
Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
Read24bit method · cpp · L89-L101 (13 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint32_t AXP192::Read24bit(uint8_t Addr) {
    uint32_t ReData = 0;
    Wire1.beginTransmission(0x34);
    Wire1.write(Addr);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 3);
    for (int i = 0; i < 3; i++) {
        ReData <<= 8;
        ReData |= Wire1.read();
    }
    return ReData;
}
Read32bit method · cpp · L102-L114 (13 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint32_t AXP192::Read32bit(uint8_t Addr) {
    uint32_t ReData = 0;
    Wire1.beginTransmission(0x34);
    Wire1.write(Addr);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, 4);
    for (int i = 0; i < 4; i++) {
        ReData <<= 8;
        ReData |= Wire1.read();
    }
    return ReData;
}
ReadBuff method · cpp · L115-L124 (10 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::ReadBuff(uint8_t Addr, uint8_t Size, uint8_t *Buff) {
    Wire1.beginTransmission(0x34);
    Wire1.write(Addr);
    Wire1.endTransmission();
    Wire1.requestFrom(0x34, (int)Size);
    for (int i = 0; i < Size; i++) {
        *(Buff + i) = Wire1.read();
    }
}
ScreenBreath method · cpp · L125-L132 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::ScreenBreath(int brightness) {
    if (brightness > 100 || brightness < 0) return;
    int vol     = map(brightness, 0, 100, 2500, 3200);
    vol         = (vol < 1800) ? 0 : (vol - 1800) / 100;
    uint8_t buf = Read8bit(0x28);
    Write1Byte(0x28, ((buf & 0x0f) | ((uint16_t)vol << 4)));
}
ScreenSwitch method · cpp · L133-L143 (11 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::ScreenSwitch(bool state) {
    uint8_t brightness;
    if (state == false) {
        brightness = 0;
    } else if (state == true) {
        brightness = 12;
    }
    uint8_t buf = Read8bit(0x28);
    Write1Byte(0x28, ((buf & 0x0f) | (brightness << 4)));
}
GetBatState method · cpp · L144-L150 (7 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
bool AXP192::GetBatState() {
    if (Read8bit(0x01) | 0x20)
        return true;
    else
        return false;
}
EnableCoulombcounter method · cpp · L160-L162 (3 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::EnableCoulombcounter(void) {
    Write1Byte(0xB8, 0x80);
}
DisableCoulombcounter method · cpp · L163-L166 (4 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::DisableCoulombcounter(void) {
    Write1Byte(0xB8, 0x00);
}
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
StopCoulombcounter method · cpp · L167-L170 (4 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::StopCoulombcounter(void) {
    Write1Byte(0xB8, 0xC0);
}
ClearCoulombcounter method · cpp · L171-L174 (4 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
void AXP192::ClearCoulombcounter(void) {
    Write1Byte(0xB8, 0xA0);
}
GetCoulombchargeData method · cpp · L175-L178 (4 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint32_t AXP192::GetCoulombchargeData(void) {
    return Read32bit(0xB0);
}
GetCoulombdischargeData method · cpp · L179-L182 (4 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint32_t AXP192::GetCoulombdischargeData(void) {
    return Read32bit(0xB4);
}
GetCoulombData method · cpp · L183-L197 (15 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
float AXP192::GetCoulombData(void) {
    uint32_t coin  = 0;
    uint32_t coout = 0;

    coin  = GetCoulombchargeData();
    coout = GetCoulombdischargeData();

    // c = 65536 * current_LSB * (coin - coout) / 3600 / ADC rate
    // Adc rate can be read from 84H ,change this variable if you change the ADC
    // reate
    float ccc = 65536 * 0.5 * (int32_t)(coin - coout) / 3600.0 / 25.0;

    return ccc;
}
GetVbatData method · cpp · L199-L206 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::GetVbatData(void) {
    uint16_t vbat = 0;
    uint8_t buf[2];
    ReadBuff(0x78, 2, buf);
    vbat = ((buf[0] << 4) + buf[1]);  // V
    return vbat;
}
GetVinData method · cpp · L207-L214 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::GetVinData(void) {
    uint16_t vin = 0;
    uint8_t buf[2];
    ReadBuff(0x56, 2, buf);
    vin = ((buf[0] << 4) + buf[1]);  // V
    return vin;
}
GetIinData method · cpp · L215-L222 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::GetIinData(void) {
    uint16_t iin = 0;
    uint8_t buf[2];
    ReadBuff(0x58, 2, buf);
    iin = ((buf[0] << 4) + buf[1]);
    return iin;
}
Want this analysis on your repo? https://repobility.com/scan/
GetVusbinData method · cpp · L223-L230 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::GetVusbinData(void) {
    uint16_t vin = 0;
    uint8_t buf[2];
    ReadBuff(0x5a, 2, buf);
    vin = ((buf[0] << 4) + buf[1]);  // V
    return vin;
}
GetIusbinData method · cpp · L231-L238 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::GetIusbinData(void) {
    uint16_t iin = 0;
    uint8_t buf[2];
    ReadBuff(0x5C, 2, buf);
    iin = ((buf[0] << 4) + buf[1]);
    return iin;
}
GetIchargeData method · cpp · L239-L246 (8 LOC)
firmware/boards/m5stickcplus_11/lib/AXP192.cpp
uint16_t AXP192::GetIchargeData(void) {
    uint16_t icharge = 0;
    uint8_t buf[2];
    ReadBuff(0x7A, 2, buf);
    icharge = (buf[0] << 5) + buf[1];
    return icharge;
}
‹ prevpage 2 / 18next ›