Bad water controller
This commit is contained in:
		
							parent
							
								
									764cfbd0fa
								
							
						
					
					
						commit
						b0210cbfbd
					
				
					 1 changed files with 63 additions and 3 deletions
				
			
		|  | @ -5,14 +5,74 @@ import wash.io.WashingIO; | ||||||
| 
 | 
 | ||||||
| public class WaterController extends ActorThread<WashingMessage> { | public class WaterController extends ActorThread<WashingMessage> { | ||||||
| 
 | 
 | ||||||
|     // TODO: add attributes |     WashingMessage.Order o; | ||||||
|  |     WashingMessage m; | ||||||
|  |     WashingIO io; | ||||||
| 
 | 
 | ||||||
|     public WaterController(WashingIO io) { |     public WaterController(WashingIO io) { | ||||||
|         // TODO |         this.io = io; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void run() { |     public void run() { | ||||||
|         // TODO | 
 | ||||||
|  |         boolean firstRun = true; | ||||||
|  | 
 | ||||||
|  |         while (true) { | ||||||
|  |             try { | ||||||
|  |                 WashingMessage n = receiveWithTimeout(60000 / Settings.SPEEDUP); | ||||||
|  | 
 | ||||||
|  |                 if (n != null) { | ||||||
|  |                     if (o != null && o != n.order()) | ||||||
|  |                         firstRun = true; | ||||||
|  |                     m = n; | ||||||
|  |                     o = m.order(); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 if (o != null) { | ||||||
|  |                     switch (o) { | ||||||
|  |                         case WATER_DRAIN -> { | ||||||
|  |                             if (io.getWaterLevel() > 0.0) { | ||||||
|  |                                 io.fill(false); | ||||||
|  |                                 io.drain(true); | ||||||
|  |                             } | ||||||
|  |                             else { | ||||||
|  |                                 //io.drain(false); | ||||||
|  |                                 if (firstRun) | ||||||
|  |                                     //sendAck(); | ||||||
|  |                                 firstRun = false; | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         case WATER_FILL -> { | ||||||
|  |                             if (io.getWaterLevel() < 10.0) { | ||||||
|  |                                 io.drain(false); | ||||||
|  |                                 io.fill(true); | ||||||
|  |                             } else { | ||||||
|  |                                 io.fill(false); | ||||||
|  |                                 if (firstRun) | ||||||
|  |                                     //sendAck(); | ||||||
|  |                                 firstRun = false; | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         case WATER_IDLE -> { | ||||||
|  |                             io.drain(false); | ||||||
|  |                             io.fill(false); | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |             } catch (InterruptedException e) { | ||||||
|  |                 throw new RuntimeException(e); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             // if m is null, it means a minute passed and no message was received | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void sendAck() { | ||||||
|  |         m.sendAck(this); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Imbus
						Imbus