-
Notifications
You must be signed in to change notification settings - Fork 14
/
I2cAnalyzerSettings.cpp
87 lines (67 loc) · 2.62 KB
/
I2cAnalyzerSettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "I2cAnalyzerSettings.h"
#include <AnalyzerHelpers.h>
#include <cstring>
I2cAnalyzerSettings::I2cAnalyzerSettings()
: mSdaChannel( UNDEFINED_CHANNEL ), mSclChannel( UNDEFINED_CHANNEL )
{
mSdaChannelInterface.reset( new AnalyzerSettingInterfaceChannel() );
mSdaChannelInterface->SetTitleAndTooltip( "SDA", "Serial Data Line" );
mSdaChannelInterface->SetChannel( mSdaChannel );
mSclChannelInterface.reset( new AnalyzerSettingInterfaceChannel() );
mSclChannelInterface->SetTitleAndTooltip( "SCL", "Serial Clock Line" );
mSclChannelInterface->SetChannel( mSclChannel );
AddInterface( mSdaChannelInterface.get() );
AddInterface( mSclChannelInterface.get() );
// AddExportOption( 0, "Export as text/csv file", "text (*.txt);;csv (*.csv)" );
AddExportOption( 0, "Export as text/csv file" );
AddExportExtension( 0, "text", "txt" );
AddExportExtension( 0, "csv", "csv" );
ClearChannels();
AddChannel( mSdaChannel, "SDA", false );
AddChannel( mSclChannel, "SCL", false );
}
I2cAnalyzerSettings::~I2cAnalyzerSettings()
{
}
bool I2cAnalyzerSettings::SetSettingsFromInterfaces()
{
if( mSdaChannelInterface->GetChannel() == mSclChannelInterface->GetChannel() )
{
SetErrorText( "SDA and SCL can't be assigned to the same input." );
return false;
}
mSdaChannel = mSdaChannelInterface->GetChannel();
mSclChannel = mSclChannelInterface->GetChannel();
ClearChannels();
AddChannel( mSdaChannel, "SDA", true );
AddChannel( mSclChannel, "SCL", true );
return true;
}
void I2cAnalyzerSettings::LoadSettings( const char* settings )
{
SimpleArchive text_archive;
text_archive.SetString( settings );
const char* name_string; // the first thing in the archive is the name of the protocol analyzer that the data belongs to.
text_archive >> &name_string;
if( strcmp( name_string, "SaleaeI2CAnalyzer" ) != 0 )
AnalyzerHelpers::Assert( "SaleaeI2CAnalyzer: Provided with a settings string that doesn't belong to us;" );
text_archive >> mSdaChannel;
text_archive >> mSclChannel;
ClearChannels();
AddChannel( mSdaChannel, "SDA", true );
AddChannel( mSclChannel, "SCL", true );
UpdateInterfacesFromSettings();
}
const char* I2cAnalyzerSettings::SaveSettings()
{
SimpleArchive text_archive;
text_archive << "SaleaeI2CAnalyzer";
text_archive << mSdaChannel;
text_archive << mSclChannel;
return SetReturnString( text_archive.GetString() );
}
void I2cAnalyzerSettings::UpdateInterfacesFromSettings()
{
mSdaChannelInterface->SetChannel( mSdaChannel );
mSclChannelInterface->SetChannel( mSclChannel );
}