@@ -278,33 +278,35 @@ pub enum TuneIndex {
278
278
TapNext ,
279
279
}
280
280
281
- impl TryFrom < u8 > for TuneIndex {
282
- type Error = ( ) ;
283
- fn try_from ( index : u8 ) -> Result < TuneIndex , ( ) > {
284
- Ok ( match index {
285
- TUNE_RESERVED => TuneIndex :: Reserved ,
286
- TUNE_BOOT => TuneIndex :: Boot ,
287
- TUNE_CHARGING => TuneIndex :: Charging ,
288
- TUNE_LEDGER_MOMENT => TuneIndex :: LedgerMoment ,
289
- TUNE_ERROR => TuneIndex :: Error ,
290
- TUNE_NEUTRAL => TuneIndex :: Neutral ,
291
- TUNE_LOCK => TuneIndex :: Lock ,
292
- TUNE_SUCCESS => TuneIndex :: Success ,
293
- TUNE_LOOK_AT_ME => TuneIndex :: LookAtMe ,
294
- TUNE_TAP_CASUAL => TuneIndex :: TapCasual ,
295
- TUNE_TAP_NEXT => TuneIndex :: TapNext ,
296
- _ => return Err ( ( ) ) ,
297
- } )
298
- }
299
- }
300
-
301
- // this is a mock that does nothing yet, but should become a direct translation
302
- // of the C original. This was done to avoid compiling `os_io_seproxyhal.c` which
303
- // includes many other things
281
+ // Direct translation of the C original. This was done to
282
+ // avoid compiling `os_io_seproxyhal.c` which includes many other things
304
283
#[ no_mangle]
305
284
extern "C" fn io_seproxyhal_play_tune ( tune_index : u8 ) {
306
- let index = TuneIndex :: try_from ( tune_index) ;
307
- if index. is_err ( ) {
285
+ let mut buffer = [ 0u8 ; 4 ] ;
286
+ let mut spi_buffer = [ 0u8 ; 128 ] ;
287
+
288
+ if tune_index >= NB_TUNES {
289
+ return ;
290
+ }
291
+
292
+ let sound_setting =
293
+ unsafe { os_setting_get ( OS_SETTING_PIEZO_SOUND . into ( ) , core:: ptr:: null_mut ( ) , 0 ) } ;
294
+
295
+ if ( ( sound_setting & 2 ) == 2 ) && ( tune_index < TUNE_TAP_CASUAL ) {
296
+ return ;
297
+ }
298
+
299
+ if ( ( sound_setting & 1 ) == 1 ) && ( tune_index >= TUNE_TAP_CASUAL ) {
308
300
return ;
309
301
}
302
+
303
+ if seph:: is_status_sent ( ) {
304
+ seph:: seph_recv ( & mut spi_buffer, 0 ) ;
305
+ }
306
+
307
+ buffer[ 0 ] = SEPROXYHAL_TAG_PLAY_TUNE as u8 ;
308
+ buffer[ 1 ] = 0 ;
309
+ buffer[ 2 ] = 1 ;
310
+ buffer[ 3 ] = tune_index;
311
+ seph:: seph_send ( & buffer) ;
310
312
}
0 commit comments