Skip to content

Commit 4cd5631

Browse files
committed
add Default trait impl for some enums
1 parent cacbe6c commit 4cd5631

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

common/src/enums.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ impl From<PicoInfo> for i16 {
216216
}
217217

218218
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
219-
pub enum PicoWaveType
220-
{
219+
pub enum PicoWaveType {
221220
Sine = 0,
222221
Square = 1,
223222
Triangle = 2,
@@ -229,15 +228,26 @@ pub enum PicoWaveType
229228
DCVoltage = 8,
230229
}
231230

231+
impl Default for PicoWaveType {
232+
fn default() -> Self {
233+
PicoWaveType::Sine
234+
}
235+
}
236+
232237
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
233-
pub enum PicoSweepType
234-
{
238+
pub enum PicoSweepType {
235239
Up = 0,
236240
Down = 1,
237241
UpDown = 2,
238242
DownUp = 3,
239243
}
240244

245+
impl Default for PicoSweepType {
246+
fn default() -> Self {
247+
PicoSweepType::Up
248+
}
249+
}
250+
241251
// Rust addition: encode the potential values of sweeps and shots, to avoid invalid states
242252
// like >0 & >0
243253
#[derive(Debug, Clone)]
@@ -249,6 +259,11 @@ pub enum SweepShotCount {
249259
ContinuousShots,
250260
}
251261

262+
impl Default for SweepShotCount {
263+
fn default() -> Self {
264+
SweepShotCount::None
265+
}
266+
}
252267

253268
// TODO: this value is copied from sys/src/ps2000a - should we import it here?
254269
// should there be a crate for identical symbols?
@@ -273,10 +288,8 @@ impl SweepShotCount {
273288
}
274289
}
275290

276-
277291
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
278-
pub enum PicoExtraOperations
279-
{
292+
pub enum PicoExtraOperations {
280293
/// <summary>
281294
/// Normal signal generator operation specified by wavetype.
282295
/// </summary>
@@ -292,12 +305,17 @@ pub enum PicoExtraOperations
292305
PRBS = 2, // Pseudo-Random Bit Stream
293306
}
294307

308+
impl Default for PicoExtraOperations {
309+
fn default() -> Self {
310+
PicoExtraOperations::Off
311+
}
312+
}
313+
295314
/// <summary>
296315
/// AWG index modes
297316
/// </summary>
298317
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
299-
pub enum PicoIndexMode
300-
{
318+
pub enum PicoIndexMode {
301319
/// <summary>
302320
/// The generator outputs the raw contents of the buffer repeatedly .
303321
/// </summary>
@@ -317,8 +335,7 @@ pub enum PicoIndexMode
317335
/// The type of trigger that will be applied to the signal generator
318336
/// </summary>
319337
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
320-
pub enum PicoSigGenTrigType
321-
{
338+
pub enum PicoSigGenTrigType {
322339
/// <summary>
323340
/// Trigger on rising edge
324341
/// </summary>
@@ -337,12 +354,17 @@ pub enum PicoSigGenTrigType
337354
GateLow = 3,
338355
}
339356

357+
impl Default for PicoSigGenTrigType {
358+
fn default() -> Self {
359+
PicoSigGenTrigType::Rising
360+
}
361+
}
362+
340363
/// <summary>
341364
/// The source that will trigger the signal generator
342365
/// </summary>
343366
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive, PartialEq)]
344-
pub enum PicoSigGenTrigSource
345-
{
367+
pub enum PicoSigGenTrigSource {
346368
/// <summary>
347369
/// Run without waiting for trigger
348370
/// </summary>
@@ -364,3 +386,9 @@ pub enum PicoSigGenTrigSource
364386
/// </summary>
365387
SoftTrig = 4,
366388
}
389+
390+
impl Default for PicoSigGenTrigSource {
391+
fn default() -> Self {
392+
PicoSigGenTrigSource::None
393+
}
394+
}

0 commit comments

Comments
 (0)