Skip to content

Commit

Permalink
chk
Browse files Browse the repository at this point in the history
  • Loading branch information
echavemann committed Dec 8, 2024
1 parent beb7536 commit ab16448
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
11 changes: 11 additions & 0 deletions include/drivers/captouch_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class CapsenseController {

bool touched;

bool test_done;

uint32_t timed_id;

etl::mutex doneLock;

GPIOPinEvent event;

CapsenseController();
Expand All @@ -37,6 +43,11 @@ class CapsenseController {
bool get_captouch_pressed();

void handle_gpio_interrupt(nrf_gpio_pin_sense_t sense, int pin);

void handle_timer_interrupt();

void start_capacitive_test();

};

} // namespace edge::drivers
44 changes: 37 additions & 7 deletions src/drivers/captouch_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "drivers/driver_enums.hpp"
#include "drivers/gpio_pin_event.hpp"
#include "drivers/virtual_timer_controller.hpp"
#include "hal/gpio_wrapper.hpp"
#include "hal/hal_enums.hpp"
#include "microbit_v2.h"
Expand All @@ -10,19 +11,18 @@

namespace edge::drivers {


CapsenseController::CapsenseController() :
touched(false),
test_done(false),
event{
TOUCH_LOGO, GPIOConfiguration::IN_NORES,
aidan::GPIOEventController::GPIOEventCallback::create<
CapsenseController, &CapsenseController::handle_gpio_interrupt>(*this)
}
{
aidan::clear_gpio_pin(TOUCH_LOGO);
nrf_gpio_cfg(
TOUCH_LOGO, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE
);
VirtualTimerController& virtualTimerController = VirtualTimerController::get();
virtualTimerController.virtual_timer_start(100000, etl::delegate<void()>::create<CapsenseController, &CapsenseController::start_capacitive_test>(*this), 0, true);
};

CapsenseController& CapsenseController::get()
Expand All @@ -46,8 +46,38 @@ bool CapsenseController::get_captouch_pressed()

void CapsenseController::handle_gpio_interrupt(nrf_gpio_pin_sense_t sense, int pin)
{
printf("interrupt?");
touched = false;
if (test_done == false)
{
test_done = true;
touched = false;
printf("Not touched\n");
}
VirtualTimerController::get().virtual_timer_cancel(timed_id);
}

void CapsenseController::handle_timer_interrupt()
{
if (test_done == false)
{
test_done = true;
touched = true;
printf("Touched\n");
}

}

void CapsenseController::start_capacitive_test()
{
printf("Starting cap test\n");
test_done = false;
VirtualTimerController& vtcontroller = VirtualTimerController::get();
aidan::clear_gpio_pin(TOUCH_LOGO);
/* vtcontroller.virtual_timer_start(30000, etl::delegate<void()>::create<CapsenseController, &CapsenseController::handle_timer_interrupt>(*this), 0, false); */
nrf_gpio_cfg(
TOUCH_LOGO, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE
);
}


} // namespace edge::drivers

0 comments on commit ab16448

Please sign in to comment.