|  |  | @ -3,6 +3,10 @@ package com.yinuo.safetywatcher.watcher.utils | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.content.Context |  |  |  | import android.content.Context | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.media.AudioAttributes |  |  |  | import android.media.AudioAttributes | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.media.SoundPool |  |  |  | import android.media.SoundPool | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.common.commonlib.utils.LogUtils | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import kotlinx.coroutines.GlobalScope | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import kotlinx.coroutines.delay | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import kotlinx.coroutines.launch | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | object SoundUtils { |  |  |  | object SoundUtils { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -28,4 +32,24 @@ object SoundUtils { | 
			
		
	
		
		
			
				
					
					|  |  |  |         // 播放音效 |  |  |  |         // 播放音效 | 
			
		
	
		
		
			
				
					
					|  |  |  |         soundPool.play(soundId, 1.0f, 1.0f, 1, 0, 1.0f); // 参数依次为音效ID、左声道音量、右声道音量、优先级、循环次数、播放速度 |  |  |  |         soundPool.play(soundId, 1.0f, 1.0f, 1, 0, 1.0f); // 参数依次为音效ID、左声道音量、右声道音量、优先级、循环次数、播放速度 | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     var soundPlaying = false | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     fun playSoundIo() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         GPIOUtils.setGpioDirection(152, "out") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         var gpioValue = 0 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         soundPlaying = true | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         GlobalScope.launch { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             while (soundPlaying) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 gpioValue = if (gpioValue > 0) 0 else 1 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 LogUtils.w("cyy gpioValue ${gpioValue}") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 GPIOUtils.setGpioValue(152, gpioValue) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 delay(500) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     fun stopSoundIo() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         soundPlaying = false | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } |