Skip to content

Commit

Permalink
feat: apply bitmask to x and y
Browse files Browse the repository at this point in the history
  • Loading branch information
wiwski committed Jul 12, 2024
1 parent d391743 commit c8d650b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ This project is a tool to convert data files from the New AGLAE particle acceler
3. Install the required packages:
It will install the rust library and the python dependencies
```
make build_rs
poetry install
make build_rs
```

## Usage
Expand Down
16 changes: 11 additions & 5 deletions src/converter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
};

pub mod config;
use config::{Detector, Config};
use config::{Config, Detector};

pub mod models;
use models::{ExpInfo, LSTDataset, MapSize};
Expand Down Expand Up @@ -306,10 +306,16 @@ fn get_channels_from_buffer(

let int_value = u16::from_le_bytes(adc_buffer);

if *adc == config.x && i64::from(int_value) < max_x {
position.x = int_value;
} else if *adc == config.y && i64::from(int_value) < max_y {
position.y = int_value;
if *adc == config.x {
// Calculate the mask to handle values up to max_x
let mask = ((1 << ((max_x as f64).log2().ceil() as u16 + 1)) - 1) as u16;
// Apply mask to the value
position.x = int_value & mask;
} else if *adc == config.y {
// Calculate the mask to handle values up to max_y
let mask = ((1 << ((max_y as f64).log2().ceil() as u16 + 1)) - 1) as u16;
// Apply mask to the value
position.y = int_value & mask;
} else {
if let Some((name, detector, floor)) = config.get_detector_and_floor_for_adc(*adc) {
if int_value > 0 {
Expand Down

0 comments on commit c8d650b

Please sign in to comment.