Repo for designs & driver for a TA7642 powered lightning detector

feat: Embassy driver #1

merged opened by sachy.dev targeting main from driver
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:usjm3ynnir6y4inkcdovrfei/sh.tangled.repo.pull/3mcxaimss3u22
+94 -28
Interdiff #2 #3
Cargo.lock

This file has not been changed.

Cargo.toml

This file has not been changed.

README.md

This file has not been changed.

embassy-strike-driver/Cargo.toml

This file has not been changed.

+73 -28
embassy-strike-driver/src/lib.rs
··· 387 387 .await; 388 388 } 389 389 390 + fn generate_signal(samples: &mut [u16]) { 391 + // Example voltage drop signal 392 + samples[5] -= 60; 393 + samples[6] -= 55; 394 + samples[7] -= 50; 395 + samples[8] -= 45; 396 + samples[9] -= 40; 397 + samples[10] -= 35; 398 + samples[11] -= 30; 399 + samples[12] -= 28; 400 + samples[13] -= 26; 401 + samples[14] -= 24; 402 + samples[15] -= 22; 403 + samples[16] -= 20; 404 + samples[17] -= 18; 405 + samples[18] -= 16; 406 + samples[19] -= 14; 407 + samples[20] -= 12; 408 + samples[21] -= 11; 409 + samples[22] -= 10; 410 + samples[23] -= 9; 411 + samples[24] -= 8; 412 + samples[25] -= 7; 413 + samples[26] -= 6; 414 + samples[27] -= 5; 415 + samples[28] -= 4; 416 + samples[29] -= 3; 417 + samples[30] -= 2; 418 + samples[31] -= 1; 419 + } 420 + 390 421 #[pollster::test] 391 422 async fn tuning_cycle_completes() { 392 423 let driver = embassy_time::MockDriver::get(); ··· 479 510 480 511 assert_eq!(peaks.len(), 0); 481 512 482 - // Example voltage drop signal 483 - samples[5] -= 60; 484 - samples[6] -= 55; 485 - samples[7] -= 50; 486 - samples[8] -= 45; 487 - samples[9] -= 40; 488 - samples[10] -= 35; 489 - samples[11] -= 30; 490 - samples[12] -= 28; 491 - samples[13] -= 26; 492 - samples[14] -= 24; 493 - samples[15] -= 22; 494 - samples[16] -= 20; 495 - samples[17] -= 18; 496 - samples[18] -= 16; 497 - samples[19] -= 14; 498 - samples[20] -= 12; 499 - samples[21] -= 11; 500 - samples[22] -= 10; 501 - samples[23] -= 9; 502 - samples[24] -= 8; 503 - samples[25] -= 7; 504 - samples[26] -= 6; 505 - samples[27] -= 5; 506 - samples[28] -= 4; 507 - samples[29] -= 3; 508 - samples[30] -= 2; 509 - samples[31] -= 1; 513 + generate_signal(&mut samples); 510 514 511 515 let expected_peaks = alloc::vec![0, 8]; 512 516 let called = Cell::new(false); ··· 527 531 528 532 assert_eq!(peaks.len(), 2); 529 533 assert!(called.get()); 534 + } 535 + 536 + #[pollster::test] 537 + async fn detection_sensitivity_can_be_configured() { 538 + let driver = embassy_time::MockDriver::get(); 539 + driver.reset(); 540 + let device = MockMachine::default(); 541 + let pwm = MockPwm(&device); 542 + let adc = MockAdc(&device); 543 + 544 + let detector = DetectorDriver::new(Default::default(), MockTimeSource, pwm, adc); 545 + detector.pwm.0.pwm.set(64); 546 + detector.state.max_duty.set(98); 547 + detector.state.duty.set(64); 548 + detector.state.avg.set(896); 549 + 550 + let mut samples = alloc::vec![0; BLOCK_SIZE]; 551 + let mut peaks: alloc::vec::Vec<usize> = alloc::vec::Vec::with_capacity(BLOCK_SIZE); 552 + 553 + // Require bigger size blips. 554 + detector.config.blip_size.set(3); 555 + 556 + detector.adc.sample(&mut samples).await; 557 + generate_signal(&mut samples); 558 + 559 + detector.detect_from_sample(0, &samples, &mut peaks, |_update| { 560 + panic!("Update shouldn't be called"); 561 + }); 562 + 563 + assert_eq!(peaks.len(), 2); 564 + 565 + // Require bigger threshold for blip detection 566 + detector.config.blip_size.set(2); 567 + detector.config.blip_threshold.set(24); 568 + 569 + detector.detect_from_sample(0, &samples, &mut peaks, |_update| { 570 + panic!("Update shouldn't be called"); 571 + }); 572 + 573 + // Update didn't call because detected blip wasn't big enough 574 + assert_eq!(peaks.len(), 1); 530 575 } 531 576 }
+21
.tangled/workflows/test.yml
··· 1 + when: 2 + - event: ["push", "pull_request"] 3 + branch: main 4 + 5 + engine: nixery 6 + 7 + dependencies: 8 + nixpkgs: 9 + - clang 10 + - cargo 11 + - rustfmt 12 + - protobuf 13 + - cargo-nextest 14 + 15 + steps: 16 + - name: Format check 17 + command: cargo fmt --all --check 18 + - name: Tests 19 + command: cargo nextest run --workspace --locked --no-fail-fast 20 + - name: Doc Tests 21 + command: cargo test --workspace --locked --doc --no-fail-fast

History

10 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
feat: Embassy driver
1/1 success
expand
expand 0 comments
pull request successfully merged
1 commit
expand
feat: Embassy driver
1/1 success
expand
expand 0 comments
1 commit
expand
feat: Embassy driver
1/1 success
expand
expand 0 comments
1 commit
expand
feat: Embassy driver
1/1 failed
expand
expand 0 comments
1 commit
expand
feat: Embassy driver
1/1 success
expand
expand 0 comments
1 commit
expand
feat: Embassy driver
1/1 success
expand
expand 0 comments
1 commit
expand
feat: Embassy driver
1/1 failed
expand
expand 0 comments
1 commit
expand
feat: Embassy driver
expand 0 comments
1 commit
expand
feat: Embassy driver
expand 0 comments
1 commit
expand
feat: Embassy driver
expand 0 comments