Skip to content

Commit

Permalink
✨ (spike): Battery use register callback charge to turn on/off mainbo…
Browse files Browse the repository at this point in the history
…ard led
  • Loading branch information
YannLocatelli committed Jan 21, 2022
1 parent 657b8f5 commit 12bd71c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions spikes/lk_sensors_battery/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// SPDX-License-Identifier: Apache-2.0

#include "drivers/BufferedSerial.h"
#include "drivers/DigitalOut.h"
#include "drivers/InterruptIn.h"
#include "rtos/ThisThread.h"

#include "CoreBattery.h"
#include "HelloWorld.h"
#include "LogKit.h"

using namespace leka;
Expand All @@ -19,11 +19,17 @@ auto main() -> int

auto charge_input = mbed::InterruptIn {PinName::BATTERY_CHARGE_STATUS};
auto corebattery = leka::CoreBattery {PinName::BATTERY_VOLTAGE, charge_input};
auto mainboard_led = mbed::DigitalOut {LED1};

log_info("Hello, World!\n\n");

HelloWorld hello;
hello.start();
mainboard_led.write(corebattery.isCharging());

auto on_charge_on = [&]() { mainboard_led.write(1); };
corebattery.registerCallbackChargeInputOn(on_charge_on);

auto on_charge_off = [&]() { mainboard_led.write(0); };
corebattery.registerCallbackChargeInputOff(on_charge_off);

while (true) {
if (corebattery.isCharging()) {
Expand Down

0 comments on commit 12bd71c

Please sign in to comment.