flipperzero-firmware/lib/subghz/transmitter.c
Skorpionm 9a9abd59e9
[FL-2904, FL-2900, FL-2890] WS: add app WeatherStation (#1833)
* WeatherStation: start
* SubGhz: rename protocol magellen -> magellan
* WeatherStation: err Unresolved symbols: {'subghz_protocol_decoder_base_get_string'}
* WeatherStation: fix Unresolved symbols: {'subghz_protocol_decoder_base_get_string'}
* Subghz: add set protocol_items
* WeatherStation: adding your protocols
* WS: add Infactory protocol
* WS: add history
* WS: add setting
* WS: add lock
* WS: add hopper frequency
* WS: fix history
* WS fix string_t -> FuriString*
* WS: add images
* WS: history record update when receiving data from the sensor again
* WS: add receiver info, delete extra code
* WS: add protocol ThermoPRO_TX4
* [FL-2900] SubGhz: Move icons in Sub-GHz
* WS: add Notification
* [FL-2890] SubGhz: Rename *_user files in resources to _user.example
* WS: add about scene
* WS: removing redundant code
* WS: add  protocol Nexus-TH
* WS: add protocol GT_WT03
* WS: fix notification and rename "Weather Station" -> "Read Weather Station"
* SubGhz: partial unit tests fix
* SubGhz: fix unit_test
* SubGhz: remove dead code
* SubGhz: rename SubGhzPresetDefinition into SubGhzRadioPreset, cleanup subghz types.

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-10-20 02:27:26 +09:00

65 lines
2.1 KiB
C

#include "transmitter.h"
#include "protocols/base.h"
#include "registry.h"
#include "protocols/protocol_items.h"
struct SubGhzTransmitter {
const SubGhzProtocol* protocol;
SubGhzProtocolEncoderBase* protocol_instance;
};
SubGhzTransmitter*
subghz_transmitter_alloc_init(SubGhzEnvironment* environment, const char* protocol_name) {
SubGhzTransmitter* instance = NULL;
const SubGhzProtocolRegistry* protocol_registry_items =
subghz_environment_get_protocol_registry(environment);
const SubGhzProtocol* protocol =
subghz_protocol_registry_get_by_name(protocol_registry_items, protocol_name);
if(protocol && protocol->encoder && protocol->encoder->alloc) {
instance = malloc(sizeof(SubGhzTransmitter));
instance->protocol = protocol;
instance->protocol_instance = instance->protocol->encoder->alloc(environment);
}
return instance;
}
void subghz_transmitter_free(SubGhzTransmitter* instance) {
furi_assert(instance);
instance->protocol->encoder->free(instance->protocol_instance);
free(instance);
}
SubGhzProtocolEncoderBase* subghz_transmitter_get_protocol_instance(SubGhzTransmitter* instance) {
furi_assert(instance);
return instance->protocol_instance;
}
bool subghz_transmitter_stop(SubGhzTransmitter* instance) {
furi_assert(instance);
bool ret = false;
if(instance->protocol && instance->protocol->encoder && instance->protocol->encoder->stop) {
instance->protocol->encoder->stop(instance->protocol_instance);
ret = true;
}
return ret;
}
bool subghz_transmitter_deserialize(SubGhzTransmitter* instance, FlipperFormat* flipper_format) {
furi_assert(instance);
bool ret = false;
if(instance->protocol && instance->protocol->encoder &&
instance->protocol->encoder->deserialize) {
ret =
instance->protocol->encoder->deserialize(instance->protocol_instance, flipper_format);
}
return ret;
}
LevelDuration subghz_transmitter_yield(void* context) {
SubGhzTransmitter* instance = context;
return instance->protocol->encoder->yield(instance->protocol_instance);
}