Commit 337f7df7 authored by Martin Cífka's avatar Martin Cífka
Browse files

Code comments & refactoring

parent a535583b
Loading
Loading
Loading
Loading
Loading
+4.19 KiB (9.38 MiB)

File changed.

No diff preview for this file type.

+2 −0
Original line number Diff line number Diff line
@@ -7,10 +7,12 @@ using namespace std;

int Codes::getSpeedMs(Speed speed)
{
    // at least 1 second
    if ((int)speed < 32768)
    {
        return 1000*(int)speed;
    }
    // subseconds speeds
    else
    {
        return 1000/((int)speed-32768);
+78 −31
Original line number Diff line number Diff line
@@ -5,9 +5,16 @@
#include <algorithm>
#include <vector>

/**
 * Class containing various constant (and related functions) used for comunication with camera
 */
class Codes
{
public:

    /**
     * Message ID constant
     */
    enum class MsgId
    {
        GetToken = 257,
@@ -39,6 +46,10 @@ public:

    };


    /**
     * Camera's state parameter constant
     */
    enum class ParamCameraState
    {
        Idle = 0,
@@ -55,6 +66,9 @@ public:
        CapturingSurroundexp = 15
    };

    /**
     * Whitebalance constant
     */
    enum class ParamWB
    {
        Auto = 0,
@@ -64,6 +78,9 @@ public:
        Night = 4
    };

    /**
     * Return value constant
     */
    enum class Rval
    {
        CommandOk = 0,
@@ -84,6 +101,9 @@ public:
        StartSessionDenied = -3,
    };

    /**
     * ISO sensitivity constant
     */
    enum class ISO
    {
        Auto = 0,
@@ -96,7 +116,9 @@ public:
        I1600 = 1600
    };


    /**
     * Shutter speed constant
     */
    enum class Speed
    {
        Auto = 0,
@@ -127,7 +149,9 @@ public:
    };


    
    /**
     * Built-in bracketing parameter constant
     */
    enum class ParamBracketingBuiltIn
    {
        EV0_5 = 1,
@@ -138,6 +162,10 @@ public:
        EV3 = 6
    };


    /**
     * Battery parameter constant
     */
    enum class ParamBattery
    {
        Percent5 = 0,
@@ -148,12 +176,18 @@ public:
        ChargeFull = 68
    };

    /**
     * Mode (photo/video) parameter constant
     */
    enum class ParamMode
    {
        Video = 0,
        Photo = 1
    };

    /**
     * SD card used-space parameter constant
     */
    enum class ParamSdcardFull
    {
        No = 0,
@@ -162,12 +196,18 @@ public:
        Unknown = 3
    };

    /**
     * 'Is SD mounted' constant
     */
    enum class ParamSdcardMounted
    {
        No = 0,
        Yes = 1
    };

    /**
     * 'Does SD card need formatting' constant
     */
    enum class ParamSdcardNeedFormat
    {
        No = 0,
@@ -175,15 +215,22 @@ public:
    };


    /**
     * Converts speed enum to milliseconds
     *
     * @param speed Enum value of speed
     * @return milliseconds equivalent
     */
    static int getSpeedMs(Speed speed);

    /**
     * Get state string representation
     */
    static std::string stateToString(int state);

private:
    
};




#endif /* CODES_H */
+263 −185

File changed.

Preview size limit exceeded, changes collapsed.

+43 −44
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ public:

    void start();

    void runReceiver();
    void startReceiver();
    void stopReceiver();

    bool isShooting();
@@ -53,7 +53,6 @@ private:
    Codes::ParamWB _photoWB;
    Codes::ParamMode _mode;

    
    size_t _bracketingStep;
    size_t _bracketingHalfCount;
    bool _bracketingVectorInvalid;;
@@ -64,7 +63,6 @@ private:
    size_t _timelapseInterval;
    size_t _timelapseCount;

    
    bool _isShooting;
    std::mutex _isShootingMutex;

@@ -74,7 +72,6 @@ private:

    Server* _server; // HTTP and WebSocket server

    
    // Ordered mapping of speed (shortest to longest) from enum to numerical value
    static std::vector<std::pair<Codes::Speed, double>> speedOrderedMapping;
    // Ordered mapping of ISO (smallest to largest)   from enum to numerical value
@@ -86,10 +83,12 @@ private:

    bool connectCommander();
    void disconnectCommander();
    void invalidateCachedSettings();

    void runExecutor();
    bool executorShoot(std::shared_ptr<DynamicJsonDocument> json);

    void initReceiver();
    void runReceiver();
    bool isReceiverRunning();

    template <typename T>
@@ -97,7 +96,8 @@ private:
    std::string generateJSON(Codes::MsgId msg);


    ////// Commands //////
    ////// Commands //////¨

    bool shoot();
    void stopShooting(bool stop = true);

@@ -149,12 +149,11 @@ private:
    * @param halfCount number of pictures to be taken above and below currently set exposure
    * @return true if setting was successful, otherwise false
    */
    bool computeBracketingVector(
    bool prepareBracketingVector(
        std::vector<std::pair<Codes::Speed, double>>::iterator speedIt,
        size_t halfCount,
        size_t evStep);


    /**
    * Set commander's bracketing settings
    *
@@ -169,7 +168,7 @@ private:
    * @param halfCount number of pictures to be taken above and below currently set exposure
    * @return true if setting was successful, otherwise false
    */
   bool computeBracketingVector(
   bool prepareBracketingVector(
        std::vector<std::pair<Codes::Speed, double>>::iterator& speedIt,
        std::vector<std::pair<Codes::ISO, double>>::iterator& isoIt,
        size_t halfCount,
Loading