acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

SSTV.h (5770B)

      1 #if !defined(_RADIOLIB_RADIOLIB_SSTV_H)
      2 #define _RADIOLIB_RADIOLIB_SSTV_H
      3 
      4 #include "../../TypeDef.h"
      5 
      6 #if !defined(RADIOLIB_EXCLUDE_SSTV)
      7 
      8 #include "../PhysicalLayer/PhysicalLayer.h"
      9 #include "../AFSK/AFSK.h"
     10 
     11 // the following implementation is based on information from
     12 // http://www.barberdsp.com/downloads/Dayton%20Paper.pdf
     13 
     14 // VIS codes
     15 #define RADIOLIB_SSTV_SCOTTIE_1                                 60
     16 #define RADIOLIB_SSTV_SCOTTIE_2                                 56
     17 #define RADIOLIB_SSTV_SCOTTIE_DX                                76
     18 #define RADIOLIB_SSTV_MARTIN_1                                  44
     19 #define RADIOLIB_SSTV_MARTIN_2                                  40
     20 #define RADIOLIB_SSTV_WRASSE_SC2_180                            55
     21 #define RADIOLIB_SSTV_PASOKON_P3                                113
     22 #define RADIOLIB_SSTV_PASOKON_P5                                114
     23 #define RADIOLIB_SSTV_PASOKON_P7                                115
     24 
     25 // SSTV tones in Hz
     26 #define RADIOLIB_SSTV_TONE_LEADER                               1900
     27 #define RADIOLIB_SSTV_TONE_BREAK                                1200
     28 #define RADIOLIB_SSTV_TONE_VIS_1                                1100
     29 #define RADIOLIB_SSTV_TONE_VIS_0                                1300
     30 #define RADIOLIB_SSTV_TONE_BRIGHTNESS_MIN                       1500
     31 #define RADIOLIB_SSTV_TONE_BRIGHTNESS_MAX                       2300
     32 
     33 // calibration header timing in us
     34 #define RADIOLIB_SSTV_HEADER_LEADER_LENGTH                      300000
     35 #define RADIOLIB_SSTV_HEADER_BREAK_LENGTH                       10000
     36 #define RADIOLIB_SSTV_HEADER_BIT_LENGTH                         30000
     37 
     38 /*!
     39   \struct tone_t
     40 
     41   \brief Structure to save data about tone.
     42 */
     43 struct tone_t {
     44 
     45   /*!
     46     \brief Tone type: GENERIC for sync and porch tones, SCAN_GREEN, SCAN_BLUE and SCAN_RED for scan lines.
     47   */
     48   enum {
     49     GENERIC = 0,
     50     SCAN_GREEN,
     51     SCAN_BLUE,
     52     SCAN_RED
     53   } type;
     54 
     55   /*!
     56     \brief Length of tone in us, set to 0 for picture scan tones.
     57   */
     58   uint32_t len;
     59 
     60   /*!
     61     \brief Frequency of tone in Hz, set to 0 for picture scan tones.
     62   */
     63   uint16_t freq;
     64 };
     65 
     66 /*!
     67   \struct SSTVMode_t
     68 
     69   \brief Structure to save data about supported SSTV modes.
     70 */
     71 struct SSTVMode_t {
     72 
     73   /*!
     74     \brief Unique VIS code of the SSTV mode.
     75   */
     76   uint8_t visCode;
     77 
     78   /*!
     79     \brief Picture width in pixels.
     80   */
     81   uint16_t width;
     82 
     83   /*!
     84     \brief Picture height in pixels.
     85   */
     86   uint16_t height;
     87 
     88   /*!
     89     \brief Pixel scan length in us.
     90   */
     91   uint16_t scanPixelLen;
     92 
     93   /*!
     94     \brief Number of tones in each transmission line. Picture scan data is considered single tone.
     95   */
     96   uint8_t numTones;
     97 
     98   /*!
     99     \brief Sequence of tones in each transmission line. This is used to create the correct encoding sequence.
    100   */
    101   tone_t tones[8];
    102 };
    103 
    104 // all currently supported SSTV modes
    105 extern const SSTVMode_t Scottie1;
    106 extern const SSTVMode_t Scottie2;
    107 extern const SSTVMode_t ScottieDX;
    108 extern const SSTVMode_t Martin1;
    109 extern const SSTVMode_t Martin2;
    110 extern const SSTVMode_t Wrasse;
    111 extern const SSTVMode_t PasokonP3;
    112 extern const SSTVMode_t PasokonP5;
    113 extern const SSTVMode_t PasokonP7;
    114 
    115 /*!
    116   \class SSTVClient
    117 
    118   \brief Client for SSTV transmissions.
    119 */
    120 class SSTVClient {
    121   public:
    122     /*!
    123       \brief Constructor for 2-FSK mode.
    124 
    125       \param phy Pointer to the wireless module providing PhysicalLayer communication.
    126     */
    127     explicit SSTVClient(PhysicalLayer* phy);
    128 
    129     #if !defined(RADIOLIB_EXCLUDE_AFSK)
    130     /*!
    131       \brief Constructor for AFSK mode.
    132 
    133       \param audio Pointer to the AFSK instance providing audio.
    134     */
    135     explicit SSTVClient(AFSKClient* audio);
    136     #endif
    137 
    138     // basic methods
    139 
    140     /*!
    141       \brief Initialization method for 2-FSK.
    142 
    143       \param base Base "0 Hz tone" RF frequency to be used in MHz.
    144 
    145       \param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7.
    146 
    147       \param correction Timing correction factor, used to adjust the length of timing pulses. Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction).
    148 
    149       \returns \ref status_codes
    150     */
    151     int16_t begin(float base, const SSTVMode_t& mode, float correction = 1.0);
    152 
    153     #if !defined(RADIOLIB_EXCLUDE_AFSK)
    154     /*!
    155       \brief Initialization method for AFSK.
    156 
    157       \param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7.
    158 
    159       \param correction Timing correction factor, used to adjust the length of timing pulses. Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction).
    160 
    161       \returns \ref status_codes
    162     */
    163     int16_t begin(const SSTVMode_t& mode, float correction = 1.0);
    164     #endif
    165 
    166     /*!
    167       \brief Sends out tone at 1900 Hz.
    168     */
    169     void idle();
    170 
    171     /*!
    172       \brief Sends synchronization header for the SSTV mode set in begin method.
    173     */
    174     void sendHeader();
    175 
    176     /*!
    177       \brief Sends single picture line in the currently configured SSTV mode.
    178 
    179       \param imgLine Image line to send, in 24-bit RGB. It is up to the user to ensure that imgLine has enough pixels to send it in the current SSTV mode.
    180     */
    181     void sendLine(uint32_t* imgLine);
    182 
    183     /*!
    184       \brief Get picture height of the currently configured SSTV mode.
    185 
    186       \returns Picture height of the currently configured SSTV mode in pixels.
    187     */
    188     uint16_t getPictureHeight() const;
    189 
    190 #if !defined(RADIOLIB_GODMODE)
    191   private:
    192 #endif
    193     PhysicalLayer* _phy;
    194     #if !defined(RADIOLIB_EXCLUDE_AFSK)
    195     AFSKClient* _audio;
    196     #endif
    197 
    198     uint32_t _base = 0;
    199     SSTVMode_t _mode = Scottie1;
    200     bool _firstLine = true;
    201 
    202     void tone(float freq, uint32_t len = 0);
    203 };
    204 
    205 #endif
    206 
    207 #endif