Merge remote-tracking branch 'priv_dark/cc1101_ext' into cc1101_ext_protoview
27
CHANGELOG.md
|
@ -1,5 +1,32 @@
|
|||
## New changes
|
||||
* SubGHz: Keeloq: Centurion Nova read and emulate support (+ add manually)
|
||||
* SubGHz: FAAC SLH - UI Fixes, Fix sending signals with no seed
|
||||
* SubGHz: Code cleanup, proper handling of protocols ignore options (by @gid9798 | PR #516)
|
||||
* SubGHz: Various UI fixes (by @wosk | PR #527)
|
||||
* NFC: Fixed issue #532 (Mifare classic user dict - delete removes more than selected key)
|
||||
* Infrared: Updated universal remote assets (by @amec0e | PR #529)
|
||||
* Plugins: Use correct categories for all plugins (extra pack too)
|
||||
* Plugins: Various fixes for uFBT (by @hedger)
|
||||
* Plugins: Added **NFC Maker** plugin (make tags with URLs, Wifi and other things) [(by Willy-JL)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/external/nfc_maker)
|
||||
* Plugins: Added JetPack Joyride [(by timstrasser)](https://github.com/timstrasser)
|
||||
* Plugins: Moved Barcode Generator [(by Kingal1337)](https://github.com/Kingal1337/flipper-barcode-generator) from extra pack into base fw, old barcode generator was removed
|
||||
* Plugins: Updated ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-wifi-marauder)
|
||||
* Plugins: Updated i2c Tools [(by NaejEL)](https://github.com/NaejEL/flipperzero-i2ctools)
|
||||
* Settings: Change LED and volume settings by 5% steps (by @cokyrain)
|
||||
* BLE: BadBT fixes and furi_hal_bt cleanup (by @Willy-JL)
|
||||
* WIP OFW PR 2825: NFC: Improved MFC emulation on some readers (by AloneLiberty)
|
||||
* OFW PR 2829: Decode only supported Oregon 3 sensor (by @wosk)
|
||||
* OFW PR: Update OFW PR 2782
|
||||
* OFW: SubGhz: add "SubGhz test" external application and the ability to work "SubGhz" as an external application
|
||||
* OFW: API: explicitly add math.h
|
||||
* OFW: NFC: Mf Ultralight emulation optimization
|
||||
* OFW: Furi_Power: fix furi_hal_power_enable_otg
|
||||
* OFW: FuriHal: allow nulling null isr
|
||||
* OFW: FuriHal, Infrared, Protobuf: various fixes and improvements
|
||||
* OFW: Picopass fix ice
|
||||
* OFW: Desktop settings: show icon and name for external applications
|
||||
* OFW: Furi,FuriHal: various improvements
|
||||
* OFW: Debug apps: speaker, uart_echo with baudrate
|
||||
* OFW: Add Mitsubishi MSZ-AP25VGK universal ac remote
|
||||
* OFW: Fix roll-over in file browser and archive
|
||||
* OFW: Fix fr-FR-mac keylayout
|
||||
|
|
|
@ -93,6 +93,7 @@ Encoders or sending made by @xMasterX:
|
|||
- Keeloq: Stilmatic
|
||||
- Keeloq: CAME Space
|
||||
- Keeloq: Aprimatic (model TR and similar)
|
||||
- Keeloq: Centurion Nova (thanks Carlos !)
|
||||
|
||||
Encoders or sending made by @Eng1n33r(first implementation in Q2 2022) & @xMasterX (current version):
|
||||
- CAME Atomo -> Update! check out new [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md)
|
||||
|
@ -144,7 +145,7 @@ You can support us by using links or addresses below:
|
|||
- WiFi Scanner plugin [(by SequoiaSan)](https://github.com/SequoiaSan/FlipperZero-WiFi-Scanner_Module)
|
||||
- MultiConverter plugin [(by theisolinearchip)](https://github.com/theisolinearchip/flipperzero_stuff)
|
||||
- WAV Player [(OFW: DrZlo13)](https://github.com/flipperdevices/flipperzero-firmware/tree/zlo/wav-player) - Fixed and improved by [LTVA1](https://github.com/LTVA1/wav_player) -> Also outputs audio on `PA6` - `3(A6)` pin
|
||||
- Barcode generator plugin [(original by McAzzaMan)](https://github.com/McAzzaMan/flipperzero-firmware/tree/UPC-A_Barcode_Generator/applications/barcode_generator) - [EAN-8 and refactoring](https://github.com/DarkFlippers/unleashed-firmware/pull/154) by @msvsergey
|
||||
- Barcode Generator [(by Kingal1337)](https://github.com/Kingal1337/flipper-barcode-generator)
|
||||
- GPIO: Sentry Safe plugin [(by H4ckd4ddy)](https://github.com/H4ckd4ddy/flipperzero-sentry-safe-plugin)
|
||||
- ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-wifi-marauder) - Saving .pcap on flipper microSD [by tcpassos](https://github.com/tcpassos/flipperzero-firmware-with-wifi-marauder-companion) -> Only with custom marauder build (It is necessary to uncomment "#define WRITE_PACKETS_SERIAL" in configs.h (in marauder fw) and compile the firmware for the wifi board.) Or download precompiled build -> [Download esp32_marauder_ver_flipper_sd_serial.bin](https://github.com/justcallmekoko/ESP32Marauder/releases/latest)
|
||||
- NRF24: Sniffer & MouseJacker (with changes) [(by mothball187)](https://github.com/mothball187/flipperzero-nrf24/tree/main/mousejacker)
|
||||
|
@ -169,6 +170,7 @@ You can support us by using links or addresses below:
|
|||
- IR Scope [(by kallanreed)](https://github.com/DarkFlippers/unleashed-firmware/pull/407)
|
||||
- **BadBT** plugin (BT version of BadKB) [(by Willy-JL, ClaraCrazy, XFW contributors)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/main/bad_kb) (See in Applications->Tools) - (aka BadUSB via Bluetooth)
|
||||
- **Mifare Nested** [(by AloneLiberty)](https://github.com/AloneLiberty/FlipperNested) - Works with PC and python app `FlipperNested`
|
||||
- **NFC Maker** plugin (make tags with URLs, Wifi and other things) [(by Willy-JL)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/external/nfc_maker)
|
||||
|
||||
Games:
|
||||
- DOOM (fixed) [(by p4nic4ttack)](https://github.com/p4nic4ttack/doom-flipper-zero/)
|
||||
|
@ -184,6 +186,7 @@ Games:
|
|||
- BlackJack [(by teeebor)](https://github.com/teeebor/flipper_games)
|
||||
- 2048 game [(by eugene-kirzhanov)](https://github.com/eugene-kirzhanov/flipper-zero-2048-game)
|
||||
- Bomberduck [(by leo-need-more-coffee)](https://github.com/leo-need-more-coffee/flipperzero-bomberduck)
|
||||
- JetPack Joyride [(by timstrasser)](https://github.com/timstrasser)
|
||||
|
||||
|
||||
# Instructions
|
||||
|
|
14
applications/debug/subghz_test/application.fam
Normal file
|
@ -0,0 +1,14 @@
|
|||
App(
|
||||
appid="subghz_test",
|
||||
name="Sub-Ghz test",
|
||||
apptype=FlipperAppType.DEBUG,
|
||||
targets=["f7"],
|
||||
entry_point="subghz_test_app",
|
||||
requires=["gui"],
|
||||
stack_size=4 * 1024,
|
||||
order=50,
|
||||
fap_icon="subghz_test_10px.png",
|
||||
fap_category="Debug",
|
||||
fap_icon_assets="images",
|
||||
fap_version="0.1",
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
//SubGhzTestCustomEvent
|
||||
SubGhzTestCustomEventStartId = 100,
|
||||
SubGhzTestCustomEventSceneShowOnlyRX,
|
||||
} SubGhzTestCustomEvent;
|
|
@ -1,4 +1,4 @@
|
|||
#include "subghz_testing.h"
|
||||
#include "subghz_test_frequency.h"
|
||||
|
||||
const uint32_t subghz_frequencies_testing[] = {
|
||||
/* 300 - 348 */
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include "../subghz_i.h"
|
||||
#include "../subghz_test_app_i.h"
|
||||
|
||||
extern const uint32_t subghz_frequencies_testing[];
|
||||
extern const uint32_t subghz_frequencies_count_testing;
|
18
applications/debug/subghz_test/helpers/subghz_test_types.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define SUBGHZ_TEST_VERSION_APP "0.1"
|
||||
#define SUBGHZ_TEST_DEVELOPED "SkorP"
|
||||
#define SUBGHZ_TEST_GITHUB "https://github.com/flipperdevices/flipperzero-firmware"
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestViewVariableItemList,
|
||||
SubGhzTestViewSubmenu,
|
||||
SubGhzTestViewStatic,
|
||||
SubGhzTestViewCarrier,
|
||||
SubGhzTestViewPacket,
|
||||
SubGhzTestViewWidget,
|
||||
SubGhzTestViewPopup,
|
||||
} SubGhzTestView;
|
BIN
applications/debug/subghz_test/images/DolphinCommon_56x48.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
244
applications/debug/subghz_test/protocol/math.c
Normal file
|
@ -0,0 +1,244 @@
|
|||
#include "math.h"
|
||||
|
||||
uint64_t subghz_protocol_blocks_reverse_key(uint64_t key, uint8_t bit_count) {
|
||||
uint64_t reverse_key = 0;
|
||||
for(uint8_t i = 0; i < bit_count; i++) {
|
||||
reverse_key = reverse_key << 1 | bit_read(key, i);
|
||||
}
|
||||
return reverse_key;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_get_parity(uint64_t key, uint8_t bit_count) {
|
||||
uint8_t parity = 0;
|
||||
for(uint8_t i = 0; i < bit_count; i++) {
|
||||
parity += bit_read(key, i);
|
||||
}
|
||||
return parity & 0x01;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_crc4(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t polynomial,
|
||||
uint8_t init) {
|
||||
uint8_t remainder = init << 4; // LSBs are unused
|
||||
uint8_t poly = polynomial << 4;
|
||||
uint8_t bit;
|
||||
|
||||
while(size--) {
|
||||
remainder ^= *message++;
|
||||
for(bit = 0; bit < 8; bit++) {
|
||||
if(remainder & 0x80) {
|
||||
remainder = (remainder << 1) ^ poly;
|
||||
} else {
|
||||
remainder = (remainder << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return remainder >> 4 & 0x0f; // discard the LSBs
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_crc7(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t polynomial,
|
||||
uint8_t init) {
|
||||
uint8_t remainder = init << 1; // LSB is unused
|
||||
uint8_t poly = polynomial << 1;
|
||||
|
||||
for(size_t byte = 0; byte < size; ++byte) {
|
||||
remainder ^= message[byte];
|
||||
for(uint8_t bit = 0; bit < 8; ++bit) {
|
||||
if(remainder & 0x80) {
|
||||
remainder = (remainder << 1) ^ poly;
|
||||
} else {
|
||||
remainder = (remainder << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return remainder >> 1 & 0x7f; // discard the LSB
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_crc8(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t polynomial,
|
||||
uint8_t init) {
|
||||
uint8_t remainder = init;
|
||||
|
||||
for(size_t byte = 0; byte < size; ++byte) {
|
||||
remainder ^= message[byte];
|
||||
for(uint8_t bit = 0; bit < 8; ++bit) {
|
||||
if(remainder & 0x80) {
|
||||
remainder = (remainder << 1) ^ polynomial;
|
||||
} else {
|
||||
remainder = (remainder << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return remainder;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_crc8le(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t polynomial,
|
||||
uint8_t init) {
|
||||
uint8_t remainder = subghz_protocol_blocks_reverse_key(init, 8);
|
||||
polynomial = subghz_protocol_blocks_reverse_key(polynomial, 8);
|
||||
|
||||
for(size_t byte = 0; byte < size; ++byte) {
|
||||
remainder ^= message[byte];
|
||||
for(uint8_t bit = 0; bit < 8; ++bit) {
|
||||
if(remainder & 1) {
|
||||
remainder = (remainder >> 1) ^ polynomial;
|
||||
} else {
|
||||
remainder = (remainder >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return remainder;
|
||||
}
|
||||
|
||||
uint16_t subghz_protocol_blocks_crc16lsb(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint16_t polynomial,
|
||||
uint16_t init) {
|
||||
uint16_t remainder = init;
|
||||
|
||||
for(size_t byte = 0; byte < size; ++byte) {
|
||||
remainder ^= message[byte];
|
||||
for(uint8_t bit = 0; bit < 8; ++bit) {
|
||||
if(remainder & 1) {
|
||||
remainder = (remainder >> 1) ^ polynomial;
|
||||
} else {
|
||||
remainder = (remainder >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return remainder;
|
||||
}
|
||||
|
||||
uint16_t subghz_protocol_blocks_crc16(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint16_t polynomial,
|
||||
uint16_t init) {
|
||||
uint16_t remainder = init;
|
||||
|
||||
for(size_t byte = 0; byte < size; ++byte) {
|
||||
remainder ^= message[byte] << 8;
|
||||
for(uint8_t bit = 0; bit < 8; ++bit) {
|
||||
if(remainder & 0x8000) {
|
||||
remainder = (remainder << 1) ^ polynomial;
|
||||
} else {
|
||||
remainder = (remainder << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return remainder;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_lfsr_digest8(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t gen,
|
||||
uint8_t key) {
|
||||
uint8_t sum = 0;
|
||||
for(size_t byte = 0; byte < size; ++byte) {
|
||||
uint8_t data = message[byte];
|
||||
for(int i = 7; i >= 0; --i) {
|
||||
// XOR key into sum if data bit is set
|
||||
if((data >> i) & 1) sum ^= key;
|
||||
|
||||
// roll the key right (actually the LSB is dropped here)
|
||||
// and apply the gen (needs to include the dropped LSB as MSB)
|
||||
if(key & 1)
|
||||
key = (key >> 1) ^ gen;
|
||||
else
|
||||
key = (key >> 1);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_lfsr_digest8_reflect(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t gen,
|
||||
uint8_t key) {
|
||||
uint8_t sum = 0;
|
||||
// Process message from last byte to first byte (reflected)
|
||||
for(int byte = size - 1; byte >= 0; --byte) {
|
||||
uint8_t data = message[byte];
|
||||
// Process individual bits of each byte (reflected)
|
||||
for(uint8_t i = 0; i < 8; ++i) {
|
||||
// XOR key into sum if data bit is set
|
||||
if((data >> i) & 1) {
|
||||
sum ^= key;
|
||||
}
|
||||
|
||||
// roll the key left (actually the LSB is dropped here)
|
||||
// and apply the gen (needs to include the dropped lsb as MSB)
|
||||
if(key & 0x80)
|
||||
key = (key << 1) ^ gen;
|
||||
else
|
||||
key = (key << 1);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
uint16_t subghz_protocol_blocks_lfsr_digest16(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint16_t gen,
|
||||
uint16_t key) {
|
||||
uint16_t sum = 0;
|
||||
for(size_t byte = 0; byte < size; ++byte) {
|
||||
uint8_t data = message[byte];
|
||||
for(int8_t i = 7; i >= 0; --i) {
|
||||
// if data bit is set then xor with key
|
||||
if((data >> i) & 1) sum ^= key;
|
||||
|
||||
// roll the key right (actually the LSB is dropped here)
|
||||
// and apply the gen (needs to include the dropped LSB as MSB)
|
||||
if(key & 1)
|
||||
key = (key >> 1) ^ gen;
|
||||
else
|
||||
key = (key >> 1);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_add_bytes(uint8_t const message[], size_t size) {
|
||||
uint32_t result = 0;
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
result += message[i];
|
||||
}
|
||||
return (uint8_t)result;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_parity8(uint8_t byte) {
|
||||
byte ^= byte >> 4;
|
||||
byte &= 0xf;
|
||||
return (0x6996 >> byte) & 1;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_parity_bytes(uint8_t const message[], size_t size) {
|
||||
uint8_t result = 0;
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
result ^= subghz_protocol_blocks_parity8(message[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_blocks_xor_bytes(uint8_t const message[], size_t size) {
|
||||
uint8_t result = 0;
|
||||
for(size_t i = 0; i < size; ++i) {
|
||||
result ^= message[i];
|
||||
}
|
||||
return result;
|
||||
}
|
222
applications/debug/subghz_test/protocol/math.h
Normal file
|
@ -0,0 +1,222 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define bit_read(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bit_set(value, bit) \
|
||||
({ \
|
||||
__typeof__(value) _one = (1); \
|
||||
(value) |= (_one << (bit)); \
|
||||
})
|
||||
#define bit_clear(value, bit) \
|
||||
({ \
|
||||
__typeof__(value) _one = (1); \
|
||||
(value) &= ~(_one << (bit)); \
|
||||
})
|
||||
#define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit))
|
||||
#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Flip the data bitwise
|
||||
*
|
||||
* @param key In data
|
||||
* @param bit_count number of data bits
|
||||
*
|
||||
* @return Reverse data
|
||||
*/
|
||||
uint64_t subghz_protocol_blocks_reverse_key(uint64_t key, uint8_t bit_count);
|
||||
|
||||
/** Get parity the data bitwise
|
||||
*
|
||||
* @param key In data
|
||||
* @param bit_count number of data bits
|
||||
*
|
||||
* @return parity
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_get_parity(uint64_t key, uint8_t bit_count);
|
||||
|
||||
/** CRC-4
|
||||
*
|
||||
* @param message array of bytes to check
|
||||
* @param size number of bytes in message
|
||||
* @param polynomial CRC polynomial
|
||||
* @param init starting crc value
|
||||
*
|
||||
* @return CRC value
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_crc4(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t polynomial,
|
||||
uint8_t init);
|
||||
|
||||
/** CRC-7
|
||||
*
|
||||
* @param message array of bytes to check
|
||||
* @param size number of bytes in message
|
||||
* @param polynomial CRC polynomial
|
||||
* @param init starting crc value
|
||||
*
|
||||
* @return CRC value
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_crc7(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t polynomial,
|
||||
uint8_t init);
|
||||
|
||||
/** Generic Cyclic Redundancy Check CRC-8. Example polynomial: 0x31 = x8 + x5 +
|
||||
* x4 + 1 (x8 is implicit) Example polynomial: 0x80 = x8 + x7 (a normal
|
||||
* bit-by-bit parity XOR)
|
||||
*
|
||||
* @param message array of bytes to check
|
||||
* @param size number of bytes in message
|
||||
* @param polynomial byte is from x^7 to x^0 (x^8 is implicitly one)
|
||||
* @param init starting crc value
|
||||
*
|
||||
* @return CRC value
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_crc8(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t polynomial,
|
||||
uint8_t init);
|
||||
|
||||
/** "Little-endian" Cyclic Redundancy Check CRC-8 LE Input and output are
|
||||
* reflected, i.e. least significant bit is shifted in first
|
||||
*
|
||||
* @param message array of bytes to check
|
||||
* @param size number of bytes in message
|
||||
* @param polynomial CRC polynomial
|
||||
* @param init starting crc value
|
||||
*
|
||||
* @return CRC value
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_crc8le(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t polynomial,
|
||||
uint8_t init);
|
||||
|
||||
/** CRC-16 LSB. Input and output are reflected, i.e. least significant bit is
|
||||
* shifted in first. Note that poly and init already need to be reflected
|
||||
*
|
||||
* @param message array of bytes to check
|
||||
* @param size number of bytes in message
|
||||
* @param polynomial CRC polynomial
|
||||
* @param init starting crc value
|
||||
*
|
||||
* @return CRC value
|
||||
*/
|
||||
uint16_t subghz_protocol_blocks_crc16lsb(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint16_t polynomial,
|
||||
uint16_t init);
|
||||
|
||||
/** CRC-16
|
||||
*
|
||||
* @param message array of bytes to check
|
||||
* @param size number of bytes in message
|
||||
* @param polynomial CRC polynomial
|
||||
* @param init starting crc value
|
||||
*
|
||||
* @return CRC value
|
||||
*/
|
||||
uint16_t subghz_protocol_blocks_crc16(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint16_t polynomial,
|
||||
uint16_t init);
|
||||
|
||||
/** Digest-8 by "LFSR-based Toeplitz hash"
|
||||
*
|
||||
* @param message bytes of message data
|
||||
* @param size number of bytes to digest
|
||||
* @param gen key stream generator, needs to includes the MSB if the
|
||||
* LFSR is rolling
|
||||
* @param key initial key
|
||||
*
|
||||
* @return digest value
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_lfsr_digest8(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t gen,
|
||||
uint8_t key);
|
||||
|
||||
/** Digest-8 by "LFSR-based Toeplitz hash", byte reflect, bit reflect
|
||||
*
|
||||
* @param message bytes of message data
|
||||
* @param size number of bytes to digest
|
||||
* @param gen key stream generator, needs to includes the MSB if the
|
||||
* LFSR is rolling
|
||||
* @param key initial key
|
||||
*
|
||||
* @return digest value
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_lfsr_digest8_reflect(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint8_t gen,
|
||||
uint8_t key);
|
||||
|
||||
/** Digest-16 by "LFSR-based Toeplitz hash"
|
||||
*
|
||||
* @param message bytes of message data
|
||||
* @param size number of bytes to digest
|
||||
* @param gen key stream generator, needs to includes the MSB if the
|
||||
* LFSR is rolling
|
||||
* @param key initial key
|
||||
*
|
||||
* @return digest value
|
||||
*/
|
||||
uint16_t subghz_protocol_blocks_lfsr_digest16(
|
||||
uint8_t const message[],
|
||||
size_t size,
|
||||
uint16_t gen,
|
||||
uint16_t key);
|
||||
|
||||
/** Compute Addition of a number of bytes
|
||||
*
|
||||
* @param message bytes of message data
|
||||
* @param size number of bytes to sum
|
||||
*
|
||||
* @return summation value
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_add_bytes(uint8_t const message[], size_t size);
|
||||
|
||||
/** Compute bit parity of a single byte (8 bits)
|
||||
*
|
||||
* @param byte single byte to check
|
||||
*
|
||||
* @return 1 odd parity, 0 even parity
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_parity8(uint8_t byte);
|
||||
|
||||
/** Compute bit parity of a number of bytes
|
||||
*
|
||||
* @param message bytes of message data
|
||||
* @param size number of bytes to sum
|
||||
*
|
||||
* @return 1 odd parity, 0 even parity
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_parity_bytes(uint8_t const message[], size_t size);
|
||||
|
||||
/** Compute XOR (byte-wide parity) of a number of bytes
|
||||
*
|
||||
* @param message bytes of message data
|
||||
* @param size number of bytes to sum
|
||||
*
|
||||
* @return summation value, per bit-position 1 odd parity, 0 even parity
|
||||
*/
|
||||
uint8_t subghz_protocol_blocks_xor_bytes(uint8_t const message[], size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
#include "princeton_for_testing.h"
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include "../blocks/math.h"
|
||||
#include "math.h"
|
||||
|
||||
/*
|
||||
* Help
|
|
@ -1,6 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
//#include "base.h"
|
||||
#include <furi.h>
|
||||
#include <lib/toolbox/level_duration.h>
|
||||
|
||||
/** SubGhzDecoderPrinceton anonymous type */
|
||||
typedef struct SubGhzDecoderPrinceton SubGhzDecoderPrinceton;
|
30
applications/debug/subghz_test/scenes/subghz_test_scene.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "../subghz_test_app_i.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const subghz_test_scene_on_enter_handlers[])(void*) = {
|
||||
#include "subghz_test_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const subghz_test_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "subghz_test_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const subghz_test_scene_on_exit_handlers[])(void* context) = {
|
||||
#include "subghz_test_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers subghz_test_scene_handlers = {
|
||||
.on_enter_handlers = subghz_test_scene_on_enter_handlers,
|
||||
.on_event_handlers = subghz_test_scene_on_event_handlers,
|
||||
.on_exit_handlers = subghz_test_scene_on_exit_handlers,
|
||||
.scene_num = SubGhzTestSceneNum,
|
||||
};
|
29
applications/debug/subghz_test/scenes/subghz_test_scene.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) SubGhzTestScene##id,
|
||||
typedef enum {
|
||||
#include "subghz_test_scene_config.h"
|
||||
SubGhzTestSceneNum,
|
||||
} SubGhzTestScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers subghz_test_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "subghz_test_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "subghz_test_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "subghz_test_scene_config.h"
|
||||
#undef ADD_SCENE
|
|
@ -0,0 +1,66 @@
|
|||
#include "../subghz_test_app_i.h"
|
||||
|
||||
void subghz_test_scene_about_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_test_scene_about_on_enter(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
furi_string_printf(temp_str, "\e#%s\n", "Information");
|
||||
|
||||
furi_string_cat_printf(temp_str, "Version: %s\n", SUBGHZ_TEST_VERSION_APP);
|
||||
furi_string_cat_printf(temp_str, "Developed by: %s\n", SUBGHZ_TEST_DEVELOPED);
|
||||
furi_string_cat_printf(temp_str, "Github: %s\n\n", SUBGHZ_TEST_GITHUB);
|
||||
|
||||
furi_string_cat_printf(temp_str, "\e#%s\n", "Description");
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"This application is designed\nto test the functionality of the\nbuilt-in CC1101 module.\n\n");
|
||||
|
||||
widget_add_text_box_element(
|
||||
app->widget,
|
||||
0,
|
||||
0,
|
||||
128,
|
||||
14,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
"\e#\e! \e!\n",
|
||||
false);
|
||||
widget_add_text_box_element(
|
||||
app->widget,
|
||||
0,
|
||||
2,
|
||||
128,
|
||||
14,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
"\e#\e! Sub-Ghz Test \e!\n",
|
||||
false);
|
||||
widget_add_text_scroll_element(app->widget, 0, 16, 128, 50, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewWidget);
|
||||
}
|
||||
|
||||
bool subghz_test_scene_about_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhzTestApp* app = context;
|
||||
bool consumed = false;
|
||||
UNUSED(app);
|
||||
UNUSED(event);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void subghz_test_scene_about_on_exit(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
|
||||
// Clear views
|
||||
widget_reset(app->widget);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#include "../subghz_test_app_i.h"
|
||||
|
||||
void subghz_test_scene_carrier_callback(SubGhzTestCarrierEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_test_scene_carrier_on_enter(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
subghz_test_carrier_set_callback(
|
||||
app->subghz_test_carrier, subghz_test_scene_carrier_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewCarrier);
|
||||
}
|
||||
|
||||
bool subghz_test_scene_carrier_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhzTestApp* app = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzTestCarrierEventOnlyRx) {
|
||||
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneShowOnlyRx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_test_scene_carrier_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
ADD_SCENE(subghz_test, start, Start)
|
||||
ADD_SCENE(subghz_test, about, About)
|
||||
ADD_SCENE(subghz_test, carrier, Carrier)
|
||||
ADD_SCENE(subghz_test, packet, Packet)
|
||||
ADD_SCENE(subghz_test, static, Static)
|
||||
ADD_SCENE(subghz_test, show_only_rx, ShowOnlyRx)
|
|
@ -0,0 +1,29 @@
|
|||
#include "../subghz_test_app_i.h"
|
||||
|
||||
void subghz_test_scene_packet_callback(SubGhzTestPacketEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_test_scene_packet_on_enter(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
subghz_test_packet_set_callback(
|
||||
app->subghz_test_packet, subghz_test_scene_packet_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewPacket);
|
||||
}
|
||||
|
||||
bool subghz_test_scene_packet_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhzTestApp* app = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzTestPacketEventOnlyRx) {
|
||||
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneShowOnlyRx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_test_scene_packet_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
#include "../subghz_test_app_i.h"
|
||||
#include <subghz_test_icons.h>
|
||||
|
||||
void subghz_test_scene_show_only_rx_popup_callback(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, SubGhzTestCustomEventSceneShowOnlyRX);
|
||||
}
|
||||
|
||||
void subghz_test_scene_show_only_rx_on_enter(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = app->popup;
|
||||
|
||||
const char* header_text = "Transmission is blocked";
|
||||
const char* message_text = "Transmission on\nthis frequency is\nrestricted in\nyour region";
|
||||
if(!furi_hal_region_is_provisioned()) {
|
||||
header_text = "Firmware update needed";
|
||||
message_text = "Please update\nfirmware before\nusing this feature\nflipp.dev/upd";
|
||||
}
|
||||
|
||||
popup_set_header(popup, header_text, 63, 3, AlignCenter, AlignTop);
|
||||
popup_set_text(popup, message_text, 0, 17, AlignLeft, AlignTop);
|
||||
popup_set_icon(popup, 72, 17, &I_DolphinCommon_56x48);
|
||||
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_callback(popup, subghz_test_scene_show_only_rx_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewPopup);
|
||||
}
|
||||
|
||||
bool subghz_test_scene_show_only_rx_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhzTestApp* app = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzTestCustomEventSceneShowOnlyRX) {
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_test_scene_show_only_rx_on_exit(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
Popup* popup = app->popup;
|
||||
|
||||
popup_reset(popup);
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
#include "../subghz_test_app_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexSubGhzTestCarrier,
|
||||
SubmenuIndexSubGhzTestPacket,
|
||||
SubmenuIndexSubGhzTestStatic,
|
||||
SubmenuIndexSubGhzTestAbout,
|
||||
} SubmenuIndex;
|
||||
|
||||
void subghz_test_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
SubGhzTestApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void subghz_test_scene_start_on_enter(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
Submenu* submenu = app->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Carrier",
|
||||
SubmenuIndexSubGhzTestCarrier,
|
||||
subghz_test_scene_start_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Packet",
|
||||
SubmenuIndexSubGhzTestPacket,
|
||||
subghz_test_scene_start_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Static",
|
||||
SubmenuIndexSubGhzTestStatic,
|
||||
subghz_test_scene_start_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"About",
|
||||
SubmenuIndexSubGhzTestAbout,
|
||||
subghz_test_scene_start_submenu_callback,
|
||||
app);
|
||||
|
||||
submenu_set_selected_item(
|
||||
submenu, scene_manager_get_scene_state(app->scene_manager, SubGhzTestSceneStart));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewSubmenu);
|
||||
}
|
||||
|
||||
bool subghz_test_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhzTestApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexSubGhzTestAbout) {
|
||||
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneAbout);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexSubGhzTestCarrier) {
|
||||
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneCarrier);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexSubGhzTestPacket) {
|
||||
scene_manager_next_scene(app->scene_manager, SubGhzTestScenePacket);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexSubGhzTestStatic) {
|
||||
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneStatic);
|
||||
consumed = true;
|
||||
}
|
||||
scene_manager_set_scene_state(app->scene_manager, SubGhzTestSceneStart, event.event);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void subghz_test_scene_start_on_exit(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
submenu_reset(app->submenu);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#include "../subghz_test_app_i.h"
|
||||
|
||||
void subghz_test_scene_static_callback(SubGhzTestStaticEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_test_scene_static_on_enter(void* context) {
|
||||
SubGhzTestApp* app = context;
|
||||
subghz_test_static_set_callback(
|
||||
app->subghz_test_static, subghz_test_scene_static_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewStatic);
|
||||
}
|
||||
|
||||
bool subghz_test_scene_static_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhzTestApp* app = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzTestStaticEventOnlyRx) {
|
||||
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneShowOnlyRx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_test_scene_static_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
BIN
applications/debug/subghz_test/subghz_test_10px.png
Normal file
After Width: | Height: | Size: 181 B |
139
applications/debug/subghz_test/subghz_test_app.c
Normal file
|
@ -0,0 +1,139 @@
|
|||
#include "subghz_test_app_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
static bool subghz_test_app_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
SubGhzTestApp* app = context;
|
||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||
}
|
||||
|
||||
static bool subghz_test_app_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestApp* app = context;
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
static void subghz_test_app_tick_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestApp* app = context;
|
||||
scene_manager_handle_tick_event(app->scene_manager);
|
||||
}
|
||||
|
||||
SubGhzTestApp* subghz_test_app_alloc() {
|
||||
SubGhzTestApp* app = malloc(sizeof(SubGhzTestApp));
|
||||
|
||||
// GUI
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
// View Dispatcher
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
app->scene_manager = scene_manager_alloc(&subghz_test_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
|
||||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
app->view_dispatcher, subghz_test_app_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
app->view_dispatcher, subghz_test_app_back_event_callback);
|
||||
view_dispatcher_set_tick_event_callback(
|
||||
app->view_dispatcher, subghz_test_app_tick_event_callback, 100);
|
||||
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
// Open Notification record
|
||||
app->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
// SubMenu
|
||||
app->submenu = submenu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, SubGhzTestViewSubmenu, submenu_get_view(app->submenu));
|
||||
|
||||
// Widget
|
||||
app->widget = widget_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, SubGhzTestViewWidget, widget_get_view(app->widget));
|
||||
|
||||
// Popup
|
||||
app->popup = popup_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, SubGhzTestViewPopup, popup_get_view(app->popup));
|
||||
|
||||
// Carrier Test Module
|
||||
app->subghz_test_carrier = subghz_test_carrier_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
SubGhzTestViewCarrier,
|
||||
subghz_test_carrier_get_view(app->subghz_test_carrier));
|
||||
|
||||
// Packet Test
|
||||
app->subghz_test_packet = subghz_test_packet_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
SubGhzTestViewPacket,
|
||||
subghz_test_packet_get_view(app->subghz_test_packet));
|
||||
|
||||
// Static send
|
||||
app->subghz_test_static = subghz_test_static_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
SubGhzTestViewStatic,
|
||||
subghz_test_static_get_view(app->subghz_test_static));
|
||||
|
||||
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneStart);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
void subghz_test_app_free(SubGhzTestApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewSubmenu);
|
||||
submenu_free(app->submenu);
|
||||
|
||||
// Widget
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewWidget);
|
||||
widget_free(app->widget);
|
||||
|
||||
// Popup
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewPopup);
|
||||
popup_free(app->popup);
|
||||
|
||||
// Carrier Test
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewCarrier);
|
||||
subghz_test_carrier_free(app->subghz_test_carrier);
|
||||
|
||||
// Packet Test
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewPacket);
|
||||
subghz_test_packet_free(app->subghz_test_packet);
|
||||
|
||||
// Static
|
||||
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewStatic);
|
||||
subghz_test_static_free(app->subghz_test_static);
|
||||
|
||||
// View dispatcher
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
scene_manager_free(app->scene_manager);
|
||||
|
||||
// Notifications
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
app->notifications = NULL;
|
||||
|
||||
// Close records
|
||||
furi_record_close(RECORD_GUI);
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
int32_t subghz_test_app(void* p) {
|
||||
UNUSED(p);
|
||||
SubGhzTestApp* subghz_test_app = subghz_test_app_alloc();
|
||||
|
||||
view_dispatcher_run(subghz_test_app->view_dispatcher);
|
||||
|
||||
subghz_test_app_free(subghz_test_app);
|
||||
|
||||
return 0;
|
||||
}
|
5
applications/debug/subghz_test/subghz_test_app_i.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "subghz_test_app_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "SubGhzTest"
|
32
applications/debug/subghz_test/subghz_test_app_i.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include "helpers/subghz_test_types.h"
|
||||
#include "helpers/subghz_test_event.h"
|
||||
|
||||
#include "scenes/subghz_test_scene.h"
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/widget.h>
|
||||
#include <gui/modules/popup.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include "views/subghz_test_static.h"
|
||||
#include "views/subghz_test_carrier.h"
|
||||
#include "views/subghz_test_packet.h"
|
||||
|
||||
typedef struct SubGhzTestApp SubGhzTestApp;
|
||||
|
||||
struct SubGhzTestApp {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
SceneManager* scene_manager;
|
||||
NotificationApp* notifications;
|
||||
Submenu* submenu;
|
||||
Widget* widget;
|
||||
Popup* popup;
|
||||
SubGhzTestStatic* subghz_test_static;
|
||||
SubGhzTestCarrier* subghz_test_carrier;
|
||||
SubGhzTestPacket* subghz_test_packet;
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
#include "subghz_test_carrier.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
#include "../subghz_test_app_i.h"
|
||||
#include "../helpers/subghz_test_frequency.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <math.h>
|
||||
|
@ -8,12 +8,11 @@
|
|||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
// TODO add external module
|
||||
|
||||
struct SubGhzTestCarrier {
|
||||
View* view;
|
||||
FuriTimer* timer;
|
||||
SubGhzTestCarrierCallback callback;
|
||||
// const SubGhzDevice* radio_device;
|
||||
void* context;
|
||||
};
|
||||
|
||||
|
@ -86,6 +85,7 @@ void subghz_test_carrier_draw(Canvas* canvas, SubGhzTestCarrierModel* model) {
|
|||
bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
// const SubGhzDevice* radio_device = subghz_test_carrier->radio_device;
|
||||
|
||||
if(event->key == InputKeyBack || event->type != InputTypeShort) {
|
||||
return false;
|
||||
|
@ -96,6 +96,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
furi_hal_subghz_idle();
|
||||
// subghz_devices_idle(radio_device);
|
||||
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->frequency > 0) model->frequency--;
|
||||
|
@ -116,10 +117,18 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
furi_hal_subghz_set_path(model->path);
|
||||
// model->real_frequency = subghz_devices_set_frequency(
|
||||
// radio_device, subghz_frequencies_testing[model->frequency]);
|
||||
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_rx();
|
||||
// furi_hal_gpio_init(
|
||||
// subghz_devices_get_data_gpio(radio_device),
|
||||
// GpioModeInput,
|
||||
// GpioPullNo,
|
||||
// GpioSpeedLow);
|
||||
// subghz_devices_set_rx(radio_device);
|
||||
} else {
|
||||
furi_hal_gpio_init(
|
||||
&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
@ -129,6 +138,15 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
subghz_test_carrier->callback(
|
||||
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
|
||||
}
|
||||
// if(!subghz_devices_set_tx(radio_device)) {
|
||||
// furi_hal_gpio_init(
|
||||
// subghz_devices_get_data_gpio(radio_device),
|
||||
// GpioModeInput,
|
||||
// GpioPullNo,
|
||||
// GpioSpeedLow);
|
||||
// subghz_test_carrier->callback(
|
||||
// SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
|
||||
// }
|
||||
}
|
||||
},
|
||||
true);
|
||||
|
@ -139,12 +157,20 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
|||
void subghz_test_carrier_enter(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
// furi_assert(subghz_test_carrier->radio_device);
|
||||
// const SubGhzDevice* radio_device = subghz_test_carrier->radio_device;
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
||||
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// subghz_devices_reset(radio_device);
|
||||
// subghz_devices_load_preset(radio_device, FuriHalSubGhzPresetOok650Async, NULL);
|
||||
|
||||
// furi_hal_gpio_init(
|
||||
// subghz_devices_get_data_gpio(radio_device), GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
|
@ -152,6 +178,8 @@ void subghz_test_carrier_enter(void* context) {
|
|||
model->frequency = subghz_frequencies_433_92_testing; // 433
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
// model->real_frequency = subghz_devices_set_frequency(
|
||||
// radio_device, subghz_frequencies_testing[model->frequency]);
|
||||
model->path = FuriHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubGhzTestCarrierModelStatusRx;
|
||||
|
@ -159,6 +187,7 @@ void subghz_test_carrier_enter(void* context) {
|
|||
true);
|
||||
|
||||
furi_hal_subghz_rx();
|
||||
// subghz_devices_set_rx(radio_device);
|
||||
|
||||
furi_timer_start(subghz_test_carrier->timer, furi_kernel_get_tick_frequency() / 4);
|
||||
}
|
||||
|
@ -171,6 +200,7 @@ void subghz_test_carrier_exit(void* context) {
|
|||
|
||||
// Reinitialize IC to default state
|
||||
furi_hal_subghz_sleep();
|
||||
// subghz_devices_sleep(subghz_test_carrier->radio_device);
|
||||
}
|
||||
|
||||
void subghz_test_carrier_rssi_timer_callback(void* context) {
|
||||
|
@ -183,6 +213,7 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
|
|||
{
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
// model->rssi = subghz_devices_get_rssi(subghz_test_carrier->radio_device);
|
||||
}
|
||||
},
|
||||
false);
|
||||
|
@ -218,3 +249,10 @@ View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier) {
|
|||
furi_assert(subghz_test_carrier);
|
||||
return subghz_test_carrier->view;
|
||||
}
|
||||
|
||||
// void subghz_test_carrier_set_radio(
|
||||
// SubGhzTestCarrier* subghz_test_carrier,
|
||||
// const SubGhzDevice* radio_device) {
|
||||
// furi_assert(subghz_test_carrier);
|
||||
// subghz_test_carrier->radio_device = radio_device;
|
||||
// }
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
// #include <lib/subghz/devices/devices.h>
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestCarrierEventOnlyRx,
|
||||
|
@ -20,3 +21,7 @@ SubGhzTestCarrier* subghz_test_carrier_alloc();
|
|||
void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier);
|
||||
|
||||
View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier);
|
||||
|
||||
// void subghz_test_carrier_set_radio(
|
||||
// SubGhzTestCarrier* subghz_test_carrier,
|
||||
// const SubGhzDevice* radio_device);
|
|
@ -1,6 +1,6 @@
|
|||
#include "subghz_test_packet.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
#include "../subghz_test_app_i.h"
|
||||
#include "../helpers/subghz_test_frequency.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <math.h>
|
||||
|
@ -8,7 +8,7 @@
|
|||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
#include <toolbox/level_duration.h>
|
||||
#include <lib/subghz/protocols/princeton_for_testing.h>
|
||||
#include "../protocol/princeton_for_testing.h"
|
||||
|
||||
#define SUBGHZ_TEST_PACKET_COUNT 500
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include "subghz_test_static.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
#include "../subghz_test_app_i.h"
|
||||
#include "../helpers/subghz_test_frequency.h"
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#include <math.h>
|
||||
|
@ -8,12 +8,10 @@
|
|||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <lib/subghz/protocols/princeton_for_testing.h>
|
||||
#include "../protocol/princeton_for_testing.h"
|
||||
|
||||
#define TAG "SubGhzTestStatic"
|
||||
|
||||
// TODO add external module
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestStaticStatusIDLE,
|
||||
SubGhzTestStaticStatusTX,
|
|
@ -425,6 +425,7 @@ MU_TEST(infrared_test_decoder_mixed) {
|
|||
infrared_test_run_decoder(InfraredProtocolSamsung32, 1);
|
||||
infrared_test_run_decoder(InfraredProtocolSIRC, 3);
|
||||
infrared_test_run_decoder(InfraredProtocolKaseikyo, 1);
|
||||
infrared_test_run_decoder(InfraredProtocolRCA, 1);
|
||||
}
|
||||
|
||||
MU_TEST(infrared_test_decoder_nec) {
|
||||
|
@ -499,6 +500,15 @@ MU_TEST(infrared_test_decoder_kaseikyo) {
|
|||
infrared_test_run_decoder(InfraredProtocolKaseikyo, 6);
|
||||
}
|
||||
|
||||
MU_TEST(infrared_test_decoder_rca) {
|
||||
infrared_test_run_decoder(InfraredProtocolRCA, 1);
|
||||
infrared_test_run_decoder(InfraredProtocolRCA, 2);
|
||||
infrared_test_run_decoder(InfraredProtocolRCA, 3);
|
||||
infrared_test_run_decoder(InfraredProtocolRCA, 4);
|
||||
infrared_test_run_decoder(InfraredProtocolRCA, 5);
|
||||
infrared_test_run_decoder(InfraredProtocolRCA, 6);
|
||||
}
|
||||
|
||||
MU_TEST(infrared_test_encoder_decoder_all) {
|
||||
infrared_test_run_encoder_decoder(InfraredProtocolNEC, 1);
|
||||
infrared_test_run_encoder_decoder(InfraredProtocolNECext, 1);
|
||||
|
@ -509,6 +519,7 @@ MU_TEST(infrared_test_encoder_decoder_all) {
|
|||
infrared_test_run_encoder_decoder(InfraredProtocolRC5, 1);
|
||||
infrared_test_run_encoder_decoder(InfraredProtocolSIRC, 1);
|
||||
infrared_test_run_encoder_decoder(InfraredProtocolKaseikyo, 1);
|
||||
infrared_test_run_encoder_decoder(InfraredProtocolRCA, 1);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(infrared_test) {
|
||||
|
@ -527,6 +538,7 @@ MU_TEST_SUITE(infrared_test) {
|
|||
MU_RUN_TEST(infrared_test_decoder_samsung32);
|
||||
MU_RUN_TEST(infrared_test_decoder_necext1);
|
||||
MU_RUN_TEST(infrared_test_decoder_kaseikyo);
|
||||
MU_RUN_TEST(infrared_test_decoder_rca);
|
||||
MU_RUN_TEST(infrared_test_decoder_mixed);
|
||||
MU_RUN_TEST(infrared_test_encoder_decoder_all);
|
||||
}
|
||||
|
|
|
@ -64,10 +64,11 @@ static inline void update_bt_timeout(Bt* bt) {
|
|||
}
|
||||
|
||||
typedef enum {
|
||||
WorkerEvtToggle = (1 << 0),
|
||||
WorkerEvtEnd = (1 << 1),
|
||||
WorkerEvtConnect = (1 << 2),
|
||||
WorkerEvtDisconnect = (1 << 3),
|
||||
WorkerEvtStartStop = (1 << 0),
|
||||
WorkerEvtPauseResume = (1 << 1),
|
||||
WorkerEvtEnd = (1 << 2),
|
||||
WorkerEvtConnect = (1 << 3),
|
||||
WorkerEvtDisconnect = (1 << 4),
|
||||
} WorkerEvtFlags;
|
||||
|
||||
static const char ducky_cmd_id[] = {"ID"};
|
||||
|
@ -280,6 +281,7 @@ static bool ducky_set_bt_id(BadBtScript* bad_bt, const char* line) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
furi_hal_bt_reverse_mac_addr(mac);
|
||||
|
||||
furi_hal_bt_set_profile_adv_name(FuriHalBtProfileHidKeyboard, line + mac_len);
|
||||
bt_set_profile_mac_address(bad_bt->bt, mac);
|
||||
|
@ -498,24 +500,26 @@ static int32_t bad_bt_worker(void* context) {
|
|||
|
||||
} else if(worker_state == BadBtStateNotConnected) { // State: Not connected
|
||||
uint32_t flags = bad_bt_flags_get(
|
||||
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle, FuriWaitForever);
|
||||
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtDisconnect | WorkerEvtStartStop,
|
||||
FuriWaitForever);
|
||||
|
||||
if(flags & WorkerEvtEnd) {
|
||||
break;
|
||||
} else if(flags & WorkerEvtConnect) {
|
||||
worker_state = BadBtStateIdle; // Ready to run
|
||||
} else if(flags & WorkerEvtToggle) {
|
||||
} else if(flags & WorkerEvtStartStop) {
|
||||
worker_state = BadBtStateWillRun; // Will run when connected
|
||||
}
|
||||
bad_bt->st.state = worker_state;
|
||||
|
||||
} else if(worker_state == BadBtStateIdle) { // State: ready to start
|
||||
uint32_t flags = bad_bt_flags_get(
|
||||
WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect, FuriWaitForever);
|
||||
WorkerEvtEnd | WorkerEvtStartStop | WorkerEvtConnect | WorkerEvtDisconnect,
|
||||
FuriWaitForever);
|
||||
|
||||
if(flags & WorkerEvtEnd) {
|
||||
break;
|
||||
} else if(flags & WorkerEvtToggle) { // Start executing script
|
||||
} else if(flags & WorkerEvtStartStop) { // Start executing script
|
||||
delay_val = 0;
|
||||
bad_bt->buf_len = 0;
|
||||
bad_bt->st.line_cur = 0;
|
||||
|
@ -534,7 +538,8 @@ static int32_t bad_bt_worker(void* context) {
|
|||
|
||||
} else if(worker_state == BadBtStateWillRun) { // State: start on connection
|
||||
uint32_t flags = bad_bt_flags_get(
|
||||
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle, FuriWaitForever);
|
||||
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtDisconnect | WorkerEvtStartStop,
|
||||
FuriWaitForever);
|
||||
|
||||
if(flags & WorkerEvtEnd) {
|
||||
break;
|
||||
|
@ -549,21 +554,21 @@ static int32_t bad_bt_worker(void* context) {
|
|||
storage_file_seek(script_file, 0, true);
|
||||
// extra time for PC to recognize Flipper as keyboard
|
||||
flags = furi_thread_flags_wait(
|
||||
WorkerEvtEnd | WorkerEvtDisconnect | WorkerEvtToggle,
|
||||
WorkerEvtEnd | WorkerEvtDisconnect | WorkerEvtStartStop,
|
||||
FuriFlagWaitAny | FuriFlagNoClear,
|
||||
1500);
|
||||
if(flags == (unsigned)FuriFlagErrorTimeout) {
|
||||
// If nothing happened - start script execution
|
||||
worker_state = BadBtStateRunning;
|
||||
} else if(flags & WorkerEvtToggle) {
|
||||
} else if(flags & WorkerEvtStartStop) {
|
||||
worker_state = BadBtStateIdle;
|
||||
furi_thread_flags_clear(WorkerEvtToggle);
|
||||
furi_thread_flags_clear(WorkerEvtStartStop);
|
||||
}
|
||||
|
||||
update_bt_timeout(bad_bt->bt);
|
||||
|
||||
bad_bt_script_set_keyboard_layout(bad_bt, bad_bt->keyboard_layout);
|
||||
} else if(flags & WorkerEvtToggle) { // Cancel scheduled execution
|
||||
} else if(flags & WorkerEvtStartStop) { // Cancel scheduled execution
|
||||
worker_state = BadBtStateNotConnected;
|
||||
}
|
||||
bad_bt->st.state = worker_state;
|
||||
|
@ -571,13 +576,15 @@ static int32_t bad_bt_worker(void* context) {
|
|||
} else if(worker_state == BadBtStateRunning) { // State: running
|
||||
uint16_t delay_cur = (delay_val > 1000) ? (1000) : (delay_val);
|
||||
uint32_t flags = furi_thread_flags_wait(
|
||||
WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect, FuriFlagWaitAny, delay_cur);
|
||||
WorkerEvtEnd | WorkerEvtStartStop | WorkerEvtConnect | WorkerEvtDisconnect,
|
||||
FuriFlagWaitAny,
|
||||
delay_cur);
|
||||
|
||||
delay_val -= delay_cur;
|
||||
if(!(flags & FuriFlagError)) {
|
||||
if(flags & WorkerEvtEnd) {
|
||||
break;
|
||||
} else if(flags & WorkerEvtToggle) {
|
||||
} else if(flags & WorkerEvtStartStop) {
|
||||
worker_state = BadBtStateIdle; // Stop executing script
|
||||
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
|
@ -630,11 +637,14 @@ static int32_t bad_bt_worker(void* context) {
|
|||
} else if(worker_state == BadBtStateWaitForBtn) { // State: Wait for button Press
|
||||
uint16_t delay_cur = (delay_val > 1000) ? (1000) : (delay_val);
|
||||
uint32_t flags = furi_thread_flags_wait(
|
||||
WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect, FuriFlagWaitAny, delay_cur);
|
||||
WorkerEvtEnd | WorkerEvtStartStop | WorkerEvtPauseResume | WorkerEvtConnect |
|
||||
WorkerEvtDisconnect,
|
||||
FuriFlagWaitAny,
|
||||
delay_cur);
|
||||
if(!(flags & FuriFlagError)) {
|
||||
if(flags & WorkerEvtEnd) {
|
||||
break;
|
||||
} else if(flags & WorkerEvtToggle) {
|
||||
} else if(flags & WorkerEvtStartStop) {
|
||||
delay_val = 0;
|
||||
worker_state = BadBtStateRunning;
|
||||
} else if(flags & WorkerEvtDisconnect) {
|
||||
|
@ -646,14 +656,15 @@ static int32_t bad_bt_worker(void* context) {
|
|||
}
|
||||
} else if(worker_state == BadBtStateStringDelay) { // State: print string with delays
|
||||
uint32_t flags = furi_thread_flags_wait(
|
||||
WorkerEvtEnd | WorkerEvtToggle | WorkerEvtDisconnect,
|
||||
WorkerEvtEnd | WorkerEvtStartStop | WorkerEvtPauseResume | WorkerEvtConnect |
|
||||
WorkerEvtDisconnect,
|
||||
FuriFlagWaitAny,
|
||||
bad_bt->stringdelay);
|
||||
|
||||
if(!(flags & FuriFlagError)) {
|
||||
if(flags & WorkerEvtEnd) {
|
||||
break;
|
||||
} else if(flags & WorkerEvtToggle) {
|
||||
} else if(flags & WorkerEvtStartStop) {
|
||||
worker_state = BadBtStateIdle; // Stop executing script
|
||||
|
||||
furi_hal_bt_hid_kb_release_all();
|
||||
|
@ -768,7 +779,7 @@ void bad_bt_script_set_keyboard_layout(BadBtScript* bad_bt, FuriString* layout_p
|
|||
|
||||
void bad_bt_script_toggle(BadBtScript* bad_bt) {
|
||||
furi_assert(bad_bt);
|
||||
furi_thread_flags_set(furi_thread_get_id(bad_bt->thread), WorkerEvtToggle);
|
||||
furi_thread_flags_set(furi_thread_get_id(bad_bt->thread), WorkerEvtStartStop);
|
||||
}
|
||||
|
||||
BadBtState* bad_bt_script_get_state(BadBtScript* bad_bt) {
|
||||
|
|
|
@ -11,6 +11,8 @@ void bad_bt_scene_config_mac_byte_input_callback(void* context) {
|
|||
void bad_bt_scene_config_mac_on_enter(void* context) {
|
||||
BadBtApp* bad_bt = context;
|
||||
|
||||
furi_hal_bt_reverse_mac_addr(bad_bt->config.bt_mac);
|
||||
|
||||
// Setup view
|
||||
ByteInput* byte_input = bad_bt->byte_input;
|
||||
byte_input_set_header_text(byte_input, "Set BT MAC address");
|
||||
|
@ -30,7 +32,6 @@ bool bad_bt_scene_config_mac_on_event(void* context, SceneManagerEvent event) {
|
|||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == BadBtAppCustomEventByteInputDone) {
|
||||
bt_set_profile_mac_address(bad_bt->bt, bad_bt->config.bt_mac);
|
||||
scene_manager_previous_scene(bad_bt->scene_manager);
|
||||
consumed = true;
|
||||
}
|
||||
|
@ -41,6 +42,10 @@ bool bad_bt_scene_config_mac_on_event(void* context, SceneManagerEvent event) {
|
|||
void bad_bt_scene_config_mac_on_exit(void* context) {
|
||||
BadBtApp* bad_bt = context;
|
||||
|
||||
furi_hal_bt_reverse_mac_addr(bad_bt->config.bt_mac);
|
||||
|
||||
bt_set_profile_mac_address(bad_bt->bt, bad_bt->config.bt_mac);
|
||||
|
||||
// Clear view
|
||||
byte_input_set_result_callback(bad_bt->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(bad_bt->byte_input, "");
|
||||
|
|
22
applications/external/barcode_gen/LICENSE
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Alan Tsui
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
88
applications/external/barcode_gen/README.md
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
<p align="center">
|
||||
<h1 align="center">Barcode Generator</h1>
|
||||
<p align="center">
|
||||
|
||||
A barcode generator for the Flipper Zero that supports **UPC-A**, **EAN-8**, **EAN-13**, **Code-39**, **Codabar**, and **Code-128**[1]
|
||||
</p>
|
||||
|
||||
Note: Barcode save locations have been moved from `/barcodes` to `/apps_data/barcodes`
|
||||
|
||||
## Table of Contents
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [Installing](#installing)
|
||||
- [Building](#building)
|
||||
- [Usage](#usage)
|
||||
- [Creating a barcode](#creating-a-barcode)
|
||||
- [Editing a barcode](#editing-a-barcode)
|
||||
- [Deleting a barcode](#deleting-a-barcode)
|
||||
- [Viewing a barcode](#viewing-a-barcode)
|
||||
- [Screenshots](#screenshots)
|
||||
- [Credits](#credits)
|
||||
|
||||
|
||||
## Installing
|
||||
1) Download the `.zip` file from the release section
|
||||
2) Extract/unzip the `.zip` file onto your computer
|
||||
3) Open qFlipper and go to the file manager
|
||||
4) Navigate to the `apps` folder
|
||||
5) Drag & drop the `.fap` file into the `apps` folder
|
||||
6) Navigate back to the root folder of the SD card and create the folder `apps_data`, if not already there
|
||||
7) Navigate into `apps_data` and create another folder called `barcode_data`
|
||||
8) Navigate into `barcode_data`
|
||||
9) Drag & drop the encoding txts (`code39_encodings.txt`, `code128_encodings.txt` & `codabar_encodings.txt`) into the `barcode_data` folder
|
||||
|
||||
## Building
|
||||
1) Clone the [flipperzero-firmware](https://github.com/flipperdevices/flipperzero-firmware) repository or a firmware of your choice
|
||||
2) Clone this repository and put it in the `applications_user` folder
|
||||
3) Build this app by using the command `./fbt fap_Barcode_App`
|
||||
4) Copy the `.fap` from `build\f7-firmware-D\.extapps\Barcode_App.fap` to `apps\Misc` using the qFlipper app
|
||||
5) While still in the qFlipper app, navigate to the root folder of the SD card and create the folder `apps_data`, if not already there
|
||||
6) Navigate into `apps_data` and create another folder called `barcode_data`
|
||||
7) Navigate into `barcode_data`
|
||||
8) Drag & drop the encoding txts (`code39_encodings.txt`, `code128_encodings.txt` & `codabar_encodings.txt`) from the `encoding_tables` folder in this repository into the `barcode_data` folder
|
||||
|
||||
## Usage
|
||||
|
||||
### Creating a barcode
|
||||
1) To create a barcode click on `Create Barcode`
|
||||
2) Next select your type using the left and right arrows
|
||||
3) Enter your filename and then your barcode data
|
||||
4) Click save
|
||||
|
||||
**Note**: For Codabar barcodes, you must manually add the start and stop codes to the barcode data
|
||||
Start/Stop codes can be A, B, C, or D
|
||||
For example, if you wanted to represent `1234` as a barcode you will need to enter something like `A1234A`. (You can replace the letters A with either A, B, C, or D)
|
||||
|
||||
![Codabar Data Example](screenshots/Codabar%20Data%20Example.png "Codabar Data Example")
|
||||
|
||||
### Editing a barcode
|
||||
1) To edit a barcode click on `Edit Barcode`
|
||||
2) Next select the barcode file you want to edit
|
||||
3) Edit the type, name, or data
|
||||
4) Click save
|
||||
|
||||
### Deleting a barcode
|
||||
1) To delete a barcode click on `Edit Barcode`
|
||||
2) Next select the barcode file you want to delete
|
||||
3) Scroll all the way to the bottom
|
||||
4) Click delete
|
||||
|
||||
### Viewing a barcode
|
||||
1) To view a barcode click on `Load Barcode`
|
||||
2) Next select the barcode file you want to view
|
||||
|
||||
## Screenshots
|
||||
![Barcode Create Screen](screenshots/Creating%20Barcode.png "Barcode Create Screen")
|
||||
|
||||
![Flipper Code-128 Barcode](screenshots/Flipper%20Barcode.png "Flipper Code-128 Barcode")
|
||||
|
||||
![Flipper Box EAN-13 Barcode](screenshots/Flipper%20Box%20Barcode.png "Flipper Box EAN-13 Barcode")
|
||||
|
||||
## Credits
|
||||
|
||||
- [Kingal1337](https://github.com/Kingal1337) - Developer
|
||||
- [Z0wl](https://github.com/Z0wl) - Added Code128-C Support
|
||||
- [@teeebor](https://github.com/teeebor) - Menu Code Snippet
|
||||
|
||||
|
||||
[1] - supports Set B (only the characters from 0-94). Also supports Set C
|
16
applications/external/barcode_gen/application.fam
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
App(
|
||||
appid="barcode_app",
|
||||
name="Barcode App",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="barcode_main",
|
||||
requires=["gui", "storage"],
|
||||
stack_size=2 * 1024,
|
||||
fap_category="Tools",
|
||||
fap_icon="images/barcode_10.png",
|
||||
fap_icon_assets="images",
|
||||
fap_icon_assets_symbol="barcode_app",
|
||||
fap_author="@Kingal1337",
|
||||
fap_weburl="https://github.com/Kingal1337/flipper-barcode-generator",
|
||||
fap_version="1.0",
|
||||
fap_description="App allows you to display various barcodes on flipper screen",
|
||||
)
|
348
applications/external/barcode_gen/barcode_app.c
vendored
Normal file
|
@ -0,0 +1,348 @@
|
|||
#include "barcode_app.h"
|
||||
|
||||
#include "barcode_app_icons.h"
|
||||
|
||||
/**
|
||||
* Opens a file browser dialog and returns the filepath of the selected file
|
||||
*
|
||||
* @param folder the folder to view when the browser opens
|
||||
* @param file_path a string pointer for the file_path when a file is selected,
|
||||
* file_path will be the folder path is nothing is selected
|
||||
* @returns true if a file is selected
|
||||
*/
|
||||
static bool select_file(const char* folder, FuriString* file_path) {
|
||||
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
DialogsFileBrowserOptions browser_options;
|
||||
dialog_file_browser_set_basic_options(&browser_options, "", &I_barcode_10);
|
||||
browser_options.base_path = DEFAULT_USER_BARCODES;
|
||||
furi_string_set(file_path, folder);
|
||||
|
||||
bool res = dialog_file_browser_show(dialogs, file_path, file_path, &browser_options);
|
||||
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the data from a file and stores them in the FuriStrings raw_type and raw_data
|
||||
*/
|
||||
ErrorCode read_raw_data(FuriString* file_path, FuriString* raw_type, FuriString* raw_data) {
|
||||
//Open Storage
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
||||
|
||||
ErrorCode reason = OKCode;
|
||||
|
||||
if(!flipper_format_file_open_existing(ff, furi_string_get_cstr(file_path))) {
|
||||
FURI_LOG_E(TAG, "Could not open file %s", furi_string_get_cstr(file_path));
|
||||
reason = FileOpening;
|
||||
} else {
|
||||
if(!flipper_format_read_string(ff, "Type", raw_type)) {
|
||||
FURI_LOG_E(TAG, "Could not read \"Type\" string");
|
||||
reason = InvalidFileData;
|
||||
}
|
||||
if(!flipper_format_read_string(ff, "Data", raw_data)) {
|
||||
FURI_LOG_E(TAG, "Could not read \"Data\" string");
|
||||
reason = InvalidFileData;
|
||||
}
|
||||
}
|
||||
|
||||
//Close Storage
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file name from a file path
|
||||
* @param file_path the file path
|
||||
* @param file_name the FuriString to store the file name
|
||||
* @param remove_extension true if the extension should be removed, otherwise false
|
||||
*/
|
||||
bool get_file_name_from_path(FuriString* file_path, FuriString* file_name, bool remove_extension) {
|
||||
if(file_path == NULL || file_name == NULL) {
|
||||
return false;
|
||||
}
|
||||
uint32_t slash_index = furi_string_search_rchar(file_path, '/', 0);
|
||||
if(slash_index == FURI_STRING_FAILURE || slash_index >= (furi_string_size(file_path) - 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
furi_string_set(file_name, file_path);
|
||||
furi_string_right(file_name, slash_index + 1);
|
||||
if(remove_extension) {
|
||||
uint32_t ext_index = furi_string_search_rchar(file_name, '.', 0);
|
||||
if(ext_index != FURI_STRING_FAILURE && ext_index < (furi_string_size(file_path))) {
|
||||
furi_string_left(file_name, ext_index);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the barcode folder
|
||||
*/
|
||||
void init_folder() {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FURI_LOG_I(TAG, "Creating barcodes folder");
|
||||
if(storage_simply_mkdir(storage, DEFAULT_USER_BARCODES)) {
|
||||
FURI_LOG_I(TAG, "Barcodes folder successfully created!");
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "Barcodes folder already exists.");
|
||||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
void select_barcode_item(BarcodeApp* app) {
|
||||
FuriString* file_path = furi_string_alloc();
|
||||
FuriString* raw_type = furi_string_alloc();
|
||||
FuriString* raw_data = furi_string_alloc();
|
||||
|
||||
//this determines if the data was read correctly or if the
|
||||
bool loaded_success = true;
|
||||
ErrorCode reason = OKCode;
|
||||
|
||||
bool file_selected = select_file(DEFAULT_USER_BARCODES, file_path);
|
||||
if(file_selected) {
|
||||
FURI_LOG_I(TAG, "The file selected is %s", furi_string_get_cstr(file_path));
|
||||
Barcode* barcode = app->barcode_view;
|
||||
|
||||
reason = read_raw_data(file_path, raw_type, raw_data);
|
||||
if(reason != OKCode) {
|
||||
loaded_success = false;
|
||||
FURI_LOG_E(TAG, "Could not read data correctly");
|
||||
}
|
||||
|
||||
//Free the data from the previous barcode
|
||||
barcode_free_model(barcode);
|
||||
|
||||
with_view_model(
|
||||
barcode->view,
|
||||
BarcodeModel * model,
|
||||
{
|
||||
model->file_path = furi_string_alloc_set(file_path);
|
||||
|
||||
model->data = malloc(sizeof(BarcodeData));
|
||||
model->data->valid = loaded_success;
|
||||
|
||||
if(loaded_success) {
|
||||
model->data->raw_data = furi_string_alloc_set(raw_data);
|
||||
model->data->correct_data = furi_string_alloc();
|
||||
|
||||
model->data->type_obj = get_type(raw_type);
|
||||
|
||||
barcode_loader(model->data);
|
||||
} else {
|
||||
model->data->reason = reason;
|
||||
}
|
||||
},
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, BarcodeView);
|
||||
}
|
||||
|
||||
furi_string_free(raw_type);
|
||||
furi_string_free(raw_data);
|
||||
furi_string_free(file_path);
|
||||
}
|
||||
|
||||
void edit_barcode_item(BarcodeApp* app) {
|
||||
FuriString* file_path = furi_string_alloc();
|
||||
FuriString* file_name = furi_string_alloc();
|
||||
FuriString* raw_type = furi_string_alloc();
|
||||
FuriString* raw_data = furi_string_alloc();
|
||||
|
||||
//this determines if the data was read correctly or if the
|
||||
ErrorCode reason = OKCode;
|
||||
|
||||
bool file_selected = select_file(DEFAULT_USER_BARCODES, file_path);
|
||||
if(file_selected) {
|
||||
FURI_LOG_I(TAG, "The file selected is %s", furi_string_get_cstr(file_path));
|
||||
CreateView* create_view_object = app->create_view;
|
||||
|
||||
reason = read_raw_data(file_path, raw_type, raw_data);
|
||||
if(reason != OKCode) {
|
||||
FURI_LOG_E(TAG, "Could not read data correctly");
|
||||
with_view_model(
|
||||
app->message_view->view,
|
||||
MessageViewModel * model,
|
||||
{ model->message = get_error_code_message(reason); },
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(
|
||||
create_view_object->barcode_app->view_dispatcher, MessageErrorView);
|
||||
|
||||
} else {
|
||||
BarcodeTypeObj* type_obj = get_type(raw_type);
|
||||
if(type_obj->type == UNKNOWN) {
|
||||
type_obj = barcode_type_objs[0];
|
||||
}
|
||||
get_file_name_from_path(file_path, file_name, true);
|
||||
|
||||
create_view_free_model(create_view_object);
|
||||
with_view_model(
|
||||
create_view_object->view,
|
||||
CreateViewModel * model,
|
||||
{
|
||||
model->selected_menu_item = 0;
|
||||
model->barcode_type = type_obj;
|
||||
model->file_path = furi_string_alloc_set(file_path);
|
||||
model->file_name = furi_string_alloc_set(file_name);
|
||||
model->barcode_data = furi_string_alloc_set(raw_data);
|
||||
model->mode = EditMode;
|
||||
},
|
||||
true);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, CreateBarcodeView);
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_free(raw_type);
|
||||
furi_string_free(raw_data);
|
||||
furi_string_free(file_name);
|
||||
furi_string_free(file_path);
|
||||
}
|
||||
|
||||
void create_barcode_item(BarcodeApp* app) {
|
||||
CreateView* create_view_object = app->create_view;
|
||||
|
||||
create_view_free_model(create_view_object);
|
||||
|
||||
with_view_model(
|
||||
create_view_object->view,
|
||||
CreateViewModel * model,
|
||||
{
|
||||
model->selected_menu_item = 0;
|
||||
model->barcode_type = barcode_type_objs[0];
|
||||
model->file_path = furi_string_alloc();
|
||||
model->file_name = furi_string_alloc();
|
||||
model->barcode_data = furi_string_alloc();
|
||||
model->mode = NewMode;
|
||||
},
|
||||
true);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, CreateBarcodeView);
|
||||
}
|
||||
|
||||
void submenu_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
|
||||
BarcodeApp* app = context;
|
||||
|
||||
if(index == SelectBarcodeItem) {
|
||||
select_barcode_item(app);
|
||||
} else if(index == EditBarcodeItem) {
|
||||
edit_barcode_item(app);
|
||||
} else if(index == CreateBarcodeItem) {
|
||||
create_barcode_item(app);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t create_view_callback(void* context) {
|
||||
UNUSED(context);
|
||||
return CreateBarcodeView;
|
||||
}
|
||||
|
||||
uint32_t main_menu_callback(void* context) {
|
||||
UNUSED(context);
|
||||
return MainMenuView;
|
||||
}
|
||||
|
||||
uint32_t exit_callback(void* context) {
|
||||
UNUSED(context);
|
||||
return VIEW_NONE;
|
||||
}
|
||||
|
||||
void free_app(BarcodeApp* app) {
|
||||
FURI_LOG_I(TAG, "Freeing Data");
|
||||
|
||||
init_folder();
|
||||
free_types();
|
||||
|
||||
view_dispatcher_remove_view(app->view_dispatcher, TextInputView);
|
||||
text_input_free(app->text_input);
|
||||
|
||||
view_dispatcher_remove_view(app->view_dispatcher, MessageErrorView);
|
||||
message_view_free(app->message_view);
|
||||
|
||||
view_dispatcher_remove_view(app->view_dispatcher, MainMenuView);
|
||||
submenu_free(app->main_menu);
|
||||
|
||||
view_dispatcher_remove_view(app->view_dispatcher, CreateBarcodeView);
|
||||
create_view_free(app->create_view);
|
||||
|
||||
view_dispatcher_remove_view(app->view_dispatcher, BarcodeView);
|
||||
barcode_free(app->barcode_view);
|
||||
|
||||
//free the dispatcher
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
|
||||
furi_message_queue_free(app->event_queue);
|
||||
|
||||
furi_record_close(RECORD_GUI);
|
||||
app->gui = NULL;
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
int32_t barcode_main(void* p) {
|
||||
UNUSED(p);
|
||||
BarcodeApp* app = malloc(sizeof(BarcodeApp));
|
||||
init_types();
|
||||
app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
||||
|
||||
// Register view port in GUI
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
app->main_menu = submenu_alloc();
|
||||
submenu_add_item(app->main_menu, "Load Barcode", SelectBarcodeItem, submenu_callback, app);
|
||||
view_set_previous_callback(submenu_get_view(app->main_menu), exit_callback);
|
||||
view_dispatcher_add_view(app->view_dispatcher, MainMenuView, submenu_get_view(app->main_menu));
|
||||
|
||||
submenu_add_item(app->main_menu, "Edit Barcode", EditBarcodeItem, submenu_callback, app);
|
||||
|
||||
/*****************************
|
||||
* Creating Text Input View
|
||||
******************************/
|
||||
app->text_input = text_input_alloc();
|
||||
view_set_previous_callback(text_input_get_view(app->text_input), create_view_callback);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, TextInputView, text_input_get_view(app->text_input));
|
||||
|
||||
/*****************************
|
||||
* Creating Message View
|
||||
******************************/
|
||||
app->message_view = message_view_allocate(app);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, MessageErrorView, message_get_view(app->message_view));
|
||||
|
||||
/*****************************
|
||||
* Creating Create View
|
||||
******************************/
|
||||
app->create_view = create_view_allocate(app);
|
||||
submenu_add_item(app->main_menu, "Create Barcode", CreateBarcodeItem, submenu_callback, app);
|
||||
view_set_previous_callback(create_get_view(app->create_view), main_menu_callback);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, CreateBarcodeView, create_get_view(app->create_view));
|
||||
|
||||
/*****************************
|
||||
* Creating Barcode View
|
||||
******************************/
|
||||
app->barcode_view = barcode_view_allocate(app);
|
||||
view_set_previous_callback(barcode_get_view(app->barcode_view), main_menu_callback);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, BarcodeView, barcode_get_view(app->barcode_view));
|
||||
|
||||
//switch view to submenu and run dispatcher
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, MainMenuView);
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
|
||||
free_app(app);
|
||||
|
||||
return 0;
|
||||
}
|
91
applications/external/barcode_gen/barcode_app.h
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
#pragma once
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
#include "barcode_utils.h"
|
||||
|
||||
#define TAG "BARCODE"
|
||||
#define VERSION "1.1"
|
||||
#define FILE_VERSION "1"
|
||||
|
||||
#define TEXT_BUFFER_SIZE 128
|
||||
|
||||
#define BARCODE_HEIGHT 50
|
||||
#define BARCODE_Y_START 3
|
||||
|
||||
//the folder where the encodings are located
|
||||
#define BARCODE_DATA_FILE_DIR_PATH EXT_PATH("apps_data/barcode_data")
|
||||
|
||||
//the folder where the codabar encoding table is located
|
||||
#define CODABAR_DICT_FILE_PATH BARCODE_DATA_FILE_DIR_PATH "/codabar_encodings.txt"
|
||||
|
||||
//the folder where the code 39 encoding table is located
|
||||
#define CODE39_DICT_FILE_PATH BARCODE_DATA_FILE_DIR_PATH "/code39_encodings.txt"
|
||||
|
||||
//the folder where the code 128 encoding table is located
|
||||
#define CODE128_DICT_FILE_PATH BARCODE_DATA_FILE_DIR_PATH "/code128_encodings.txt"
|
||||
|
||||
//the folder where the code 128 C encoding table is located
|
||||
#define CODE128C_DICT_FILE_PATH BARCODE_DATA_FILE_DIR_PATH "/code128c_encodings.txt"
|
||||
|
||||
//the folder where the user stores their barcodes
|
||||
#define DEFAULT_USER_BARCODES EXT_PATH("apps_data/barcodes")
|
||||
|
||||
//The extension barcode files use
|
||||
#define BARCODE_EXTENSION ".txt"
|
||||
#define BARCODE_EXTENSION_LENGTH 4
|
||||
|
||||
#include "views/barcode_view.h"
|
||||
#include "views/create_view.h"
|
||||
#include "views/message_view.h"
|
||||
#include "barcode_validator.h"
|
||||
|
||||
typedef struct BarcodeApp BarcodeApp;
|
||||
|
||||
struct BarcodeApp {
|
||||
Submenu* main_menu;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
Gui* gui;
|
||||
|
||||
FuriMessageQueue* event_queue;
|
||||
|
||||
CreateView* create_view;
|
||||
Barcode* barcode_view;
|
||||
|
||||
MessageView* message_view;
|
||||
TextInput* text_input;
|
||||
};
|
||||
|
||||
enum SubmenuItems {
|
||||
SelectBarcodeItem,
|
||||
EditBarcodeItem,
|
||||
|
||||
CreateBarcodeItem
|
||||
};
|
||||
|
||||
enum Views {
|
||||
TextInputView,
|
||||
MessageErrorView,
|
||||
MainMenuView,
|
||||
CreateBarcodeView,
|
||||
|
||||
BarcodeView
|
||||
};
|
||||
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
|
||||
uint32_t main_menu_callback(void* context);
|
||||
|
||||
uint32_t exit_callback(void* context);
|
||||
|
||||
int32_t barcode_main(void* p);
|
147
applications/external/barcode_gen/barcode_utils.c
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
#include "barcode_utils.h"
|
||||
|
||||
BarcodeTypeObj* barcode_type_objs[NUMBER_OF_BARCODE_TYPES] = {NULL};
|
||||
|
||||
void init_types() {
|
||||
BarcodeTypeObj* upc_a = malloc(sizeof(BarcodeTypeObj));
|
||||
upc_a->name = "UPC-A";
|
||||
upc_a->type = UPCA;
|
||||
upc_a->min_digits = 11;
|
||||
upc_a->max_digits = 12;
|
||||
upc_a->start_pos = 16;
|
||||
barcode_type_objs[UPCA] = upc_a;
|
||||
|
||||
BarcodeTypeObj* ean_8 = malloc(sizeof(BarcodeTypeObj));
|
||||
ean_8->name = "EAN-8";
|
||||
ean_8->type = EAN8;
|
||||
ean_8->min_digits = 7;
|
||||
ean_8->max_digits = 8;
|
||||
ean_8->start_pos = 32;
|
||||
barcode_type_objs[EAN8] = ean_8;
|
||||
|
||||
BarcodeTypeObj* ean_13 = malloc(sizeof(BarcodeTypeObj));
|
||||
ean_13->name = "EAN-13";
|
||||
ean_13->type = EAN13;
|
||||
ean_13->min_digits = 12;
|
||||
ean_13->max_digits = 13;
|
||||
ean_13->start_pos = 16;
|
||||
barcode_type_objs[EAN13] = ean_13;
|
||||
|
||||
BarcodeTypeObj* code_39 = malloc(sizeof(BarcodeTypeObj));
|
||||
code_39->name = "CODE-39";
|
||||
code_39->type = CODE39;
|
||||
code_39->min_digits = 1;
|
||||
code_39->max_digits = -1;
|
||||
code_39->start_pos = 0;
|
||||
barcode_type_objs[CODE39] = code_39;
|
||||
|
||||
BarcodeTypeObj* code_128 = malloc(sizeof(BarcodeTypeObj));
|
||||
code_128->name = "CODE-128";
|
||||
code_128->type = CODE128;
|
||||
code_128->min_digits = 1;
|
||||
code_128->max_digits = -1;
|
||||
code_128->start_pos = 0;
|
||||
barcode_type_objs[CODE128] = code_128;
|
||||
|
||||
BarcodeTypeObj* code_128c = malloc(sizeof(BarcodeTypeObj));
|
||||
code_128c->name = "CODE-128C";
|
||||
code_128c->type = CODE128C;
|
||||
code_128c->min_digits = 2;
|
||||
code_128c->max_digits = -1;
|
||||
code_128c->start_pos = 0;
|
||||
barcode_type_objs[CODE128C] = code_128c;
|
||||
|
||||
BarcodeTypeObj* codabar = malloc(sizeof(BarcodeTypeObj));
|
||||
codabar->name = "Codabar";
|
||||
codabar->type = CODABAR;
|
||||
codabar->min_digits = 1;
|
||||
codabar->max_digits = -1;
|
||||
codabar->start_pos = 0;
|
||||
barcode_type_objs[CODABAR] = codabar;
|
||||
|
||||
BarcodeTypeObj* unknown = malloc(sizeof(BarcodeTypeObj));
|
||||
unknown->name = "Unknown";
|
||||
unknown->type = UNKNOWN;
|
||||
unknown->min_digits = 0;
|
||||
unknown->max_digits = 0;
|
||||
unknown->start_pos = 0;
|
||||
barcode_type_objs[UNKNOWN] = unknown;
|
||||
}
|
||||
|
||||
void free_types() {
|
||||
for(int i = 0; i < NUMBER_OF_BARCODE_TYPES; i++) {
|
||||
free(barcode_type_objs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
BarcodeTypeObj* get_type(FuriString* type_string) {
|
||||
if(furi_string_cmp_str(type_string, "UPC-A") == 0) {
|
||||
return barcode_type_objs[UPCA];
|
||||
}
|
||||
if(furi_string_cmp_str(type_string, "EAN-8") == 0) {
|
||||
return barcode_type_objs[EAN8];
|
||||
}
|
||||
if(furi_string_cmp_str(type_string, "EAN-13") == 0) {
|
||||
return barcode_type_objs[EAN13];
|
||||
}
|
||||
if(furi_string_cmp_str(type_string, "CODE-39") == 0) {
|
||||
return barcode_type_objs[CODE39];
|
||||
}
|
||||
if(furi_string_cmp_str(type_string, "CODE-128") == 0) {
|
||||
return barcode_type_objs[CODE128];
|
||||
}
|
||||
if(furi_string_cmp_str(type_string, "CODE-128C") == 0) {
|
||||
return barcode_type_objs[CODE128C];
|
||||
}
|
||||
if(furi_string_cmp_str(type_string, "Codabar") == 0) {
|
||||
return barcode_type_objs[CODABAR];
|
||||
}
|
||||
|
||||
return barcode_type_objs[UNKNOWN];
|
||||
}
|
||||
|
||||
const char* get_error_code_name(ErrorCode error_code) {
|
||||
switch(error_code) {
|
||||
case WrongNumberOfDigits:
|
||||
return "Wrong Number Of Digits";
|
||||
case InvalidCharacters:
|
||||
return "Invalid Characters";
|
||||
case UnsupportedType:
|
||||
return "Unsupported Type";
|
||||
case FileOpening:
|
||||
return "File Opening Error";
|
||||
case InvalidFileData:
|
||||
return "Invalid File Data";
|
||||
case MissingEncodingTable:
|
||||
return "Missing Encoding Table";
|
||||
case EncodingTableError:
|
||||
return "Encoding Table Error";
|
||||
case OKCode:
|
||||
return "OK";
|
||||
default:
|
||||
return "Unknown Code";
|
||||
};
|
||||
}
|
||||
|
||||
const char* get_error_code_message(ErrorCode error_code) {
|
||||
switch(error_code) {
|
||||
case WrongNumberOfDigits:
|
||||
return "Wrong # of characters";
|
||||
case InvalidCharacters:
|
||||
return "Invalid characters";
|
||||
case UnsupportedType:
|
||||
return "Unsupported barcode type";
|
||||
case FileOpening:
|
||||
return "Could not open file";
|
||||
case InvalidFileData:
|
||||
return "Invalid file data";
|
||||
case MissingEncodingTable:
|
||||
return "Missing encoding table";
|
||||
case EncodingTableError:
|
||||
return "Encoding table error";
|
||||
case OKCode:
|
||||
return "OK";
|
||||
default:
|
||||
return "Could not read barcode data";
|
||||
};
|
||||
}
|
55
applications/external/barcode_gen/barcode_utils.h
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
|
||||
#pragma once
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define NUMBER_OF_BARCODE_TYPES 8
|
||||
|
||||
typedef enum {
|
||||
WrongNumberOfDigits, //There is too many or too few digits in the barcode
|
||||
InvalidCharacters, //The barcode contains invalid characters
|
||||
UnsupportedType, //the barcode type is not supported
|
||||
FileOpening, //A problem occurred when opening the barcode data file
|
||||
InvalidFileData, //One of the key in the file doesn't exist or there is a typo
|
||||
MissingEncodingTable, //The encoding table txt for the barcode type is missing
|
||||
EncodingTableError, //Something is wrong with the encoding table, probably missing data or typo
|
||||
OKCode
|
||||
} ErrorCode;
|
||||
|
||||
typedef enum {
|
||||
UPCA,
|
||||
EAN8,
|
||||
EAN13,
|
||||
CODE39,
|
||||
CODE128,
|
||||
CODE128C,
|
||||
CODABAR,
|
||||
|
||||
UNKNOWN
|
||||
} BarcodeType;
|
||||
|
||||
typedef struct {
|
||||
char* name; //The name of the barcode type
|
||||
BarcodeType type; //The barcode type enum
|
||||
int min_digits; //the minimum number of digits
|
||||
int max_digits; //the maximum number of digits
|
||||
int start_pos; //where to start drawing the barcode, set to -1 to dynamically draw barcode
|
||||
} BarcodeTypeObj;
|
||||
|
||||
typedef struct {
|
||||
BarcodeTypeObj* type_obj;
|
||||
int check_digit; //A place to store the check digit
|
||||
FuriString* raw_data; //the data directly from the file
|
||||
FuriString* correct_data; //the corrected/processed data
|
||||
bool valid; //true if the raw data is correctly formatted, such as correct num of digits, valid characters, etc.
|
||||
ErrorCode reason; //the reason why this barcode is invalid
|
||||
} BarcodeData;
|
||||
|
||||
//All available barcode types
|
||||
extern BarcodeTypeObj* barcode_type_objs[NUMBER_OF_BARCODE_TYPES];
|
||||
|
||||
void init_types();
|
||||
void free_types();
|
||||
BarcodeTypeObj* get_type(FuriString* type_string);
|
||||
const char* get_error_code_name(ErrorCode error_code);
|
||||
const char* get_error_code_message(ErrorCode error_code);
|
532
applications/external/barcode_gen/barcode_validator.c
vendored
Normal file
|
@ -0,0 +1,532 @@
|
|||
#include "barcode_validator.h"
|
||||
|
||||
void barcode_loader(BarcodeData* barcode_data) {
|
||||
switch(barcode_data->type_obj->type) {
|
||||
case UPCA:
|
||||
case EAN8:
|
||||
case EAN13:
|
||||
ean_upc_loader(barcode_data);
|
||||
break;
|
||||
case CODE39:
|
||||
code_39_loader(barcode_data);
|
||||
break;
|
||||
case CODE128:
|
||||
code_128_loader(barcode_data);
|
||||
break;
|
||||
case CODE128C:
|
||||
code_128c_loader(barcode_data);
|
||||
break;
|
||||
case CODABAR:
|
||||
codabar_loader(barcode_data);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
barcode_data->reason = UnsupportedType;
|
||||
barcode_data->valid = false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the check digit of a barcode if they have one
|
||||
* @param barcode_data the barcode data
|
||||
* @returns a check digit or -1 for either an invalid
|
||||
*/
|
||||
int calculate_check_digit(BarcodeData* barcode_data) {
|
||||
int check_digit = -1;
|
||||
switch(barcode_data->type_obj->type) {
|
||||
case UPCA:
|
||||
case EAN8:
|
||||
case EAN13:
|
||||
check_digit = calculate_ean_upc_check_digit(barcode_data);
|
||||
break;
|
||||
case CODE39:
|
||||
case CODE128:
|
||||
case CODE128C:
|
||||
case CODABAR:
|
||||
case UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return check_digit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the check digit of barcode types UPC-A, EAN-8, & EAN-13
|
||||
*/
|
||||
int calculate_ean_upc_check_digit(BarcodeData* barcode_data) {
|
||||
int check_digit = 0;
|
||||
int odd = 0;
|
||||
int even = 0;
|
||||
|
||||
int length = barcode_data->type_obj->min_digits;
|
||||
|
||||
//Get sum of odd digits
|
||||
for(int i = 0; i < length; i += 2) {
|
||||
odd += furi_string_get_char(barcode_data->raw_data, i) - '0';
|
||||
}
|
||||
|
||||
//Get sum of even digits
|
||||
for(int i = 1; i < length; i += 2) {
|
||||
even += furi_string_get_char(barcode_data->raw_data, i) - '0';
|
||||
}
|
||||
|
||||
if(barcode_data->type_obj->type == EAN13) {
|
||||
check_digit = even * 3 + odd;
|
||||
} else {
|
||||
check_digit = odd * 3 + even;
|
||||
}
|
||||
|
||||
check_digit = check_digit % 10;
|
||||
|
||||
return (10 - check_digit) % 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and validates Barcode Types EAN-8, EAN-13, and UPC-A
|
||||
* barcode_data and its strings should already be allocated;
|
||||
*/
|
||||
void ean_upc_loader(BarcodeData* barcode_data) {
|
||||
int barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
int min_digits = barcode_data->type_obj->min_digits;
|
||||
int max_digit = barcode_data->type_obj->max_digits;
|
||||
|
||||
//check the length of the barcode
|
||||
if(barcode_length < min_digits || barcode_length > max_digit) {
|
||||
barcode_data->reason = WrongNumberOfDigits;
|
||||
barcode_data->valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
//checks if the barcode contains any characters that aren't a number
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
char character = furi_string_get_char(barcode_data->raw_data, i);
|
||||
int digit = character - '0'; //convert the number into an int (also the index)
|
||||
if(digit < 0 || digit > 9) {
|
||||
barcode_data->reason = InvalidCharacters;
|
||||
barcode_data->valid = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int check_digit = calculate_check_digit(barcode_data);
|
||||
char check_digit_char = check_digit + '0';
|
||||
|
||||
barcode_data->check_digit = check_digit;
|
||||
|
||||
//if the barcode length is at max length then we will verify if the check digit is correct
|
||||
if(barcode_length == max_digit) {
|
||||
//append the raw_data to the correct data string
|
||||
furi_string_cat(barcode_data->correct_data, barcode_data->raw_data);
|
||||
|
||||
//append the check digit to the correct data string
|
||||
furi_string_set_char(barcode_data->correct_data, min_digits, check_digit_char);
|
||||
}
|
||||
//if the barcode length is at min length, we will calculate the check digit
|
||||
if(barcode_length == min_digits) {
|
||||
//append the raw_data to the correct data string
|
||||
furi_string_cat(barcode_data->correct_data, barcode_data->raw_data);
|
||||
|
||||
//append the check digit to the correct data string
|
||||
furi_string_push_back(barcode_data->correct_data, check_digit_char);
|
||||
}
|
||||
}
|
||||
|
||||
void code_39_loader(BarcodeData* barcode_data) {
|
||||
int barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
int min_digits = barcode_data->type_obj->min_digits;
|
||||
|
||||
//check the length of the barcode, must contain atleast a character,
|
||||
//this can have as many characters as it wants, it might not fit on the screen
|
||||
if(barcode_length < min_digits) {
|
||||
barcode_data->reason = WrongNumberOfDigits;
|
||||
barcode_data->valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
FuriString* barcode_bits = furi_string_alloc();
|
||||
FuriString* temp_string = furi_string_alloc();
|
||||
|
||||
//add starting and ending *
|
||||
if(!furi_string_start_with(barcode_data->raw_data, "*")) {
|
||||
furi_string_push_back(temp_string, '*');
|
||||
furi_string_cat(temp_string, barcode_data->raw_data);
|
||||
furi_string_set(barcode_data->raw_data, temp_string);
|
||||
}
|
||||
|
||||
if(!furi_string_end_with(barcode_data->raw_data, "*")) {
|
||||
furi_string_push_back(barcode_data->raw_data, '*');
|
||||
}
|
||||
|
||||
furi_string_free(temp_string);
|
||||
barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
//Open Storage
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
||||
|
||||
if(!flipper_format_file_open_existing(ff, CODE39_DICT_FILE_PATH)) {
|
||||
FURI_LOG_E(TAG, "Could not open file %s", CODE39_DICT_FILE_PATH);
|
||||
barcode_data->reason = MissingEncodingTable;
|
||||
barcode_data->valid = false;
|
||||
} else {
|
||||
FuriString* char_bits = furi_string_alloc();
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
char barcode_char = toupper(furi_string_get_char(barcode_data->raw_data, i));
|
||||
|
||||
//convert a char into a string so it used in flipper_format_read_string
|
||||
char current_character[2];
|
||||
snprintf(current_character, 2, "%c", barcode_char);
|
||||
|
||||
if(!flipper_format_read_string(ff, current_character, char_bits)) {
|
||||
FURI_LOG_E(TAG, "Could not read \"%c\" string", barcode_char);
|
||||
barcode_data->reason = InvalidCharacters;
|
||||
barcode_data->valid = false;
|
||||
break;
|
||||
} else {
|
||||
FURI_LOG_I(
|
||||
TAG, "\"%c\" string: %s", barcode_char, furi_string_get_cstr(char_bits));
|
||||
furi_string_cat(barcode_bits, char_bits);
|
||||
}
|
||||
flipper_format_rewind(ff);
|
||||
}
|
||||
furi_string_free(char_bits);
|
||||
}
|
||||
|
||||
//Close Storage
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_string_cat(barcode_data->correct_data, barcode_bits);
|
||||
furi_string_free(barcode_bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a code 128 barcode
|
||||
*
|
||||
* Only supports character set B
|
||||
*/
|
||||
void code_128_loader(BarcodeData* barcode_data) {
|
||||
int barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
//the start code for character set B
|
||||
int start_code_value = 104;
|
||||
|
||||
//The bits for the start code
|
||||
const char* start_code_bits = "11010010000";
|
||||
|
||||
//The bits for the stop code
|
||||
const char* stop_code_bits = "1100011101011";
|
||||
|
||||
int min_digits = barcode_data->type_obj->min_digits;
|
||||
|
||||
/**
|
||||
* A sum of all of the characters values
|
||||
* Ex:
|
||||
* Barcode Data : ABC
|
||||
* A has a value of 33
|
||||
* B has a value of 34
|
||||
* C has a value of 35
|
||||
*
|
||||
* the checksum_adder would be (33 * 1) + (34 * 2) + (35 * 3) + 104 = 310
|
||||
*
|
||||
* Add 104 since we are using set B
|
||||
*/
|
||||
int checksum_adder = start_code_value;
|
||||
/**
|
||||
* Checksum digits is the number of characters it has read so far
|
||||
* In the above example the checksum_digits would be 3
|
||||
*/
|
||||
int checksum_digits = 0;
|
||||
|
||||
//the calculated check digit
|
||||
int final_check_digit = 0;
|
||||
|
||||
//check the length of the barcode, must contain atleast a character,
|
||||
//this can have as many characters as it wants, it might not fit on the screen
|
||||
if(barcode_length < min_digits) {
|
||||
barcode_data->reason = WrongNumberOfDigits;
|
||||
barcode_data->valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
//Open Storage
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
||||
|
||||
FuriString* barcode_bits = furi_string_alloc();
|
||||
|
||||
//add the start code
|
||||
furi_string_cat(barcode_bits, start_code_bits);
|
||||
|
||||
if(!flipper_format_file_open_existing(ff, CODE128_DICT_FILE_PATH)) {
|
||||
FURI_LOG_E(TAG, "Could not open file %s", CODE128_DICT_FILE_PATH);
|
||||
barcode_data->reason = MissingEncodingTable;
|
||||
barcode_data->valid = false;
|
||||
} else {
|
||||
FuriString* value = furi_string_alloc();
|
||||
FuriString* char_bits = furi_string_alloc();
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
char barcode_char = furi_string_get_char(barcode_data->raw_data, i);
|
||||
|
||||
//convert a char into a string so it used in flipper_format_read_string
|
||||
char current_character[2];
|
||||
snprintf(current_character, 2, "%c", barcode_char);
|
||||
|
||||
//get the value of the character
|
||||
if(!flipper_format_read_string(ff, current_character, value)) {
|
||||
FURI_LOG_E(TAG, "Could not read \"%c\" string", barcode_char);
|
||||
barcode_data->reason = InvalidCharacters;
|
||||
barcode_data->valid = false;
|
||||
break;
|
||||
}
|
||||
//using the value of the character, get the characters bits
|
||||
if(!flipper_format_read_string(ff, furi_string_get_cstr(value), char_bits)) {
|
||||
FURI_LOG_E(TAG, "Could not read \"%c\" string", barcode_char);
|
||||
barcode_data->reason = EncodingTableError;
|
||||
barcode_data->valid = false;
|
||||
break;
|
||||
} else {
|
||||
//add the bits to the full barcode
|
||||
furi_string_cat(barcode_bits, char_bits);
|
||||
|
||||
//calculate the checksum
|
||||
checksum_digits += 1;
|
||||
checksum_adder += (atoi(furi_string_get_cstr(value)) * checksum_digits);
|
||||
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"\"%c\" string: %s : %s : %d : %d : %d",
|
||||
barcode_char,
|
||||
furi_string_get_cstr(char_bits),
|
||||
furi_string_get_cstr(value),
|
||||
checksum_digits,
|
||||
(atoi(furi_string_get_cstr(value)) * checksum_digits),
|
||||
checksum_adder);
|
||||
}
|
||||
//bring the file pointer back to the beginning
|
||||
flipper_format_rewind(ff);
|
||||
}
|
||||
|
||||
//calculate the check digit and convert it into a c string for lookup in the encoding table
|
||||
final_check_digit = checksum_adder % 103;
|
||||
int length = snprintf(NULL, 0, "%d", final_check_digit);
|
||||
char* final_check_digit_string = malloc(length + 1);
|
||||
snprintf(final_check_digit_string, length + 1, "%d", final_check_digit);
|
||||
|
||||
//after the checksum has been calculated, add the bits to the full barcode
|
||||
if(!flipper_format_read_string(ff, final_check_digit_string, char_bits)) {
|
||||
FURI_LOG_E(TAG, "Could not read \"%s\" string", final_check_digit_string);
|
||||
barcode_data->reason = EncodingTableError;
|
||||
barcode_data->valid = false;
|
||||
} else {
|
||||
//add the check digit bits to the full barcode
|
||||
furi_string_cat(barcode_bits, char_bits);
|
||||
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"\"%s\" string: %s",
|
||||
final_check_digit_string,
|
||||
furi_string_get_cstr(char_bits));
|
||||
}
|
||||
|
||||
free(final_check_digit_string);
|
||||
furi_string_free(value);
|
||||
furi_string_free(char_bits);
|
||||
}
|
||||
|
||||
//add the stop code
|
||||
furi_string_cat(barcode_bits, stop_code_bits);
|
||||
|
||||
//Close Storage
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_string_cat(barcode_data->correct_data, barcode_bits);
|
||||
furi_string_free(barcode_bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a code 128 C barcode
|
||||
*/
|
||||
void code_128c_loader(BarcodeData* barcode_data) {
|
||||
int barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
//the start code for character set C
|
||||
int start_code_value = 105;
|
||||
|
||||
//The bits for the start code
|
||||
const char* start_code_bits = "11010011100";
|
||||
|
||||
//The bits for the stop code
|
||||
const char* stop_code_bits = "1100011101011";
|
||||
|
||||
int min_digits = barcode_data->type_obj->min_digits;
|
||||
|
||||
int checksum_adder = start_code_value;
|
||||
int checksum_digits = 0;
|
||||
|
||||
//the calculated check digit
|
||||
int final_check_digit = 0;
|
||||
|
||||
// check the length of the barcode, must contain atleast 2 character,
|
||||
// this can have as many characters as it wants, it might not fit on the screen
|
||||
// code 128 C: the length must be even
|
||||
if((barcode_length < min_digits) || (barcode_length & 1)) {
|
||||
barcode_data->reason = WrongNumberOfDigits;
|
||||
barcode_data->valid = false;
|
||||
return;
|
||||
}
|
||||
//Open Storage
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
||||
|
||||
FuriString* barcode_bits = furi_string_alloc();
|
||||
|
||||
//add the start code
|
||||
furi_string_cat(barcode_bits, start_code_bits);
|
||||
|
||||
if(!flipper_format_file_open_existing(ff, CODE128C_DICT_FILE_PATH)) {
|
||||
FURI_LOG_E(TAG, "c128c Could not open file %s", CODE128C_DICT_FILE_PATH);
|
||||
barcode_data->reason = MissingEncodingTable;
|
||||
barcode_data->valid = false;
|
||||
} else {
|
||||
FuriString* value = furi_string_alloc();
|
||||
FuriString* char_bits = furi_string_alloc();
|
||||
for(int i = 0; i < barcode_length; i += 2) {
|
||||
char barcode_char1 = furi_string_get_char(barcode_data->raw_data, i);
|
||||
char barcode_char2 = furi_string_get_char(barcode_data->raw_data, i + 1);
|
||||
FURI_LOG_I(TAG, "c128c bc1='%c' bc2='%c'", barcode_char1, barcode_char2);
|
||||
|
||||
char current_chars[4];
|
||||
snprintf(current_chars, 3, "%c%c", barcode_char1, barcode_char2);
|
||||
FURI_LOG_I(TAG, "c128c current_chars='%s'", current_chars);
|
||||
|
||||
//using the value of the characters, get the characters bits
|
||||
if(!flipper_format_read_string(ff, current_chars, char_bits)) {
|
||||
FURI_LOG_E(TAG, "c128c Could not read \"%s\" string", current_chars);
|
||||
barcode_data->reason = EncodingTableError;
|
||||
barcode_data->valid = false;
|
||||
break;
|
||||
} else {
|
||||
//add the bits to the full barcode
|
||||
furi_string_cat(barcode_bits, char_bits);
|
||||
|
||||
// calculate the checksum
|
||||
checksum_digits += 1;
|
||||
checksum_adder += (atoi(current_chars) * checksum_digits);
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"c128c \"%s\" string: %s : %s : %d : %d : %d",
|
||||
current_chars,
|
||||
furi_string_get_cstr(char_bits),
|
||||
furi_string_get_cstr(value),
|
||||
checksum_digits,
|
||||
(atoi(furi_string_get_cstr(value)) * checksum_digits),
|
||||
checksum_adder);
|
||||
}
|
||||
//bring the file pointer back to the begining
|
||||
flipper_format_rewind(ff);
|
||||
}
|
||||
//calculate the check digit and convert it into a c string for lookup in the encoding table
|
||||
final_check_digit = checksum_adder % 103;
|
||||
FURI_LOG_I(TAG, "c128c finale_check_digit=%d", final_check_digit);
|
||||
|
||||
int length = snprintf(NULL, 0, "%d", final_check_digit);
|
||||
if(final_check_digit < 100) length = 2;
|
||||
char* final_check_digit_string = malloc(length + 1);
|
||||
snprintf(final_check_digit_string, length + 1, "%02d", final_check_digit);
|
||||
|
||||
//after the checksum has been calculated, add the bits to the full barcode
|
||||
if(!flipper_format_read_string(ff, final_check_digit_string, char_bits)) {
|
||||
FURI_LOG_E(TAG, "c128c cksum Could not read \"%s\" string", final_check_digit_string);
|
||||
barcode_data->reason = EncodingTableError;
|
||||
barcode_data->valid = false;
|
||||
} else {
|
||||
//add the check digit bits to the full barcode
|
||||
furi_string_cat(barcode_bits, char_bits);
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"check digit \"%s\" string: %s",
|
||||
final_check_digit_string,
|
||||
furi_string_get_cstr(char_bits));
|
||||
}
|
||||
|
||||
free(final_check_digit_string);
|
||||
furi_string_free(value);
|
||||
furi_string_free(char_bits);
|
||||
}
|
||||
|
||||
//add the stop code
|
||||
furi_string_cat(barcode_bits, stop_code_bits);
|
||||
|
||||
//Close Storage
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
FURI_LOG_I(TAG, "c128c %s", furi_string_get_cstr(barcode_bits));
|
||||
furi_string_cat(barcode_data->correct_data, barcode_bits);
|
||||
furi_string_free(barcode_bits);
|
||||
}
|
||||
|
||||
void codabar_loader(BarcodeData* barcode_data) {
|
||||
int barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
int min_digits = barcode_data->type_obj->min_digits;
|
||||
|
||||
//check the length of the barcode, must contain atleast a character,
|
||||
//this can have as many characters as it wants, it might not fit on the screen
|
||||
if(barcode_length < min_digits) {
|
||||
barcode_data->reason = WrongNumberOfDigits;
|
||||
barcode_data->valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
FuriString* barcode_bits = furi_string_alloc();
|
||||
|
||||
barcode_length = furi_string_size(barcode_data->raw_data);
|
||||
|
||||
//Open Storage
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
||||
|
||||
if(!flipper_format_file_open_existing(ff, CODABAR_DICT_FILE_PATH)) {
|
||||
FURI_LOG_E(TAG, "Could not open file %s", CODABAR_DICT_FILE_PATH);
|
||||
barcode_data->reason = MissingEncodingTable;
|
||||
barcode_data->valid = false;
|
||||
} else {
|
||||
FuriString* char_bits = furi_string_alloc();
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
char barcode_char = toupper(furi_string_get_char(barcode_data->raw_data, i));
|
||||
|
||||
//convert a char into a string so it used in flipper_format_read_string
|
||||
char current_character[2];
|
||||
snprintf(current_character, 2, "%c", barcode_char);
|
||||
|
||||
if(!flipper_format_read_string(ff, current_character, char_bits)) {
|
||||
FURI_LOG_E(TAG, "Could not read \"%c\" string", barcode_char);
|
||||
barcode_data->reason = InvalidCharacters;
|
||||
barcode_data->valid = false;
|
||||
break;
|
||||
} else {
|
||||
FURI_LOG_I(
|
||||
TAG, "\"%c\" string: %s", barcode_char, furi_string_get_cstr(char_bits));
|
||||
furi_string_cat(barcode_bits, char_bits);
|
||||
}
|
||||
flipper_format_rewind(ff);
|
||||
}
|
||||
furi_string_free(char_bits);
|
||||
}
|
||||
|
||||
//Close Storage
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_string_cat(barcode_data->correct_data, barcode_bits);
|
||||
furi_string_free(barcode_bits);
|
||||
}
|
15
applications/external/barcode_gen/barcode_validator.h
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "barcode_app.h"
|
||||
|
||||
int calculate_check_digit(BarcodeData* barcode_data);
|
||||
int calculate_ean_upc_check_digit(BarcodeData* barcode_data);
|
||||
void ean_upc_loader(BarcodeData* barcode_data);
|
||||
void upc_a_loader(BarcodeData* barcode_data);
|
||||
void ean_8_loader(BarcodeData* barcode_data);
|
||||
void ean_13_loader(BarcodeData* barcode_data);
|
||||
void code_39_loader(BarcodeData* barcode_data);
|
||||
void code_128_loader(BarcodeData* barcode_data);
|
||||
void code_128c_loader(BarcodeData* barcode_data);
|
||||
void codabar_loader(BarcodeData* barcode_data);
|
||||
void barcode_loader(BarcodeData* barcode_data);
|
52
applications/external/barcode_gen/encodings.c
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "encodings.h"
|
||||
|
||||
const char EAN_13_STRUCTURE_CODES[10][6] = {
|
||||
"LLLLLL",
|
||||
"LLGLGG",
|
||||
"LLGGLG",
|
||||
"LLGGGL",
|
||||
"LGLLGG",
|
||||
"LGGLLG",
|
||||
"LGGGLL",
|
||||
"LGLGLG",
|
||||
"LGLGGL",
|
||||
"LGGLGL"};
|
||||
|
||||
const char UPC_EAN_L_CODES[10][8] = {
|
||||
"0001101", // 0
|
||||
"0011001", // 1
|
||||
"0010011", // 2
|
||||
"0111101", // 3
|
||||
"0100011", // 4
|
||||
"0110001", // 5
|
||||
"0101111", // 6
|
||||
"0111011", // 7
|
||||
"0110111", // 8
|
||||
"0001011" // 9
|
||||
};
|
||||
|
||||
const char EAN_G_CODES[10][8] = {
|
||||
"0100111", // 0
|
||||
"0110011", // 1
|
||||
"0011011", // 2
|
||||
"0100001", // 3
|
||||
"0011101", // 4
|
||||
"0111001", // 5
|
||||
"0000101", // 6
|
||||
"0010001", // 7
|
||||
"0001001", // 8
|
||||
"0010111" // 9
|
||||
};
|
||||
|
||||
const char UPC_EAN_R_CODES[10][8] = {
|
||||
"1110010", // 0
|
||||
"1100110", // 1
|
||||
"1101100", // 2
|
||||
"1000010", // 3
|
||||
"1011100", // 4
|
||||
"1001110", // 5
|
||||
"1010000", // 6
|
||||
"1000100", // 7
|
||||
"1001000", // 8
|
||||
"1110100" // 9
|
||||
};
|
6
applications/external/barcode_gen/encodings.h
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
extern const char EAN_13_STRUCTURE_CODES[10][6];
|
||||
extern const char UPC_EAN_L_CODES[10][8];
|
||||
extern const char EAN_G_CODES[10][8];
|
||||
extern const char UPC_EAN_R_CODES[10][8];
|
BIN
applications/external/barcode_gen/images/barcode_10.png
vendored
Normal file
After Width: | Height: | Size: 161 B |
BIN
applications/external/barcode_gen/screenshots/Codabar Data Example.png
vendored
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
applications/external/barcode_gen/screenshots/Creating Barcode.png
vendored
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
applications/external/barcode_gen/screenshots/Flipper Barcode.png
vendored
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
applications/external/barcode_gen/screenshots/Flipper Box Barcode.png
vendored
Normal file
After Width: | Height: | Size: 1.3 KiB |
510
applications/external/barcode_gen/views/barcode_view.c
vendored
Normal file
|
@ -0,0 +1,510 @@
|
|||
#include "../barcode_app.h"
|
||||
#include "barcode_view.h"
|
||||
#include "../encodings.h"
|
||||
|
||||
/**
|
||||
* @brief Draws a single bit from a barcode at a specified location
|
||||
* @param canvas
|
||||
* @param bit a 1 or a 0 to signify a bit of data
|
||||
* @param x the top left x coordinate
|
||||
* @param y the top left y coordinate
|
||||
* @param width the width of the bit
|
||||
* @param height the height of the bit
|
||||
*/
|
||||
static void draw_bit(Canvas* canvas, int bit, int x, int y, int width, int height) {
|
||||
if(bit == 1) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
} else {
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
canvas_draw_box(canvas, x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static void draw_error_str(Canvas* canvas, const char* error) {
|
||||
canvas_clear(canvas);
|
||||
canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignCenter, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bits a string of 1's and 0's
|
||||
* @returns the x coordinate after the bits have been drawn, useful for drawing the next section of bits
|
||||
*/
|
||||
static int draw_bits(Canvas* canvas, const char* bits, int x, int y, int width, int height) {
|
||||
int bits_length = strlen(bits);
|
||||
for(int i = 0; i < bits_length; i++) {
|
||||
char c = bits[i];
|
||||
int num = c - '0';
|
||||
|
||||
draw_bit(canvas, num, x, y, width, height);
|
||||
|
||||
x += width;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an EAN-8 type barcode, does not check if the barcode is valid
|
||||
* @param canvas the canvas
|
||||
* @param barcode_digits the digits in the barcode, must be 8 characters long
|
||||
*/
|
||||
static void draw_ean_8(Canvas* canvas, BarcodeData* barcode_data) {
|
||||
FuriString* barcode_digits = barcode_data->correct_data;
|
||||
BarcodeTypeObj* type_obj = barcode_data->type_obj;
|
||||
|
||||
int barcode_length = furi_string_size(barcode_digits);
|
||||
|
||||
int x = type_obj->start_pos;
|
||||
int y = BARCODE_Y_START;
|
||||
int width = 1;
|
||||
int height = BARCODE_HEIGHT;
|
||||
|
||||
//the guard patterns for the beginning, center, ending
|
||||
const char* end_bits = "101";
|
||||
const char* center_bits = "01010";
|
||||
|
||||
//draw the starting guard pattern
|
||||
x = draw_bits(canvas, end_bits, x, y, width, height + 5);
|
||||
|
||||
FuriString* code_part = furi_string_alloc();
|
||||
|
||||
//loop through each digit, find the encoding, and draw it
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
char current_digit = furi_string_get_char(barcode_digits, i);
|
||||
|
||||
//the actual number and the index of the bits
|
||||
int index = current_digit - '0';
|
||||
//use the L-codes for the first 4 digits and the R-Codes for the last 4 digits
|
||||
if(i <= 3) {
|
||||
furi_string_set_str(code_part, UPC_EAN_L_CODES[index]);
|
||||
} else {
|
||||
furi_string_set_str(code_part, UPC_EAN_R_CODES[index]);
|
||||
}
|
||||
|
||||
//convert the current_digit char into a string so it can be printed
|
||||
char current_digit_string[2];
|
||||
snprintf(current_digit_string, 2, "%c", current_digit);
|
||||
|
||||
//set the canvas color to black to print the digit
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_str(canvas, x + 1, y + height + 8, current_digit_string);
|
||||
|
||||
//draw the bits of the barcode
|
||||
x = draw_bits(canvas, furi_string_get_cstr(code_part), x, y, width, height);
|
||||
|
||||
//if the index has reached 3, that means 4 digits have been drawn and now draw the center guard pattern
|
||||
if(i == 3) {
|
||||
x = draw_bits(canvas, center_bits, x, y, width, height + 5);
|
||||
}
|
||||
}
|
||||
furi_string_free(code_part);
|
||||
|
||||
//draw the ending guard pattern
|
||||
x = draw_bits(canvas, end_bits, x, y, width, height + 5);
|
||||
}
|
||||
|
||||
static void draw_ean_13(Canvas* canvas, BarcodeData* barcode_data) {
|
||||
FuriString* barcode_digits = barcode_data->correct_data;
|
||||
BarcodeTypeObj* type_obj = barcode_data->type_obj;
|
||||
|
||||
int barcode_length = furi_string_size(barcode_digits);
|
||||
|
||||
int x = type_obj->start_pos;
|
||||
int y = BARCODE_Y_START;
|
||||
int width = 1;
|
||||
int height = BARCODE_HEIGHT;
|
||||
|
||||
//the guard patterns for the beginning, center, ending
|
||||
const char* end_bits = "101";
|
||||
const char* center_bits = "01010";
|
||||
|
||||
//draw the starting guard pattern
|
||||
x = draw_bits(canvas, end_bits, x, y, width, height + 5);
|
||||
|
||||
FuriString* left_structure = furi_string_alloc();
|
||||
FuriString* code_part = furi_string_alloc();
|
||||
|
||||
//loop through each digit, find the encoding, and draw it
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
char current_digit = furi_string_get_char(barcode_digits, i);
|
||||
int index = current_digit - '0';
|
||||
|
||||
if(i == 0) {
|
||||
furi_string_set_str(left_structure, EAN_13_STRUCTURE_CODES[index]);
|
||||
|
||||
//convert the current_digit char into a string so it can be printed
|
||||
char current_digit_string[2];
|
||||
snprintf(current_digit_string, 2, "%c", current_digit);
|
||||
|
||||
//set the canvas color to black to print the digit
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_str(canvas, x - 10, y + height + 8, current_digit_string);
|
||||
|
||||
continue;
|
||||
} else {
|
||||
//use the L-codes for the first 6 digits and the R-Codes for the last 6 digits
|
||||
if(i <= 6) {
|
||||
//get the encoding type at the current barcode bit position
|
||||
char encoding_type = furi_string_get_char(left_structure, i - 1);
|
||||
if(encoding_type == 'L') {
|
||||
furi_string_set_str(code_part, UPC_EAN_L_CODES[index]);
|
||||
} else {
|
||||
furi_string_set_str(code_part, EAN_G_CODES[index]);
|
||||
}
|
||||
} else {
|
||||
furi_string_set_str(code_part, UPC_EAN_R_CODES[index]);
|
||||
}
|
||||
|
||||
//convert the current_digit char into a string so it can be printed
|
||||
char current_digit_string[2];
|
||||
snprintf(current_digit_string, 2, "%c", current_digit);
|
||||
|
||||
//set the canvas color to black to print the digit
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_str(canvas, x + 1, y + height + 8, current_digit_string);
|
||||
|
||||
//draw the bits of the barcode
|
||||
x = draw_bits(canvas, furi_string_get_cstr(code_part), x, y, width, height);
|
||||
|
||||
//if the index has reached 6, that means 6 digits have been drawn and we now draw the center guard pattern
|
||||
if(i == 6) {
|
||||
x = draw_bits(canvas, center_bits, x, y, width, height + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_free(left_structure);
|
||||
furi_string_free(code_part);
|
||||
|
||||
//draw the ending guard pattern
|
||||
x = draw_bits(canvas, end_bits, x, y, width, height + 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a UPC-A barcode
|
||||
*/
|
||||
static void draw_upc_a(Canvas* canvas, BarcodeData* barcode_data) {
|
||||
FuriString* barcode_digits = barcode_data->correct_data;
|
||||
BarcodeTypeObj* type_obj = barcode_data->type_obj;
|
||||
|
||||
int barcode_length = furi_string_size(barcode_digits);
|
||||
|
||||
int x = type_obj->start_pos;
|
||||
int y = BARCODE_Y_START;
|
||||
int width = 1;
|
||||
int height = BARCODE_HEIGHT;
|
||||
|
||||
//the guard patterns for the beginning, center, ending
|
||||
char* end_bits = "101";
|
||||
char* center_bits = "01010";
|
||||
|
||||
//draw the starting guard pattern
|
||||
x = draw_bits(canvas, end_bits, x, y, width, height + 5);
|
||||
|
||||
FuriString* code_part = furi_string_alloc();
|
||||
|
||||
//loop through each digit, find the encoding, and draw it
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
char current_digit = furi_string_get_char(barcode_digits, i);
|
||||
int index = current_digit - '0'; //convert the number into an int (also the index)
|
||||
|
||||
//use the L-codes for the first 6 digits and the R-Codes for the last 6 digits
|
||||
if(i <= 5) {
|
||||
furi_string_set_str(code_part, UPC_EAN_L_CODES[index]);
|
||||
} else {
|
||||
furi_string_set_str(code_part, UPC_EAN_R_CODES[index]);
|
||||
}
|
||||
|
||||
//convert the current_digit char into a string so it can be printed
|
||||
char current_digit_string[2];
|
||||
snprintf(current_digit_string, 2, "%c", current_digit);
|
||||
|
||||
//set the canvas color to black to print the digit
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_str(canvas, x + 1, y + height + 8, current_digit_string);
|
||||
|
||||
//draw the bits of the barcode
|
||||
x = draw_bits(canvas, furi_string_get_cstr(code_part), x, y, width, height);
|
||||
|
||||
//if the index has reached 6, that means 6 digits have been drawn and we now draw the center guard pattern
|
||||
if(i == 5) {
|
||||
x = draw_bits(canvas, center_bits, x, y, width, height + 5);
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_free(code_part);
|
||||
|
||||
//draw the ending guard pattern
|
||||
x = draw_bits(canvas, end_bits, x, y, width, height + 5);
|
||||
}
|
||||
|
||||
static void draw_code_39(Canvas* canvas, BarcodeData* barcode_data) {
|
||||
FuriString* raw_data = barcode_data->raw_data;
|
||||
FuriString* barcode_digits = barcode_data->correct_data;
|
||||
//BarcodeTypeObj* type_obj = barcode_data->type_obj;
|
||||
|
||||
int barcode_length = furi_string_size(barcode_digits);
|
||||
int total_pixels = 0;
|
||||
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
//1 for wide, 0 for narrow
|
||||
char wide_or_narrow = furi_string_get_char(barcode_digits, i);
|
||||
int wn_digit = wide_or_narrow - '0'; //wide(1) or narrow(0) digit
|
||||
|
||||
if(wn_digit == 1) {
|
||||
total_pixels += 3;
|
||||
} else {
|
||||
total_pixels += 1;
|
||||
}
|
||||
if((i + 1) % 9 == 0) {
|
||||
total_pixels += 1;
|
||||
}
|
||||
}
|
||||
|
||||
int x = (128 - total_pixels) / 2;
|
||||
int y = BARCODE_Y_START;
|
||||
int width = 1;
|
||||
int height = BARCODE_HEIGHT;
|
||||
bool filled_in = true;
|
||||
|
||||
//set the canvas color to black to print the digit
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
// canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignCenter, error);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 62, y + height + 8, AlignCenter, AlignBottom, furi_string_get_cstr(raw_data));
|
||||
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
//1 for wide, 0 for narrow
|
||||
char wide_or_narrow = furi_string_get_char(barcode_digits, i);
|
||||
int wn_digit = wide_or_narrow - '0'; //wide(1) or narrow(0) digit
|
||||
|
||||
if(filled_in) {
|
||||
if(wn_digit == 1) {
|
||||
x = draw_bits(canvas, "111", x, y, width, height);
|
||||
} else {
|
||||
x = draw_bits(canvas, "1", x, y, width, height);
|
||||
}
|
||||
filled_in = false;
|
||||
} else {
|
||||
if(wn_digit == 1) {
|
||||
x = draw_bits(canvas, "000", x, y, width, height);
|
||||
} else {
|
||||
x = draw_bits(canvas, "0", x, y, width, height);
|
||||
}
|
||||
filled_in = true;
|
||||
}
|
||||
if((i + 1) % 9 == 0) {
|
||||
x = draw_bits(canvas, "0", x, y, width, height);
|
||||
filled_in = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_code_128(Canvas* canvas, BarcodeData* barcode_data) {
|
||||
FuriString* raw_data = barcode_data->raw_data;
|
||||
FuriString* barcode_digits = barcode_data->correct_data;
|
||||
|
||||
int barcode_length = furi_string_size(barcode_digits);
|
||||
|
||||
int x = (128 - barcode_length) / 2;
|
||||
int y = BARCODE_Y_START;
|
||||
int width = 1;
|
||||
int height = BARCODE_HEIGHT;
|
||||
|
||||
x = draw_bits(canvas, furi_string_get_cstr(barcode_digits), x, y, width, height);
|
||||
|
||||
//set the canvas color to black to print the digit
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
// canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignCenter, error);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 62, y + height + 8, AlignCenter, AlignBottom, furi_string_get_cstr(raw_data));
|
||||
}
|
||||
|
||||
static void draw_codabar(Canvas* canvas, BarcodeData* barcode_data) {
|
||||
FuriString* raw_data = barcode_data->raw_data;
|
||||
FuriString* barcode_digits = barcode_data->correct_data;
|
||||
//BarcodeTypeObj* type_obj = barcode_data->type_obj;
|
||||
|
||||
int barcode_length = furi_string_size(barcode_digits);
|
||||
int total_pixels = 0;
|
||||
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
//1 for wide, 0 for narrow
|
||||
char wide_or_narrow = furi_string_get_char(barcode_digits, i);
|
||||
int wn_digit = wide_or_narrow - '0'; //wide(1) or narrow(0) digit
|
||||
|
||||
if(wn_digit == 1) {
|
||||
total_pixels += 3;
|
||||
} else {
|
||||
total_pixels += 1;
|
||||
}
|
||||
if((i + 1) % 7 == 0) {
|
||||
total_pixels += 1;
|
||||
}
|
||||
}
|
||||
|
||||
int x = (128 - total_pixels) / 2;
|
||||
int y = BARCODE_Y_START;
|
||||
int width = 1;
|
||||
int height = BARCODE_HEIGHT;
|
||||
bool filled_in = true;
|
||||
|
||||
//set the canvas color to black to print the digit
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
// canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignCenter, error);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 62, y + height + 8, AlignCenter, AlignBottom, furi_string_get_cstr(raw_data));
|
||||
|
||||
for(int i = 0; i < barcode_length; i++) {
|
||||
//1 for wide, 0 for narrow
|
||||
char wide_or_narrow = furi_string_get_char(barcode_digits, i);
|
||||
int wn_digit = wide_or_narrow - '0'; //wide(1) or narrow(0) digit
|
||||
|
||||
if(filled_in) {
|
||||
if(wn_digit == 1) {
|
||||
x = draw_bits(canvas, "111", x, y, width, height);
|
||||
} else {
|
||||
x = draw_bits(canvas, "1", x, y, width, height);
|
||||
}
|
||||
filled_in = false;
|
||||
} else {
|
||||
if(wn_digit == 1) {
|
||||
x = draw_bits(canvas, "000", x, y, width, height);
|
||||
} else {
|
||||
x = draw_bits(canvas, "0", x, y, width, height);
|
||||
}
|
||||
filled_in = true;
|
||||
}
|
||||
if((i + 1) % 7 == 0) {
|
||||
x = draw_bits(canvas, "0", x, y, width, height);
|
||||
filled_in = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void barcode_draw_callback(Canvas* canvas, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
BarcodeModel* barcode_model = ctx;
|
||||
BarcodeData* data = barcode_model->data;
|
||||
// const char* barcode_digits =;
|
||||
|
||||
canvas_clear(canvas);
|
||||
if(data->valid) {
|
||||
switch(data->type_obj->type) {
|
||||
case UPCA:
|
||||
draw_upc_a(canvas, data);
|
||||
break;
|
||||
case EAN8:
|
||||
draw_ean_8(canvas, data);
|
||||
break;
|
||||
case EAN13:
|
||||
draw_ean_13(canvas, data);
|
||||
break;
|
||||
case CODE39:
|
||||
draw_code_39(canvas, data);
|
||||
break;
|
||||
case CODE128:
|
||||
case CODE128C:
|
||||
draw_code_128(canvas, data);
|
||||
break;
|
||||
case CODABAR:
|
||||
draw_codabar(canvas, data);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch(data->reason) {
|
||||
case WrongNumberOfDigits:
|
||||
draw_error_str(canvas, "Wrong # of characters");
|
||||
break;
|
||||
case InvalidCharacters:
|
||||
draw_error_str(canvas, "Invalid characters");
|
||||
break;
|
||||
case UnsupportedType:
|
||||
draw_error_str(canvas, "Unsupported barcode type");
|
||||
break;
|
||||
case FileOpening:
|
||||
draw_error_str(canvas, "Could not open file");
|
||||
break;
|
||||
case InvalidFileData:
|
||||
draw_error_str(canvas, "Invalid file data");
|
||||
break;
|
||||
case MissingEncodingTable:
|
||||
draw_error_str(canvas, "Missing encoding table");
|
||||
break;
|
||||
case EncodingTableError:
|
||||
draw_error_str(canvas, "Encoding table error");
|
||||
break;
|
||||
default:
|
||||
draw_error_str(canvas, "Could not read barcode data");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool barcode_input_callback(InputEvent* input_event, void* ctx) {
|
||||
UNUSED(ctx);
|
||||
//furi_assert(ctx);
|
||||
|
||||
//Barcode* test_view_object = ctx;
|
||||
|
||||
if(input_event->key == InputKeyBack) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Barcode* barcode_view_allocate(BarcodeApp* barcode_app) {
|
||||
furi_assert(barcode_app);
|
||||
|
||||
Barcode* barcode = malloc(sizeof(Barcode));
|
||||
|
||||
barcode->view = view_alloc();
|
||||
barcode->barcode_app = barcode_app;
|
||||
|
||||
view_set_context(barcode->view, barcode);
|
||||
view_allocate_model(barcode->view, ViewModelTypeLocking, sizeof(BarcodeModel));
|
||||
view_set_draw_callback(barcode->view, barcode_draw_callback);
|
||||
view_set_input_callback(barcode->view, barcode_input_callback);
|
||||
|
||||
return barcode;
|
||||
}
|
||||
|
||||
void barcode_free_model(Barcode* barcode) {
|
||||
with_view_model(
|
||||
barcode->view,
|
||||
BarcodeModel * model,
|
||||
{
|
||||
if(model->file_path != NULL) {
|
||||
furi_string_free(model->file_path);
|
||||
}
|
||||
if(model->data != NULL) {
|
||||
if(model->data->raw_data != NULL) {
|
||||
furi_string_free(model->data->raw_data);
|
||||
}
|
||||
if(model->data->correct_data != NULL) {
|
||||
furi_string_free(model->data->correct_data);
|
||||
}
|
||||
free(model->data);
|
||||
}
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
void barcode_free(Barcode* barcode) {
|
||||
furi_assert(barcode);
|
||||
|
||||
barcode_free_model(barcode);
|
||||
view_free(barcode->view);
|
||||
free(barcode);
|
||||
}
|
||||
|
||||
View* barcode_get_view(Barcode* barcode) {
|
||||
furi_assert(barcode);
|
||||
return barcode->view;
|
||||
}
|
23
applications/external/barcode_gen/views/barcode_view.h
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef struct BarcodeApp BarcodeApp;
|
||||
|
||||
typedef struct {
|
||||
View* view;
|
||||
BarcodeApp* barcode_app;
|
||||
} Barcode;
|
||||
|
||||
typedef struct {
|
||||
FuriString* file_path;
|
||||
BarcodeData* data;
|
||||
} BarcodeModel;
|
||||
|
||||
Barcode* barcode_view_allocate(BarcodeApp* barcode_app);
|
||||
|
||||
void barcode_free_model(Barcode* barcode);
|
||||
|
||||
void barcode_free(Barcode* barcode);
|
||||
|
||||
View* barcode_get_view(Barcode* barcode);
|
494
applications/external/barcode_gen/views/create_view.c
vendored
Normal file
|
@ -0,0 +1,494 @@
|
|||
#include "../barcode_app.h"
|
||||
#include "create_view.h"
|
||||
#include <math.h>
|
||||
|
||||
#define LINE_HEIGHT 16
|
||||
#define TEXT_PADDING 4
|
||||
#define TOTAL_MENU_ITEMS 5
|
||||
|
||||
typedef enum {
|
||||
TypeMenuItem,
|
||||
FileNameMenuItem,
|
||||
BarcodeDataMenuItem,
|
||||
SaveMenuButton,
|
||||
DeleteMenuButton
|
||||
} MenuItems;
|
||||
|
||||
/**
|
||||
* Took this function from blackjack
|
||||
* @author @teeebor
|
||||
*/
|
||||
void draw_menu_item(
|
||||
Canvas* const canvas,
|
||||
const char* text,
|
||||
const char* value,
|
||||
int y,
|
||||
bool left_caret,
|
||||
bool right_caret,
|
||||
bool selected) {
|
||||
UNUSED(selected);
|
||||
if(y < 0 || y >= 64) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(selected) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, 0, y, 123, LINE_HEIGHT);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
|
||||
canvas_draw_str_aligned(canvas, 4, y + TEXT_PADDING, AlignLeft, AlignTop, text);
|
||||
if(left_caret) {
|
||||
canvas_draw_str_aligned(canvas, 60, y + TEXT_PADDING, AlignLeft, AlignTop, "<");
|
||||
}
|
||||
|
||||
canvas_draw_str_aligned(canvas, 90, y + TEXT_PADDING, AlignCenter, AlignTop, value);
|
||||
if(right_caret) {
|
||||
canvas_draw_str_aligned(canvas, 120, y + TEXT_PADDING, AlignRight, AlignTop, ">");
|
||||
}
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
|
||||
void draw_button(Canvas* const canvas, const char* text, int y, bool selected) {
|
||||
if(selected) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, 0, y, 123, LINE_HEIGHT);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
|
||||
canvas_draw_str_aligned(canvas, 64, y + TEXT_PADDING, AlignCenter, AlignTop, text);
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
|
||||
static void app_draw_callback(Canvas* canvas, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
|
||||
CreateViewModel* create_view_model = ctx;
|
||||
|
||||
BarcodeTypeObj* type_obj = create_view_model->barcode_type;
|
||||
if(create_view_model->barcode_type == NULL) {
|
||||
return;
|
||||
}
|
||||
BarcodeType selected_type = type_obj->type;
|
||||
|
||||
int selected_menu_item = create_view_model->selected_menu_item;
|
||||
|
||||
int total_menu_items = create_view_model->mode == EditMode ? TOTAL_MENU_ITEMS :
|
||||
TOTAL_MENU_ITEMS - 1;
|
||||
|
||||
int startY = 0;
|
||||
|
||||
//the menu items index that is/would be in view
|
||||
//int current_last_menu_item = selected_menu_item + 3;
|
||||
if(selected_menu_item > 1) {
|
||||
int offset = 2;
|
||||
if(selected_menu_item + offset > total_menu_items) {
|
||||
offset = 3;
|
||||
}
|
||||
startY -= (LINE_HEIGHT * (selected_menu_item - offset));
|
||||
}
|
||||
|
||||
//ensure that the scroll height is atleast 1
|
||||
int scrollHeight = ceil(64.0 / total_menu_items);
|
||||
int scrollPos = scrollHeight * selected_menu_item;
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
//draw the scroll bar box
|
||||
canvas_draw_box(canvas, 125, scrollPos, 3, scrollHeight);
|
||||
//draw the scroll bar track
|
||||
canvas_draw_box(canvas, 126, 0, 1, 64);
|
||||
|
||||
draw_menu_item(
|
||||
canvas,
|
||||
"Type",
|
||||
type_obj->name,
|
||||
TypeMenuItem * LINE_HEIGHT + startY,
|
||||
selected_type > 0,
|
||||
selected_type < NUMBER_OF_BARCODE_TYPES - 2,
|
||||
selected_menu_item == TypeMenuItem);
|
||||
|
||||
draw_menu_item(
|
||||
canvas,
|
||||
"Name",
|
||||
furi_string_empty(create_view_model->file_name) ?
|
||||
"--" :
|
||||
furi_string_get_cstr(create_view_model->file_name),
|
||||
FileNameMenuItem * LINE_HEIGHT + startY,
|
||||
false,
|
||||
false,
|
||||
selected_menu_item == FileNameMenuItem);
|
||||
|
||||
draw_menu_item(
|
||||
canvas,
|
||||
"Data",
|
||||
furi_string_empty(create_view_model->barcode_data) ?
|
||||
"--" :
|
||||
furi_string_get_cstr(create_view_model->barcode_data),
|
||||
BarcodeDataMenuItem * LINE_HEIGHT + startY,
|
||||
false,
|
||||
false,
|
||||
selected_menu_item == BarcodeDataMenuItem);
|
||||
|
||||
draw_button(
|
||||
canvas,
|
||||
"Save",
|
||||
SaveMenuButton * LINE_HEIGHT + startY,
|
||||
selected_menu_item == SaveMenuButton);
|
||||
|
||||
if(create_view_model->mode == EditMode) {
|
||||
draw_button(
|
||||
canvas,
|
||||
"Delete",
|
||||
DeleteMenuButton * LINE_HEIGHT + startY,
|
||||
selected_menu_item == DeleteMenuButton);
|
||||
}
|
||||
}
|
||||
|
||||
void text_input_callback(void* ctx) {
|
||||
CreateView* create_view_object = ctx;
|
||||
|
||||
with_view_model(
|
||||
create_view_object->view,
|
||||
CreateViewModel * model,
|
||||
{
|
||||
if(create_view_object->setter == FileNameSetter) {
|
||||
furi_string_set_str(model->file_name, create_view_object->input);
|
||||
}
|
||||
if(create_view_object->setter == BarcodeDataSetter) {
|
||||
furi_string_set_str(model->barcode_data, create_view_object->input);
|
||||
}
|
||||
},
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(
|
||||
create_view_object->barcode_app->view_dispatcher, CreateBarcodeView);
|
||||
}
|
||||
|
||||
static bool app_input_callback(InputEvent* input_event, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
|
||||
if(input_event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CreateView* create_view_object = ctx;
|
||||
|
||||
//get the currently selected menu item from the model
|
||||
int selected_menu_item = 0;
|
||||
BarcodeTypeObj* barcode_type = NULL;
|
||||
FuriString* file_name;
|
||||
FuriString* barcode_data;
|
||||
CreateMode mode;
|
||||
|
||||
with_view_model(
|
||||
create_view_object->view,
|
||||
CreateViewModel * model,
|
||||
{
|
||||
selected_menu_item = model->selected_menu_item;
|
||||
barcode_type = model->barcode_type;
|
||||
file_name = model->file_name;
|
||||
barcode_data = model->barcode_data;
|
||||
mode = model->mode;
|
||||
},
|
||||
true);
|
||||
|
||||
int total_menu_items = mode == EditMode ? TOTAL_MENU_ITEMS : TOTAL_MENU_ITEMS - 1;
|
||||
|
||||
if(input_event->type == InputTypePress) {
|
||||
if(input_event->key == InputKeyUp && selected_menu_item > 0) {
|
||||
selected_menu_item--;
|
||||
} else if(input_event->key == InputKeyDown && selected_menu_item < total_menu_items - 1) {
|
||||
selected_menu_item++;
|
||||
} else if(input_event->key == InputKeyLeft) {
|
||||
if(selected_menu_item == TypeMenuItem && barcode_type != NULL) { //Select Barcode Type
|
||||
if(barcode_type->type > 0) {
|
||||
barcode_type = barcode_type_objs[barcode_type->type - 1];
|
||||
}
|
||||
}
|
||||
} else if(input_event->key == InputKeyRight) {
|
||||
if(selected_menu_item == TypeMenuItem && barcode_type != NULL) { //Select Barcode Type
|
||||
if(barcode_type->type < NUMBER_OF_BARCODE_TYPES - 2) {
|
||||
barcode_type = barcode_type_objs[barcode_type->type + 1];
|
||||
}
|
||||
}
|
||||
} else if(input_event->key == InputKeyOk) {
|
||||
if(selected_menu_item == FileNameMenuItem && barcode_type != NULL) {
|
||||
create_view_object->setter = FileNameSetter;
|
||||
|
||||
snprintf(
|
||||
create_view_object->input,
|
||||
sizeof(create_view_object->input),
|
||||
"%s",
|
||||
furi_string_get_cstr(file_name));
|
||||
|
||||
text_input_set_result_callback(
|
||||
create_view_object->barcode_app->text_input,
|
||||
text_input_callback,
|
||||
create_view_object,
|
||||
create_view_object->input,
|
||||
TEXT_BUFFER_SIZE - BARCODE_EXTENSION_LENGTH, //remove the barcode length
|
||||
//clear default text
|
||||
false);
|
||||
text_input_set_header_text(
|
||||
create_view_object->barcode_app->text_input, "File Name");
|
||||
|
||||
view_dispatcher_switch_to_view(
|
||||
create_view_object->barcode_app->view_dispatcher, TextInputView);
|
||||
}
|
||||
if(selected_menu_item == BarcodeDataMenuItem && barcode_type != NULL) {
|
||||
create_view_object->setter = BarcodeDataSetter;
|
||||
|
||||
snprintf(
|
||||
create_view_object->input,
|
||||
sizeof(create_view_object->input),
|
||||
"%s",
|
||||
furi_string_get_cstr(barcode_data));
|
||||
|
||||
text_input_set_result_callback(
|
||||
create_view_object->barcode_app->text_input,
|
||||
text_input_callback,
|
||||
create_view_object,
|
||||
create_view_object->input,
|
||||
TEXT_BUFFER_SIZE,
|
||||
//clear default text
|
||||
false);
|
||||
text_input_set_header_text(
|
||||
create_view_object->barcode_app->text_input, "Barcode Data");
|
||||
|
||||
view_dispatcher_switch_to_view(
|
||||
create_view_object->barcode_app->view_dispatcher, TextInputView);
|
||||
}
|
||||
if(selected_menu_item == SaveMenuButton && barcode_type != NULL) {
|
||||
save_barcode(create_view_object);
|
||||
}
|
||||
if(selected_menu_item == DeleteMenuButton && barcode_type != NULL) {
|
||||
if(mode == EditMode) {
|
||||
remove_barcode(create_view_object);
|
||||
} else if(mode == NewMode) {
|
||||
view_dispatcher_switch_to_view(
|
||||
create_view_object->barcode_app->view_dispatcher, MainMenuView);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//change the currently selected menu item
|
||||
with_view_model(
|
||||
create_view_object->view,
|
||||
CreateViewModel * model,
|
||||
{
|
||||
model->selected_menu_item = selected_menu_item;
|
||||
model->barcode_type = barcode_type;
|
||||
},
|
||||
true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CreateView* create_view_allocate(BarcodeApp* barcode_app) {
|
||||
furi_assert(barcode_app);
|
||||
|
||||
CreateView* create_view_object = malloc(sizeof(CreateView));
|
||||
|
||||
create_view_object->view = view_alloc();
|
||||
create_view_object->barcode_app = barcode_app;
|
||||
|
||||
view_set_context(create_view_object->view, create_view_object);
|
||||
view_allocate_model(create_view_object->view, ViewModelTypeLocking, sizeof(CreateViewModel));
|
||||
view_set_draw_callback(create_view_object->view, app_draw_callback);
|
||||
view_set_input_callback(create_view_object->view, app_input_callback);
|
||||
|
||||
return create_view_object;
|
||||
}
|
||||
|
||||
void create_view_free_model(CreateView* create_view_object) {
|
||||
with_view_model(
|
||||
create_view_object->view,
|
||||
CreateViewModel * model,
|
||||
{
|
||||
if(model->file_path != NULL) {
|
||||
furi_string_free(model->file_path);
|
||||
}
|
||||
if(model->file_name != NULL) {
|
||||
furi_string_free(model->file_name);
|
||||
}
|
||||
if(model->barcode_data != NULL) {
|
||||
furi_string_free(model->barcode_data);
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void remove_barcode(CreateView* create_view_object) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
bool success = false;
|
||||
|
||||
with_view_model(
|
||||
create_view_object->view,
|
||||
CreateViewModel * model,
|
||||
{
|
||||
FURI_LOG_I(TAG, "Attempting to remove file");
|
||||
if(model->file_path != NULL) {
|
||||
FURI_LOG_I(TAG, "Removing File: %s", furi_string_get_cstr(model->file_path));
|
||||
if(storage_simply_remove(storage, furi_string_get_cstr(model->file_path))) {
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"File: \"%s\" was successfully removed",
|
||||
furi_string_get_cstr(model->file_path));
|
||||
success = true;
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Unable to remove file!");
|
||||
success = false;
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Could not remove barcode file");
|
||||
success = false;
|
||||
}
|
||||
},
|
||||
true);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
with_view_model(
|
||||
create_view_object->barcode_app->message_view->view,
|
||||
MessageViewModel * model,
|
||||
{
|
||||
if(success) {
|
||||
model->message = "File Deleted";
|
||||
} else {
|
||||
model->message = "Could not delete file";
|
||||
}
|
||||
},
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(
|
||||
create_view_object->barcode_app->view_dispatcher, MessageErrorView);
|
||||
}
|
||||
|
||||
void save_barcode(CreateView* create_view_object) {
|
||||
BarcodeTypeObj* barcode_type = NULL;
|
||||
FuriString* file_path; //this may be empty
|
||||
FuriString* file_name;
|
||||
FuriString* barcode_data;
|
||||
CreateMode mode;
|
||||
|
||||
with_view_model(
|
||||
create_view_object->view,
|
||||
CreateViewModel * model,
|
||||
{
|
||||
file_path = model->file_path;
|
||||
file_name = model->file_name;
|
||||
barcode_data = model->barcode_data;
|
||||
barcode_type = model->barcode_type;
|
||||
mode = model->mode;
|
||||
},
|
||||
true);
|
||||
|
||||
if(file_name == NULL || furi_string_empty(file_name)) {
|
||||
FURI_LOG_E(TAG, "File Name cannot be empty");
|
||||
return;
|
||||
}
|
||||
if(barcode_data == NULL || furi_string_empty(barcode_data)) {
|
||||
FURI_LOG_E(TAG, "Barcode Data cannot be empty");
|
||||
return;
|
||||
}
|
||||
if(barcode_type == NULL) {
|
||||
FURI_LOG_E(TAG, "Type not defined");
|
||||
return;
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
|
||||
FuriString* full_file_path = furi_string_alloc_set(DEFAULT_USER_BARCODES);
|
||||
furi_string_push_back(full_file_path, '/');
|
||||
furi_string_cat(full_file_path, file_name);
|
||||
furi_string_cat_str(full_file_path, BARCODE_EXTENSION);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
if(mode == EditMode) {
|
||||
if(!furi_string_empty(file_path)) {
|
||||
if(!furi_string_equal(file_path, full_file_path)) {
|
||||
FS_Error error = storage_common_rename(
|
||||
storage,
|
||||
furi_string_get_cstr(file_path),
|
||||
furi_string_get_cstr(full_file_path));
|
||||
if(error != FSE_OK) {
|
||||
FURI_LOG_E(TAG, "Rename error: %s", storage_error_get_desc(error));
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "Rename Success");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
||||
|
||||
FURI_LOG_I(TAG, "Saving Barcode to: %s", furi_string_get_cstr(full_file_path));
|
||||
|
||||
bool file_opened_status = false;
|
||||
if(mode == NewMode) {
|
||||
file_opened_status =
|
||||
flipper_format_file_open_new(ff, furi_string_get_cstr(full_file_path));
|
||||
} else if(mode == EditMode) {
|
||||
file_opened_status =
|
||||
flipper_format_file_open_always(ff, furi_string_get_cstr(full_file_path));
|
||||
}
|
||||
|
||||
if(file_opened_status) {
|
||||
// Filetype: Barcode
|
||||
// Version: 1
|
||||
|
||||
// # Types - UPC-A, EAN-8, EAN-13, CODE-39
|
||||
// Type: CODE-39
|
||||
// Data: AB
|
||||
flipper_format_write_string_cstr(ff, "Filetype", "Barcode");
|
||||
|
||||
flipper_format_write_string_cstr(ff, "Version", FILE_VERSION);
|
||||
|
||||
flipper_format_write_comment_cstr(
|
||||
ff, "Types - UPC-A, EAN-8, EAN-13, CODE-39, CODE-128, Codabar");
|
||||
|
||||
flipper_format_write_string_cstr(ff, "Type", barcode_type->name);
|
||||
|
||||
flipper_format_write_string_cstr(ff, "Data", furi_string_get_cstr(barcode_data));
|
||||
|
||||
success = true;
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Save error");
|
||||
success = false;
|
||||
}
|
||||
furi_string_free(full_file_path);
|
||||
flipper_format_free(ff);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
with_view_model(
|
||||
create_view_object->barcode_app->message_view->view,
|
||||
MessageViewModel * model,
|
||||
{
|
||||
if(success) {
|
||||
model->message = "File Saved!";
|
||||
} else {
|
||||
model->message = "A saving error has occurred";
|
||||
}
|
||||
},
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(
|
||||
create_view_object->barcode_app->view_dispatcher, MessageErrorView);
|
||||
}
|
||||
|
||||
void create_view_free(CreateView* create_view_object) {
|
||||
furi_assert(create_view_object);
|
||||
|
||||
create_view_free_model(create_view_object);
|
||||
view_free(create_view_object->view);
|
||||
free(create_view_object);
|
||||
}
|
||||
|
||||
View* create_get_view(CreateView* create_view_object) {
|
||||
furi_assert(create_view_object);
|
||||
return create_view_object->view;
|
||||
}
|
46
applications/external/barcode_gen/views/create_view.h
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef struct BarcodeApp BarcodeApp;
|
||||
|
||||
typedef enum {
|
||||
FileNameSetter,
|
||||
BarcodeDataSetter
|
||||
} InputSetter; //what value to set for the text input view
|
||||
|
||||
typedef enum {
|
||||
EditMode,
|
||||
|
||||
NewMode
|
||||
} CreateMode;
|
||||
|
||||
typedef struct {
|
||||
View* view;
|
||||
BarcodeApp* barcode_app;
|
||||
|
||||
InputSetter setter;
|
||||
char input[TEXT_BUFFER_SIZE];
|
||||
} CreateView;
|
||||
|
||||
typedef struct {
|
||||
int selected_menu_item;
|
||||
|
||||
CreateMode mode;
|
||||
BarcodeTypeObj* barcode_type;
|
||||
FuriString* file_path; //the current file that is opened
|
||||
FuriString* file_name;
|
||||
FuriString* barcode_data;
|
||||
} CreateViewModel;
|
||||
|
||||
CreateView* create_view_allocate(BarcodeApp* barcode_app);
|
||||
|
||||
void remove_barcode(CreateView* create_view_object);
|
||||
|
||||
void save_barcode(CreateView* create_view_object);
|
||||
|
||||
void create_view_free_model(CreateView* create_view_object);
|
||||
|
||||
void create_view_free(CreateView* create_view_object);
|
||||
|
||||
View* create_get_view(CreateView* create_view_object);
|
66
applications/external/barcode_gen/views/message_view.c
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "../barcode_app.h"
|
||||
#include "message_view.h"
|
||||
|
||||
static void app_draw_callback(Canvas* canvas, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
|
||||
MessageViewModel* message_view_model = ctx;
|
||||
|
||||
canvas_clear(canvas);
|
||||
if(message_view_model->message != NULL) {
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 62, 30, AlignCenter, AlignCenter, message_view_model->message);
|
||||
}
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, 100, 52, 28, 12);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_str_aligned(canvas, 114, 58, AlignCenter, AlignCenter, "OK");
|
||||
}
|
||||
|
||||
static bool app_input_callback(InputEvent* input_event, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
|
||||
MessageView* message_view_object = ctx;
|
||||
|
||||
if(input_event->key == InputKeyBack) {
|
||||
view_dispatcher_switch_to_view(
|
||||
message_view_object->barcode_app->view_dispatcher, MainMenuView);
|
||||
}
|
||||
if(input_event->type == InputTypeShort) {
|
||||
if(input_event->key == InputKeyOk) {
|
||||
view_dispatcher_switch_to_view(
|
||||
message_view_object->barcode_app->view_dispatcher, MainMenuView);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
MessageView* message_view_allocate(BarcodeApp* barcode_app) {
|
||||
furi_assert(barcode_app);
|
||||
|
||||
MessageView* message_view_object = malloc(sizeof(MessageView));
|
||||
|
||||
message_view_object->view = view_alloc();
|
||||
message_view_object->barcode_app = barcode_app;
|
||||
|
||||
view_set_context(message_view_object->view, message_view_object);
|
||||
view_allocate_model(message_view_object->view, ViewModelTypeLocking, sizeof(MessageViewModel));
|
||||
view_set_draw_callback(message_view_object->view, app_draw_callback);
|
||||
view_set_input_callback(message_view_object->view, app_input_callback);
|
||||
|
||||
return message_view_object;
|
||||
}
|
||||
|
||||
void message_view_free(MessageView* message_view_object) {
|
||||
furi_assert(message_view_object);
|
||||
|
||||
view_free(message_view_object->view);
|
||||
free(message_view_object);
|
||||
}
|
||||
|
||||
View* message_get_view(MessageView* message_view_object) {
|
||||
furi_assert(message_view_object);
|
||||
return message_view_object->view;
|
||||
}
|
22
applications/external/barcode_gen/views/message_view.h
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef struct BarcodeApp BarcodeApp;
|
||||
|
||||
typedef struct {
|
||||
View* view;
|
||||
BarcodeApp* barcode_app;
|
||||
} MessageView;
|
||||
|
||||
typedef struct {
|
||||
const char* message;
|
||||
} MessageViewModel;
|
||||
|
||||
MessageView* message_view_allocate(BarcodeApp* barcode_app);
|
||||
|
||||
void message_view_free_model(MessageView* message_view_object);
|
||||
|
||||
void message_view_free(MessageView* message_view_object);
|
||||
|
||||
View* message_get_view(MessageView* message_view_object);
|
|
@ -1,17 +0,0 @@
|
|||
App(
|
||||
appid="barcode_generator",
|
||||
name="Barcode Generator",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="barcode_generator_app",
|
||||
requires=[
|
||||
"gui",
|
||||
"dialogs",
|
||||
],
|
||||
stack_size=1 * 1024,
|
||||
order=50,
|
||||
fap_icon="barcode_10px.png",
|
||||
fap_category="Misc",
|
||||
fap_author="@xMasterX & @msvsergey & @McAzzaMan",
|
||||
fap_version="1.0",
|
||||
fap_description="App displays Barcode on flipper screen and allows to edit it",
|
||||
)
|
Before Width: | Height: | Size: 2.3 KiB |
|
@ -1,447 +0,0 @@
|
|||
#include "barcode_generator.h"
|
||||
|
||||
static BarcodeType* barcodeTypes[NUMBER_OF_BARCODE_TYPES];
|
||||
|
||||
void init_types() {
|
||||
BarcodeType* upcA = malloc(sizeof(BarcodeType));
|
||||
upcA->name = "UPC-A";
|
||||
upcA->numberOfDigits = 12;
|
||||
upcA->startPos = 19;
|
||||
upcA->bartype = BarTypeUPCA;
|
||||
barcodeTypes[0] = upcA;
|
||||
|
||||
BarcodeType* ean8 = malloc(sizeof(BarcodeType));
|
||||
ean8->name = "EAN-8";
|
||||
ean8->numberOfDigits = 8;
|
||||
ean8->startPos = 33;
|
||||
ean8->bartype = BarTypeEAN8;
|
||||
barcodeTypes[1] = ean8;
|
||||
|
||||
BarcodeType* ean13 = malloc(sizeof(BarcodeType));
|
||||
ean13->name = "EAN-13";
|
||||
ean13->numberOfDigits = 13;
|
||||
ean13->startPos = 19;
|
||||
ean13->bartype = BarTypeEAN13;
|
||||
barcodeTypes[2] = ean13;
|
||||
}
|
||||
|
||||
void draw_digit(
|
||||
Canvas* canvas,
|
||||
int digit,
|
||||
BarEncodingType rightHand,
|
||||
int startingPosition,
|
||||
bool drawlines) {
|
||||
char digitStr[2];
|
||||
snprintf(digitStr, 2, "%u", digit);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_str(
|
||||
canvas, startingPosition, BARCODE_Y_START + BARCODE_HEIGHT + BARCODE_TEXT_OFFSET, digitStr);
|
||||
|
||||
if(drawlines) {
|
||||
switch(rightHand) {
|
||||
case BarEncodingTypeLeft:
|
||||
case BarEncodingTypeRight:
|
||||
canvas_set_color(
|
||||
canvas, (rightHand == BarEncodingTypeRight) ? ColorBlack : ColorWhite);
|
||||
//int count = 0;
|
||||
for(int i = 0; i < 4; i++) {
|
||||
canvas_draw_box(
|
||||
canvas, startingPosition, BARCODE_Y_START, DIGITS[digit][i], BARCODE_HEIGHT);
|
||||
canvas_invert_color(canvas);
|
||||
startingPosition += DIGITS[digit][i];
|
||||
}
|
||||
break;
|
||||
case BarEncodingTypeG:
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
//int count = 0;
|
||||
for(int i = 3; i >= 0; i--) {
|
||||
canvas_draw_box(
|
||||
canvas, startingPosition, BARCODE_Y_START, DIGITS[digit][i], BARCODE_HEIGHT);
|
||||
canvas_invert_color(canvas);
|
||||
startingPosition += DIGITS[digit][i];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int get_digit_position(int index, BarcodeType* type) {
|
||||
int pos = 0;
|
||||
switch(type->bartype) {
|
||||
case BarTypeEAN8:
|
||||
case BarTypeUPCA:
|
||||
pos = type->startPos + index * 7;
|
||||
if(index >= type->numberOfDigits / 2) {
|
||||
pos += 5;
|
||||
}
|
||||
break;
|
||||
case BarTypeEAN13:
|
||||
if(index == 0)
|
||||
pos = type->startPos - 10;
|
||||
else {
|
||||
pos = type->startPos + (index - 1) * 7;
|
||||
if((index - 1) >= type->numberOfDigits / 2) {
|
||||
pos += 5;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
int get_menu_text_location(int index) {
|
||||
return 20 + 10 * index;
|
||||
}
|
||||
|
||||
int get_barcode_max_index(PluginState* plugin_state) {
|
||||
return plugin_state->barcode_state.doParityCalculation ?
|
||||
barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]->numberOfDigits - 1 :
|
||||
barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]->numberOfDigits;
|
||||
}
|
||||
|
||||
int calculate_check_digit(PluginState* plugin_state, BarcodeType* type) {
|
||||
int checkDigit = 0;
|
||||
int checkDigitOdd = 0;
|
||||
int checkDigitEven = 0;
|
||||
//add all odd positions. Confusing because 0index
|
||||
for(int i = 0; i < type->numberOfDigits - 1; i += 2) {
|
||||
checkDigitOdd += plugin_state->barcode_state.barcodeNumeral[i];
|
||||
}
|
||||
|
||||
//add all even positions to above. Confusing because 0index
|
||||
for(int i = 1; i < type->numberOfDigits - 1; i += 2) {
|
||||
checkDigitEven += plugin_state->barcode_state.barcodeNumeral[i];
|
||||
}
|
||||
|
||||
if(type->bartype == BarTypeEAN13) {
|
||||
checkDigit = checkDigitEven * 3 + checkDigitOdd;
|
||||
} else {
|
||||
checkDigit = checkDigitOdd * 3 + checkDigitEven;
|
||||
}
|
||||
|
||||
checkDigit = checkDigit % 10; //mod 10
|
||||
|
||||
//if m = 0 then x12 = 0, otherwise x12 is 10 - m
|
||||
return (10 - checkDigit) % 10;
|
||||
}
|
||||
|
||||
static void render_callback(Canvas* const canvas, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
PluginState* plugin_state = ctx;
|
||||
furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
|
||||
|
||||
if(plugin_state->mode == MenuMode) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_str_aligned(canvas, 64, 6, AlignCenter, AlignCenter, "MENU");
|
||||
canvas_draw_frame(canvas, 50, 0, 29, 11); //box around Menu
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, get_menu_text_location(0), AlignCenter, AlignCenter, "View");
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, get_menu_text_location(1), AlignCenter, AlignCenter, "Edit");
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 64, get_menu_text_location(2), AlignCenter, AlignCenter, "Parity?");
|
||||
|
||||
canvas_draw_frame(canvas, 83, get_menu_text_location(2) - 3, 6, 6);
|
||||
if(plugin_state->barcode_state.doParityCalculation == true) {
|
||||
canvas_draw_box(canvas, 85, get_menu_text_location(2) - 1, 2, 2);
|
||||
}
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
64,
|
||||
get_menu_text_location(3),
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
(barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex])->name);
|
||||
canvas_draw_disc(
|
||||
canvas,
|
||||
40,
|
||||
get_menu_text_location(plugin_state->menuIndex) - 1,
|
||||
2); //draw menu cursor
|
||||
} else {
|
||||
BarcodeType* type = barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex];
|
||||
|
||||
//start saftey
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, type->startPos - 3, BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
|
||||
canvas_draw_box(canvas, (type->startPos - 1), BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
|
||||
|
||||
int startpos = 0;
|
||||
int endpos = type->numberOfDigits;
|
||||
if(type->bartype == BarTypeEAN13) {
|
||||
startpos++;
|
||||
draw_digit(
|
||||
canvas,
|
||||
plugin_state->barcode_state.barcodeNumeral[0],
|
||||
BarEncodingTypeRight,
|
||||
get_digit_position(0, barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]),
|
||||
false);
|
||||
}
|
||||
if(plugin_state->barcode_state.doParityCalculation) { //calculate the check digit
|
||||
plugin_state->barcode_state.barcodeNumeral[type->numberOfDigits - 1] =
|
||||
calculate_check_digit(plugin_state, type);
|
||||
}
|
||||
for(int index = startpos; index < endpos; index++) {
|
||||
BarEncodingType barEncodingType = BarEncodingTypeLeft;
|
||||
if(type->bartype == BarTypeEAN13) {
|
||||
if(index - 1 >= (type->numberOfDigits - 1) / 2) {
|
||||
barEncodingType = BarEncodingTypeRight;
|
||||
} else {
|
||||
barEncodingType =
|
||||
(FURI_BIT(
|
||||
EAN13ENCODE[plugin_state->barcode_state.barcodeNumeral[0]],
|
||||
index - 1)) ?
|
||||
BarEncodingTypeG :
|
||||
BarEncodingTypeLeft;
|
||||
}
|
||||
} else {
|
||||
if(index >= type->numberOfDigits / 2) {
|
||||
barEncodingType = BarEncodingTypeRight;
|
||||
}
|
||||
}
|
||||
|
||||
int digitPosition = get_digit_position(
|
||||
index, barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]);
|
||||
draw_digit(
|
||||
canvas,
|
||||
plugin_state->barcode_state.barcodeNumeral[index],
|
||||
barEncodingType,
|
||||
digitPosition,
|
||||
true);
|
||||
}
|
||||
|
||||
//central separator
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, 62, BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
|
||||
canvas_draw_box(canvas, 64, BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
|
||||
|
||||
if(plugin_state->mode == EditMode) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(
|
||||
canvas,
|
||||
get_digit_position(
|
||||
plugin_state->editingIndex,
|
||||
barcodeTypes[plugin_state->barcode_state.barcodeTypeIndex]) -
|
||||
1,
|
||||
63,
|
||||
7,
|
||||
1); //draw editing cursor
|
||||
}
|
||||
|
||||
//end safety
|
||||
int endSafetyPosition = get_digit_position(type->numberOfDigits - 1, type) + 7;
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, endSafetyPosition, BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
|
||||
canvas_draw_box(canvas, (endSafetyPosition + 2), BARCODE_Y_START, 1, BARCODE_HEIGHT + 2);
|
||||
}
|
||||
|
||||
furi_mutex_release(plugin_state->mutex);
|
||||
}
|
||||
|
||||
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||
furi_assert(event_queue);
|
||||
|
||||
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
|
||||
static void barcode_generator_state_init(PluginState* plugin_state) {
|
||||
plugin_state->editingIndex = 0;
|
||||
plugin_state->mode = ViewMode;
|
||||
plugin_state->menuIndex = MENU_INDEX_VIEW;
|
||||
if(!LOAD_BARCODE_SETTINGS(&plugin_state->barcode_state)) {
|
||||
for(int i = 0; i < BARCODE_MAX_LENS; ++i) {
|
||||
plugin_state->barcode_state.barcodeNumeral[i] = i % 10;
|
||||
}
|
||||
plugin_state->barcode_state.doParityCalculation = true;
|
||||
plugin_state->barcode_state.barcodeTypeIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static bool handle_key_press_view(InputKey key, PluginState* plugin_state) {
|
||||
switch(key) {
|
||||
case InputKeyOk:
|
||||
case InputKeyBack:
|
||||
plugin_state->mode = MenuMode;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool handle_key_press_edit(InputKey key, PluginState* plugin_state) {
|
||||
int barcodeMaxIndex = get_barcode_max_index(plugin_state);
|
||||
|
||||
switch(key) {
|
||||
case InputKeyUp:
|
||||
plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] =
|
||||
(plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] + 1) % 10;
|
||||
break;
|
||||
|
||||
case InputKeyDown:
|
||||
plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] =
|
||||
(plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] == 0) ?
|
||||
9 :
|
||||
plugin_state->barcode_state.barcodeNumeral[plugin_state->editingIndex] - 1;
|
||||
break;
|
||||
|
||||
case InputKeyRight:
|
||||
plugin_state->editingIndex = (plugin_state->editingIndex + 1) % barcodeMaxIndex;
|
||||
break;
|
||||
|
||||
case InputKeyLeft:
|
||||
plugin_state->editingIndex = (plugin_state->editingIndex == 0) ?
|
||||
barcodeMaxIndex - 1 :
|
||||
plugin_state->editingIndex - 1;
|
||||
break;
|
||||
|
||||
case InputKeyOk:
|
||||
case InputKeyBack:
|
||||
plugin_state->mode = MenuMode;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool handle_key_press_menu(InputKey key, PluginState* plugin_state) {
|
||||
switch(key) {
|
||||
case InputKeyUp:
|
||||
plugin_state->menuIndex = (plugin_state->menuIndex == MENU_INDEX_VIEW) ?
|
||||
MENU_INDEX_TYPE :
|
||||
plugin_state->menuIndex - 1;
|
||||
break;
|
||||
|
||||
case InputKeyDown:
|
||||
plugin_state->menuIndex = (plugin_state->menuIndex + 1) % 4;
|
||||
break;
|
||||
|
||||
case InputKeyRight:
|
||||
if(plugin_state->menuIndex == MENU_INDEX_TYPE) {
|
||||
plugin_state->barcode_state.barcodeTypeIndex =
|
||||
(plugin_state->barcode_state.barcodeTypeIndex == NUMBER_OF_BARCODE_TYPES - 1) ?
|
||||
0 :
|
||||
plugin_state->barcode_state.barcodeTypeIndex + 1;
|
||||
} else if(plugin_state->menuIndex == MENU_INDEX_PARITY) {
|
||||
plugin_state->barcode_state.doParityCalculation =
|
||||
!plugin_state->barcode_state.doParityCalculation;
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(plugin_state->menuIndex == MENU_INDEX_TYPE) {
|
||||
plugin_state->barcode_state.barcodeTypeIndex =
|
||||
(plugin_state->barcode_state.barcodeTypeIndex == 0) ?
|
||||
NUMBER_OF_BARCODE_TYPES - 1 :
|
||||
plugin_state->barcode_state.barcodeTypeIndex - 1;
|
||||
} else if(plugin_state->menuIndex == MENU_INDEX_PARITY) {
|
||||
plugin_state->barcode_state.doParityCalculation =
|
||||
!plugin_state->barcode_state.doParityCalculation;
|
||||
}
|
||||
break;
|
||||
|
||||
case InputKeyOk:
|
||||
if(plugin_state->menuIndex == MENU_INDEX_VIEW) {
|
||||
plugin_state->mode = ViewMode;
|
||||
} else if(plugin_state->menuIndex == MENU_INDEX_EDIT) {
|
||||
plugin_state->mode = EditMode;
|
||||
} else if(plugin_state->menuIndex == MENU_INDEX_PARITY) {
|
||||
plugin_state->barcode_state.doParityCalculation =
|
||||
!plugin_state->barcode_state.doParityCalculation;
|
||||
} else if(plugin_state->menuIndex == MENU_INDEX_TYPE) {
|
||||
plugin_state->barcode_state.barcodeTypeIndex =
|
||||
(plugin_state->barcode_state.barcodeTypeIndex == NUMBER_OF_BARCODE_TYPES - 1) ?
|
||||
0 :
|
||||
plugin_state->barcode_state.barcodeTypeIndex + 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case InputKeyBack:
|
||||
return false;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
int barcodeMaxIndex = get_barcode_max_index(plugin_state);
|
||||
if(plugin_state->editingIndex >= barcodeMaxIndex)
|
||||
plugin_state->editingIndex = barcodeMaxIndex - 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t barcode_generator_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
init_types();
|
||||
|
||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
||||
|
||||
PluginState* plugin_state = malloc(sizeof(PluginState));
|
||||
barcode_generator_state_init(plugin_state);
|
||||
|
||||
plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
if(!plugin_state->mutex) {
|
||||
FURI_LOG_E("barcode_generator", "cannot create mutex\r\n");
|
||||
furi_message_queue_free(event_queue);
|
||||
free(plugin_state);
|
||||
return 255;
|
||||
}
|
||||
|
||||
// Set system callbacks
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, render_callback, plugin_state);
|
||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||
|
||||
// Open GUI and register view_port
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
PluginEvent event;
|
||||
for(bool processing = true; processing;) {
|
||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||
furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
|
||||
|
||||
if(event_status == FuriStatusOk) {
|
||||
// press events
|
||||
if(event.type == EventTypeKey &&
|
||||
((event.input.type == InputTypePress) || (event.input.type == InputTypeRepeat))) {
|
||||
switch(plugin_state->mode) {
|
||||
case ViewMode:
|
||||
processing = handle_key_press_view(event.input.key, plugin_state);
|
||||
break;
|
||||
case EditMode:
|
||||
processing = handle_key_press_edit(event.input.key, plugin_state);
|
||||
break;
|
||||
case MenuMode:
|
||||
processing = handle_key_press_menu(event.input.key, plugin_state);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view_port_update(view_port);
|
||||
furi_mutex_release(plugin_state->mutex);
|
||||
}
|
||||
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
furi_record_close(RECORD_GUI);
|
||||
view_port_free(view_port);
|
||||
furi_message_queue_free(event_queue);
|
||||
furi_mutex_free(plugin_state->mutex);
|
||||
// save settings
|
||||
SAVE_BARCODE_SETTINGS(&plugin_state->barcode_state);
|
||||
free(plugin_state);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
#include <stdlib.h>
|
||||
#include <storage/storage.h>
|
||||
#include <toolbox/saved_struct.h>
|
||||
|
||||
#define BARCODE_SETTINGS_FILE_NAME "apps/Misc/barcodegen.save"
|
||||
|
||||
#define BARCODE_SETTINGS_VER (1)
|
||||
#define BARCODE_SETTINGS_PATH EXT_PATH(BARCODE_SETTINGS_FILE_NAME)
|
||||
#define BARCODE_SETTINGS_MAGIC (0xC2)
|
||||
|
||||
#define SAVE_BARCODE_SETTINGS(x) \
|
||||
saved_struct_save( \
|
||||
BARCODE_SETTINGS_PATH, \
|
||||
(x), \
|
||||
sizeof(BarcodeState), \
|
||||
BARCODE_SETTINGS_MAGIC, \
|
||||
BARCODE_SETTINGS_VER)
|
||||
|
||||
#define LOAD_BARCODE_SETTINGS(x) \
|
||||
saved_struct_load( \
|
||||
BARCODE_SETTINGS_PATH, \
|
||||
(x), \
|
||||
sizeof(BarcodeState), \
|
||||
BARCODE_SETTINGS_MAGIC, \
|
||||
BARCODE_SETTINGS_VER)
|
||||
|
||||
#define BARCODE_HEIGHT 50
|
||||
#define BARCODE_Y_START 3
|
||||
#define BARCODE_TEXT_OFFSET 9
|
||||
#define BARCODE_MAX_LENS 13
|
||||
#define NUMBER_OF_BARCODE_TYPES 3
|
||||
#define MENU_INDEX_VIEW 0
|
||||
#define MENU_INDEX_EDIT 1
|
||||
#define MENU_INDEX_PARITY 2
|
||||
#define MENU_INDEX_TYPE 3
|
||||
|
||||
typedef enum {
|
||||
EventTypeTick,
|
||||
EventTypeKey,
|
||||
} EventType;
|
||||
|
||||
typedef struct {
|
||||
EventType type;
|
||||
InputEvent input;
|
||||
} PluginEvent;
|
||||
|
||||
typedef enum {
|
||||
ViewMode,
|
||||
EditMode,
|
||||
MenuMode,
|
||||
} Mode;
|
||||
|
||||
typedef enum {
|
||||
BarEncodingTypeLeft,
|
||||
BarEncodingTypeRight,
|
||||
BarEncodingTypeG,
|
||||
} BarEncodingType;
|
||||
|
||||
typedef enum {
|
||||
BarTypeEAN8,
|
||||
BarTypeUPCA,
|
||||
BarTypeEAN13,
|
||||
} BarType;
|
||||
|
||||
typedef struct {
|
||||
char* name;
|
||||
int numberOfDigits;
|
||||
int startPos;
|
||||
BarType bartype;
|
||||
} BarcodeType;
|
||||
|
||||
typedef struct {
|
||||
int barcodeNumeral[BARCODE_MAX_LENS]; //The current barcode number
|
||||
bool doParityCalculation; //Should do parity check?
|
||||
int barcodeTypeIndex;
|
||||
} BarcodeState;
|
||||
|
||||
typedef struct {
|
||||
FuriMutex* mutex;
|
||||
BarcodeState barcode_state;
|
||||
int editingIndex; //The index of the editing symbol
|
||||
int menuIndex; //The index of the menu cursor
|
||||
Mode mode; //View, edit or menu
|
||||
} PluginState;
|
||||
|
||||
static const int DIGITS[10][4] = {
|
||||
{3, 2, 1, 1},
|
||||
{2, 2, 2, 1},
|
||||
{2, 1, 2, 2},
|
||||
{1, 4, 1, 1},
|
||||
{1, 1, 3, 2},
|
||||
{1, 2, 3, 1},
|
||||
{1, 1, 1, 4},
|
||||
{1, 3, 1, 2},
|
||||
{1, 2, 1, 3},
|
||||
{3, 1, 1, 2},
|
||||
};
|
||||
|
||||
static const uint8_t EAN13ENCODE[10] = {
|
||||
0b000000,
|
||||
0b110100,
|
||||
0b101100,
|
||||
0b011100,
|
||||
0b110010,
|
||||
0b100110,
|
||||
0b001110,
|
||||
0b101010,
|
||||
0b011010,
|
||||
0b010110,
|
||||
};
|
|
@ -5,7 +5,6 @@
|
|||
#include <input/input.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <gui/canvas_i.h>
|
||||
#include "bomberduck_icons.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
|
|
Before Width: | Height: | Size: 113 B After Width: | Height: | Size: 113 B |
Before Width: | Height: | Size: 116 B After Width: | Height: | Size: 116 B |
Before Width: | Height: | Size: 116 B After Width: | Height: | Size: 116 B |
22
applications/external/flappy_bird/flappy_bird.c
vendored
|
@ -3,7 +3,6 @@
|
|||
#include <flappy_bird_icons.h>
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/icon_animation_i.h>
|
||||
#include <input/input.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
|
@ -30,6 +29,14 @@ typedef enum {
|
|||
EventTypeKey,
|
||||
} EventType;
|
||||
|
||||
typedef enum { BirdState0 = 0, BirdState1, BirdState2, BirdStateMAX } BirdState;
|
||||
|
||||
const Icon* bird_states[BirdStateMAX] = {
|
||||
&I_bird_01,
|
||||
&I_bird_02,
|
||||
&I_bird_03,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
|
@ -38,7 +45,6 @@ typedef struct {
|
|||
typedef struct {
|
||||
float gravity;
|
||||
POINT point;
|
||||
IconAnimation* sprite;
|
||||
} BIRD;
|
||||
|
||||
typedef struct {
|
||||
|
@ -93,7 +99,6 @@ static void flappy_game_state_init(GameState* const game_state) {
|
|||
bird.gravity = 0.0f;
|
||||
bird.point.x = 15;
|
||||
bird.point.y = 32;
|
||||
bird.sprite = icon_animation_alloc(&A_bird);
|
||||
|
||||
game_state->debug = DEBUG;
|
||||
game_state->bird = bird;
|
||||
|
@ -106,7 +111,6 @@ static void flappy_game_state_init(GameState* const game_state) {
|
|||
}
|
||||
|
||||
static void flappy_game_state_free(GameState* const game_state) {
|
||||
icon_animation_free(game_state->bird.sprite);
|
||||
free(game_state);
|
||||
}
|
||||
|
||||
|
@ -224,14 +228,14 @@ static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
|
|||
}
|
||||
|
||||
// Switch animation
|
||||
game_state->bird.sprite->frame = 1;
|
||||
BirdState bird_state = BirdState1;
|
||||
if(game_state->bird.gravity < -0.5)
|
||||
game_state->bird.sprite->frame = 0;
|
||||
bird_state = BirdState0;
|
||||
else if(game_state->bird.gravity > 0.5)
|
||||
game_state->bird.sprite->frame = 2;
|
||||
bird_state = BirdState2;
|
||||
|
||||
canvas_draw_icon_animation(
|
||||
canvas, game_state->bird.point.x, game_state->bird.point.y, game_state->bird.sprite);
|
||||
canvas_draw_icon(
|
||||
canvas, game_state->bird.point.x, game_state->bird.point.y, bird_states[bird_state]);
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
char buffer[12];
|
||||
|
|
674
applications/external/flipper_i2ctools/LICENSE
vendored
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -1,5 +1,5 @@
|
|||
App(
|
||||
appid="i2c_tools",
|
||||
appid="i2ctools",
|
||||
name="[GPIO] i2c Tools",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="i2ctools_app",
|
||||
|
@ -10,6 +10,6 @@ App(
|
|||
fap_category="GPIO",
|
||||
fap_icon_assets="images",
|
||||
fap_author="@NaejEL",
|
||||
fap_version="1.0",
|
||||
fap_version="1.1",
|
||||
fap_description="Set of i2c tools",
|
||||
)
|
|
@ -22,6 +22,10 @@ void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
|
|||
draw_sender_view(canvas, i2ctools->sender);
|
||||
break;
|
||||
|
||||
case INFOS_VIEW:
|
||||
draw_infos_view(canvas);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "views/sniffer_view.h"
|
||||
#include "views/scanner_view.h"
|
||||
#include "views/sender_view.h"
|
||||
#include "views/infos_view.h"
|
||||
|
||||
// App datas
|
||||
typedef struct {
|
||||
|
|
BIN
applications/external/flipper_i2ctools/images/Voltage_16x16.png
vendored
Normal file
After Width: | Height: | Size: 294 B |
15
applications/external/flipper_i2ctools/views/infos_view.c
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "infos_view.h"
|
||||
|
||||
void draw_infos_view(Canvas* canvas) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, "Wiring: ");
|
||||
canvas_draw_str_aligned(canvas, 43, 3, AlignLeft, AlignTop, "C0->SCL");
|
||||
canvas_draw_str_aligned(canvas, 43, 13, AlignLeft, AlignTop, "C1->SDA");
|
||||
canvas_draw_str_aligned(canvas, 43, 23, AlignLeft, AlignTop, "GND->GND");
|
||||
canvas_draw_icon(canvas, 15, 33, &I_Voltage_16x16);
|
||||
canvas_draw_str_aligned(canvas, 30, 38, AlignLeft, AlignTop, "Only use 3v3 levels");
|
||||
}
|
8
applications/external/flipper_i2ctools/views/infos_view.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <i2ctools_icons.h>
|
||||
|
||||
#define INFOS_TEXT "INFOS"
|
||||
|
||||
void draw_infos_view(Canvas* canvas);
|
|
@ -14,6 +14,8 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
|
|||
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, INFOS_MENU_X, INFOS_MENU_Y, AlignLeft, AlignTop, INFOS_MENU_TEXT);
|
||||
canvas_draw_rbox(canvas, 80, SCAN_MENU_Y - 2, 43, 13, 3);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_str_aligned(
|
||||
|
@ -26,6 +28,8 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
|
|||
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, INFOS_MENU_X, INFOS_MENU_Y, AlignLeft, AlignTop, INFOS_MENU_TEXT);
|
||||
canvas_draw_rbox(canvas, 80, SNIFF_MENU_Y - 2, 43, 13, 3);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_str_aligned(
|
||||
|
@ -38,12 +42,28 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
|
|||
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, INFOS_MENU_X, INFOS_MENU_Y, AlignLeft, AlignTop, INFOS_MENU_TEXT);
|
||||
canvas_draw_rbox(canvas, 80, SEND_MENU_Y - 2, 43, 13, 3);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
|
||||
break;
|
||||
|
||||
case INFOS_VIEW:
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
|
||||
canvas_draw_rbox(canvas, 80, INFOS_MENU_Y - 2, 43, 13, 3);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, INFOS_MENU_X, INFOS_MENU_Y, AlignLeft, AlignTop, INFOS_MENU_TEXT);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <i2c_tools_icons.h>
|
||||
#include <i2ctools_icons.h>
|
||||
#define APP_NAME "I2C Tools"
|
||||
|
||||
#define SCAN_MENU_TEXT "Scan"
|
||||
#define SCAN_MENU_X 90
|
||||
#define SCAN_MENU_Y 13
|
||||
#define SCAN_MENU_Y 7
|
||||
|
||||
#define SNIFF_MENU_TEXT "Sniff"
|
||||
#define SNIFF_MENU_X 90
|
||||
#define SNIFF_MENU_Y 27
|
||||
#define SNIFF_MENU_Y 21
|
||||
|
||||
#define SEND_MENU_TEXT "Send"
|
||||
#define SEND_MENU_X 90
|
||||
#define SEND_MENU_Y 41
|
||||
#define SEND_MENU_Y 35
|
||||
|
||||
#define INFOS_MENU_TEXT "Infos"
|
||||
#define INFOS_MENU_X 90
|
||||
#define INFOS_MENU_Y 49
|
||||
|
||||
// Menu
|
||||
typedef enum {
|
||||
|
@ -22,6 +26,7 @@ typedef enum {
|
|||
SCAN_VIEW,
|
||||
SNIFF_VIEW,
|
||||
SEND_VIEW,
|
||||
INFOS_VIEW,
|
||||
|
||||
/* Know menu Size*/
|
||||
MENU_SIZE
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <i2c_tools_icons.h>
|
||||
#include <i2ctools_icons.h>
|
||||
#include "../i2cscanner.h"
|
||||
|
||||
#define SCAN_TEXT "SCAN"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <i2c_tools_icons.h>
|
||||
#include <i2ctools_icons.h>
|
||||
#include "../i2csender.h"
|
||||
|
||||
#define SEND_TEXT "SEND"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <i2c_tools_icons.h>
|
||||
#include <i2ctools_icons.h>
|
||||
#include "../i2csniffer.h"
|
||||
|
||||
#define SNIFF_TEXT "SNIFF"
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <input/input.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <gui/canvas_i.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
#define Y_FIELD_SIZE 6
|
||||
|
|
|
@ -10,7 +10,7 @@ App(
|
|||
stack_size=2 * 1024,
|
||||
order=20,
|
||||
fap_icon="icons/hex_10px.png",
|
||||
fap_category="Misc",
|
||||
fap_category="Tools",
|
||||
fap_icon_assets="icons",
|
||||
fap_author="@QtRoS",
|
||||
fap_version="1.0",
|
||||
|
|
|
@ -4,7 +4,7 @@ App(
|
|||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="hid_usb_app",
|
||||
stack_size=1 * 1024,
|
||||
fap_category="Misc",
|
||||
fap_category="USB",
|
||||
fap_icon="hid_usb_10px.png",
|
||||
fap_icon_assets="assets",
|
||||
fap_icon_assets_symbol="hid",
|
||||
|
@ -17,7 +17,7 @@ App(
|
|||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="hid_ble_app",
|
||||
stack_size=1 * 1024,
|
||||
fap_category="Misc",
|
||||
fap_category="Bluetooth",
|
||||
fap_icon="hid_ble_10px.png",
|
||||
fap_icon_assets="assets",
|
||||
fap_icon_assets_symbol="hid",
|
||||
|
|
|
@ -7,7 +7,7 @@ App(
|
|||
requires=["gui"],
|
||||
stack_size=2 * 1024,
|
||||
fap_icon="ir_scope.png",
|
||||
fap_category="Tools",
|
||||
fap_category="Infrared",
|
||||
fap_author="@kallanreed",
|
||||
fap_version="1.0",
|
||||
fap_description="App allows to see incoming IR signals.",
|
||||
|
|
15
applications/external/jetpack_joyride/application.fam
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
# For details & more options, see documentation/AppManifests.md in firmware repo
|
||||
|
||||
App(
|
||||
appid="jetpack_joyride",
|
||||
name="Jetpack Joyride",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="jetpack_game_app",
|
||||
cdefines=["APP_JETPACK_GAME"],
|
||||
requires=["gui"],
|
||||
stack_size=4 * 1024,
|
||||
order=100,
|
||||
fap_icon="icon.png",
|
||||
fap_category="Games",
|
||||
fap_icon_assets="assets",
|
||||
)
|
BIN
applications/external/jetpack_joyride/assets/air_vent.png
vendored
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
applications/external/jetpack_joyride/assets/alert/frame_01.png
vendored
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
applications/external/jetpack_joyride/assets/alert/frame_02.png
vendored
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
applications/external/jetpack_joyride/assets/barry/frame_01.png
vendored
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
applications/external/jetpack_joyride/assets/barry/frame_02.png
vendored
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
applications/external/jetpack_joyride/assets/barry/frame_03.png
vendored
Normal file
After Width: | Height: | Size: 1.9 KiB |
1
applications/external/jetpack_joyride/assets/barry/frame_rate
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
3
|
BIN
applications/external/jetpack_joyride/assets/barry_infill.png
vendored
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
applications/external/jetpack_joyride/assets/bg1.png
vendored
Normal file
After Width: | Height: | Size: 835 B |
BIN
applications/external/jetpack_joyride/assets/bg2.png
vendored
Normal file
After Width: | Height: | Size: 968 B |
BIN
applications/external/jetpack_joyride/assets/bg3.png
vendored
Normal file
After Width: | Height: | Size: 886 B |
BIN
applications/external/jetpack_joyride/assets/coin.png
vendored
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
applications/external/jetpack_joyride/assets/coin_infill.png
vendored
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
applications/external/jetpack_joyride/assets/dead_scientist.png
vendored
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
applications/external/jetpack_joyride/assets/dead_scientist_infill.png
vendored
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
applications/external/jetpack_joyride/assets/door.png
vendored
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
applications/external/jetpack_joyride/assets/missile/frame_01.png
vendored
Normal file
After Width: | Height: | Size: 1.9 KiB |