Skip to content

Commit

Permalink
Merge pull request #22 from sundaram123krishnan/master
Browse files Browse the repository at this point in the history
Displaying pin names
  • Loading branch information
andrewdavidmackenzie authored May 15, 2024
2 parents 4b6bcb3 + da5936d commit eda2508
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum PinFunction {
pub struct Pin {
pub board_pin_number: u8,
bcm_pin_number: Option<u8>,
name: &'static str,
pub name: &'static str,
options: &'static[PinFunction], // The set of functions the pin can have, chosen by user config
config: Option<PinFunction>, // The currently selected function for the pin, if any selected
}
Expand Down Expand Up @@ -90,7 +90,7 @@ const PIN_4: Pin = Pin {
};

const PIN_5: Pin = Pin {
board_pin_number: 2,
board_pin_number: 5,
bcm_pin_number: Some(3),
name: "GPIO3",
options: &[PinFunction::Input, PinFunction::Output, PinFunction::SCL1, PinFunction::I2C],
Expand Down
17 changes: 11 additions & 6 deletions src/piggui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ mod hw;
// in Cargo.toml so no need for the feature to be used here for conditional compiling
use iced::widget::{button, container, row, Column, Text};
use iced::{alignment, window, Element, Length, Sandbox, Settings};

// Use Hardware via trait
use hw::Hardware;
use crate::gpio::GPIOConfig;
use hw::Hardware;

fn main() -> Result<(), iced::Error> {
let window = window::Settings {
Expand Down Expand Up @@ -95,11 +94,17 @@ fn pin_view(config: &GPIOConfig) -> Element<'static, Message> {

for pair in config.pins.chunks(2) {
let row = row!(
// add radio button
button(Text::new(pair[0].board_pin_number.to_string())).on_press(Message::Activate),
button(Text::new(pair[1].board_pin_number.to_string())).on_press(Message::Activate),
Text::new(pair[0].name).size(20),
button(Text::new(pair[0].board_pin_number.to_string()))
.on_press(Message::Activate)
.width(Length::Fixed(50 as f32)),
button(Text::new(pair[1].board_pin_number.to_string()))
.on_press(Message::Activate)
.width(Length::Fixed(50 as f32)),
Text::new(pair[1].name).size(20),
)
.spacing(10);
.spacing(10)
.align_items(iced::Alignment::Center);
column = column.push(row);
}
container(column).height(2000).width(2000).into()
Expand Down

0 comments on commit eda2508

Please sign in to comment.