forked from M-Labs/humpback-dds
mqtt_mux: add publish example
This commit is contained in:
parent
f993ee5e28
commit
93f3b2dfb3
34
src/main.rs
34
src/main.rs
@ -96,10 +96,10 @@ fn main() -> ! {
|
||||
.pll1_r_ck(400.mhz())
|
||||
.freeze(vos, &dp.SYSCFG);
|
||||
|
||||
unsafe {
|
||||
logger::enable_itm(&dp.DBGMCU, &mut cp.DCB, &mut cp.ITM);
|
||||
}
|
||||
logger::init();
|
||||
// unsafe {
|
||||
// logger::enable_itm(&dp.DBGMCU, &mut cp.DCB, &mut cp.ITM);
|
||||
// }
|
||||
// logger::init();
|
||||
|
||||
let mut delay = cp.SYST.delay(ccdr.clocks);
|
||||
|
||||
@ -109,11 +109,13 @@ fn main() -> ! {
|
||||
let gpiod = dp.GPIOD.split(ccdr.peripheral.GPIOD);
|
||||
let gpioe = dp.GPIOE.split(ccdr.peripheral.GPIOE);
|
||||
let gpiof = dp.GPIOF.split(ccdr.peripheral.GPIOF);
|
||||
let gpiog = dp.GPIOG.split(ccdr.peripheral.GPIOG);
|
||||
|
||||
trace!("Flashing configuration bitstream to iCE40 HX8K on Humpback.");
|
||||
delay.delay_ms(1000_u16);
|
||||
let gpiog = dp.GPIOG.split(ccdr.peripheral.GPIOG);
|
||||
|
||||
gpiob.pb3.into_alternate_af0().set_speed(Speed::VeryHigh);
|
||||
|
||||
// trace!("Flashing configuration bitstream to iCE40 HX8K on Humpback.");
|
||||
// delay.delay_ms(1000_u16);
|
||||
/*
|
||||
// Using SPI_1 alternate functions (af5)
|
||||
let fpga_sck = gpiob.pb3.into_alternate_af5();
|
||||
let fpga_sdo = gpiob.pb4.into_alternate_af5();
|
||||
@ -136,7 +138,7 @@ fn main() -> ! {
|
||||
);
|
||||
|
||||
flash_ice40_fpga(fpga_cfg_spi, fpga_ss, fpga_creset, fpga_cdone, delay).unwrap();
|
||||
|
||||
*/
|
||||
// Configure ethernet IO
|
||||
{
|
||||
let _rmii_refclk = gpioa.pa1.into_alternate_af11().set_speed(Speed::VeryHigh);
|
||||
@ -215,7 +217,12 @@ fn main() -> ! {
|
||||
|
||||
let mut urukul = Urukul::new(
|
||||
parts.spi1, parts.spi2, parts.spi3, parts.spi4, parts.spi5, parts.spi6, parts.spi7
|
||||
);
|
||||
);
|
||||
|
||||
unsafe {
|
||||
logger::enable_itm(&dp.DBGMCU, &mut cp.DCB, &mut cp.ITM);
|
||||
}
|
||||
logger::init();
|
||||
|
||||
urukul.reset().unwrap();
|
||||
info!("Test value: {}", urukul.test().unwrap());
|
||||
@ -275,11 +282,16 @@ fn main() -> ! {
|
||||
if connection && !has_subscribed && tick {
|
||||
match client.subscribe("Urukul/Control/#", &[]) {
|
||||
Ok(()) => has_subscribed = true,
|
||||
Err(minimq::Error::NotReady) => {},
|
||||
Err(minimq::Error::NotReady) => warn!("Minimq is not ready"),
|
||||
e => warn!("{:?}", e),
|
||||
};
|
||||
}
|
||||
|
||||
if connection && tick && (time % 3000) == 0 {
|
||||
info!("Feedback from print publish: {:?}", client
|
||||
.publish("Channel1/Switch", mqtt_mux.get_switch_status_message(1).unwrap().as_bytes(), QoS::AtMostOnce, &[]));
|
||||
}
|
||||
|
||||
// Reset tick flag
|
||||
tick = false;
|
||||
}
|
||||
|
@ -278,6 +278,15 @@ impl<SPI, E> MqttMux<SPI> where SPI: Transfer<u8, Error = E> {
|
||||
MqttCommand::Profile(prof) => self.urukul.set_profile(prof),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_switch_status_message(&mut self, channel: u8) -> Result<&str, Error<E>> {
|
||||
self.urukul.get_channel_switch_status(channel.into()).map(
|
||||
|stat| if stat {
|
||||
"on"
|
||||
} else {
|
||||
"off"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Read message parameter separator (optional comma and whitespace)
|
||||
|
Loading…
Reference in New Issue
Block a user