Skip to content

Commit ac14185

Browse files
committed
Documented Trigger class
1 parent ca71b08 commit ac14185

File tree

2 files changed

+74
-14
lines changed

2 files changed

+74
-14
lines changed

scopehal/Trigger.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***********************************************************************************************************************
22
* *
3-
* libscopehal v0.1 *
3+
* libscopehal *
44
* *
5-
* Copyright (c) 2012-2021 Andrew D. Zonenberg and contributors *
5+
* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -27,6 +27,13 @@
2727
* *
2828
***********************************************************************************************************************/
2929

30+
/**
31+
@file
32+
@author Andrew D. Zonenberg
33+
@brief Implementation of Trigger
34+
@ingroup core
35+
*/
36+
3037
#include "scopehal.h"
3138

3239
using namespace std;
@@ -36,6 +43,11 @@ Trigger::CreateMapType Trigger::m_createprocs;
3643
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3744
// Construction / destruction
3845

46+
/**
47+
@brief Initialize a new trigger
48+
49+
@param scope The scope this trigger is attached to
50+
*/
3951
Trigger::Trigger(Oscilloscope* scope)
4052
: m_scope(scope)
4153
, m_levelname("Level")
@@ -51,24 +63,45 @@ Trigger::~Trigger()
5163
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5264
// Enumeration
5365

66+
/**
67+
@brief Register a new trigger class for dynamic creation
68+
69+
Do not call this function directly, use the AddTriggerClass macro
70+
71+
@param name Name of the trigger class
72+
@param proc Factory method
73+
*/
5474
void Trigger::DoAddTriggerClass(string name, CreateProcType proc)
5575
{
5676
m_createprocs[name] = proc;
5777
}
5878

79+
/**
80+
@brief Gets a list of all registered trigger types
81+
82+
@param[out] names List of known triggers
83+
*/
5984
void Trigger::EnumTriggers(vector<string>& names)
6085
{
6186
for(CreateMapType::iterator it=m_createprocs.begin(); it != m_createprocs.end(); ++it)
6287
names.push_back(it->first);
6388
}
6489

90+
/**
91+
@brief Creates a new trigger for an oscilloscope
92+
93+
@param name Name of the desired trigger
94+
@param scope The scope to create the trigger for
95+
96+
@return The newly created trigger, or nullptr on failure
97+
*/
6598
Trigger* Trigger::CreateTrigger(string name, Oscilloscope* scope)
6699
{
67100
if(m_createprocs.find(name) != m_createprocs.end())
68101
return m_createprocs[name](scope);
69102

70103
LogError("Invalid trigger name: %s\n", name.c_str());
71-
return NULL;
104+
return nullptr;
72105
}
73106

74107
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

scopehal/Trigger.h

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***********************************************************************************************************************
22
* *
3-
* libscopehal v0.1 *
3+
* libscopehal *
44
* *
5-
* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
5+
* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -31,46 +31,76 @@
3131
@file
3232
@author Andrew D. Zonenberg
3333
@brief Declaration of Trigger
34+
@ingroup core
3435
*/
3536
#ifndef Trigger_h
3637
#define Trigger_h
3738

3839
#include "FlowGraphNode.h"
3940

4041
/**
41-
@brief Abstract base class for oscilloscope / logic analyzer triggers
42+
@brief Abstract base class for oscilloscope / logic analyzer trigger inputs
43+
@ingroup core
4244
*/
4345
class Trigger : public FlowGraphNode
4446
{
4547
public:
4648
Trigger(Oscilloscope* scope);
4749
virtual ~Trigger();
4850

51+
///@brief Get the trigger level
4952
float GetLevel()
5053
{ return m_parameters[m_levelname].GetFloatVal(); }
5154

55+
/**
56+
@brief Sets the trigger level
57+
58+
@param level Trigger level
59+
*/
5260
void SetLevel(float level)
5361
{ m_parameters[m_levelname].SetFloatVal(level); }
5462

63+
///@brief Gets the scope this trigger is attached to
5564
Oscilloscope* GetScope()
5665
{ return m_scope; }
5766

58-
//Conditions for filters
67+
///@brief Conditions for triggers that perform logical comparisons of values
5968
enum Condition
6069
{
70+
///@brief Match when value is equal to target
6171
CONDITION_EQUAL,
72+
73+
///@brief Match when value is not equal to target
6274
CONDITION_NOT_EQUAL,
75+
76+
///@brief Match when value is less than target
6377
CONDITION_LESS,
78+
79+
///@brief Match when value is less than or equal to target
6480
CONDITION_LESS_OR_EQUAL,
81+
82+
///@brief Match when value is greater than target
6583
CONDITION_GREATER,
84+
85+
///@brief Match when value is greater than or equal to target
6686
CONDITION_GREATER_OR_EQUAL,
87+
88+
///@brief Match when value is greater than one target but less than another
6789
CONDITION_BETWEEN,
90+
91+
///@brief Match when value is not between two targets
6892
CONDITION_NOT_BETWEEN,
93+
94+
///@brief Always match
6995
CONDITION_ANY
7096
};
7197

7298
protected:
99+
100+
///@brief The scope this trigger is part of
73101
Oscilloscope* m_scope;
102+
103+
///@brief Name of the "trigger level" parameter
74104
std::string m_levelname;
75105

76106
public:
@@ -82,16 +112,13 @@ class Trigger : public FlowGraphNode
82112
static void EnumTriggers(std::vector<std::string>& names);
83113
static Trigger* CreateTrigger(std::string name, Oscilloscope* scope);
84114

85-
/**
86-
@brief Serializes this trigger's configuration to a YAML string.
87-
88-
@return YAML block with this trigger's configuration
89-
*/
90-
virtual YAML::Node SerializeConfiguration(IDTable& table);
115+
virtual YAML::Node SerializeConfiguration(IDTable& table) override;
91116

92117
protected:
93-
//Class enumeration
118+
///@brief Helper typedef for m_createprocs
94119
typedef std::map< std::string, CreateProcType > CreateMapType;
120+
121+
///@brief Map of trigger type names to factory methods
95122
static CreateMapType m_createprocs;
96123
};
97124

0 commit comments

Comments
 (0)