Skip to content
Snippets Groups Projects
Commit 946b34f5 authored by DAsamhan's avatar DAsamhan
Browse files

add callback

parent cecc6f63
Branches
1 merge request!6Implement main application
......@@ -45,6 +45,10 @@ void BleScanner::SetScan(bool enable){
}
}
void BleScanner::RegisterCallback(void (*callback)(std::string, std::vector<uint8_t>, int8_t)){
registeredCallback = callback;
}
void BleScanner::BleDevicefound(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, struct net_buf_simple *ad){
char addr_str[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
......
......@@ -11,7 +11,7 @@ static IrDriver *context;
IrDriver::IrDriver(){
context = this;
int err = gpio_pin_configure_dt(&irSensorNode, GPIO_INPUT);
gpio_pin_interrupt_configure_dt(&irSensorNode, GPIO_INT_EDGE_BOTH);
gpio_pin_interrupt_configure_dt(&irSensorNode, GPIO_INT_EDGE_RISING);
gpio_init_callback(&irSensorCb, InterruptCallback, BIT(irSensorNode.pin));
gpio_add_callback(irSensorNode.port, &irSensorCb);
......
......@@ -24,6 +24,8 @@ DriverHook::DriverHook(){
ledDriver = new LedDriver();
servoDriver = new ServoDriver();
irDriver = new IrDriver();
irDriver->RegisterInterrupt(IrSensorCallback);
bleScanner->RegisterCallback(BleDataCallback);
zbus_chan_add_obs(&driverRequestChannel, &driverHookListener, K_NO_WAIT);
}
......@@ -32,6 +34,23 @@ DriverHook::~DriverHook(){
}
void DriverHook::IrSensorCallback(uint8_t data){
LOG_INF("Iterrupt triggeredd. pin %d", data);
std::vector<uint8_t> sensorData;
sensorData.push_back(data);
DriverMessage_t sentMessage = {
.number = IR_DRIVER,
.type = REQUEST_SET,
.value = sensorData
};
zbus_chan_pub(&driverResponseChannel, &sentMessage, K_MSEC(200));
}
void DriverHook::BleDataCallback(std::string addr, std::vector<uint8_t> data, int8_t rssi){
LOG_HEXDUMP_INF(data.data(), data.size(), "BLE data:");
}
void DriverHook::Init(){
......@@ -93,8 +112,6 @@ void DriverHook::DriverRequestListener(const struct zbus_channel *chan){
break;
}
LOG_INF("Sensor data %d", msg->value[0]);
int status = zbus_chan_pub(&driverResponseChannel, &sentMessage, K_MSEC(200));
LOG_INF("Status pub %d", status);
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment