forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Weather station: new external radio driver (#3)
* Weather station: new external radio driver
- Loading branch information
Showing
8 changed files
with
135 additions
and
40 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
applications/external/weather_station/helpers/radio_device_loader.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "radio_device_loader.h" | ||
|
||
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h> | ||
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h> | ||
|
||
static void radio_device_loader_power_on() { | ||
uint8_t attempts = 0; | ||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) { | ||
furi_hal_power_enable_otg(); | ||
//CC1101 power-up time | ||
furi_delay_ms(10); | ||
} | ||
} | ||
|
||
static void radio_device_loader_power_off() { | ||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); | ||
} | ||
|
||
bool radio_device_loader_is_connect_external(const char* name) { | ||
bool is_connect = false; | ||
bool is_otg_enabled = furi_hal_power_is_otg_enabled(); | ||
|
||
if(!is_otg_enabled) { | ||
radio_device_loader_power_on(); | ||
} | ||
|
||
const SubGhzDevice* device = subghz_devices_get_by_name(name); | ||
if(device) { | ||
is_connect = subghz_devices_is_connect(device); | ||
} | ||
|
||
if(!is_otg_enabled) { | ||
radio_device_loader_power_off(); | ||
} | ||
return is_connect; | ||
} | ||
|
||
const SubGhzDevice* radio_device_loader_set( | ||
const SubGhzDevice* current_radio_device, | ||
SubGhzRadioDeviceType radio_device_type) { | ||
const SubGhzDevice* radio_device; | ||
|
||
if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 && | ||
radio_device_loader_is_connect_external(SUBGHZ_DEVICE_CC1101_EXT_NAME)) { | ||
radio_device_loader_power_on(); | ||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME); | ||
subghz_devices_begin(radio_device); | ||
} else if(current_radio_device == NULL) { | ||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME); | ||
} else { | ||
radio_device_loader_end(current_radio_device); | ||
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME); | ||
} | ||
|
||
return radio_device; | ||
} | ||
|
||
bool radio_device_loader_is_external(const SubGhzDevice* radio_device) { | ||
furi_assert(radio_device); | ||
return (radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME)); | ||
} | ||
|
||
void radio_device_loader_end(const SubGhzDevice* radio_device) { | ||
furi_assert(radio_device); | ||
radio_device_loader_power_off(); | ||
if(radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME)) { | ||
subghz_devices_end(radio_device); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
applications/external/weather_station/helpers/radio_device_loader.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <lib/subghz/devices/devices.h> | ||
|
||
/** SubGhzRadioDeviceType */ | ||
typedef enum { | ||
SubGhzRadioDeviceTypeInternal, | ||
SubGhzRadioDeviceTypeExternalCC1101, | ||
} SubGhzRadioDeviceType; | ||
|
||
const SubGhzDevice* radio_device_loader_set( | ||
const SubGhzDevice* current_radio_device, | ||
SubGhzRadioDeviceType radio_device_type); | ||
|
||
bool radio_device_loader_is_external(const SubGhzDevice* radio_device); | ||
|
||
void radio_device_loader_end(const SubGhzDevice* radio_device); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters