- 
                Notifications
    You must be signed in to change notification settings 
- Fork 605
Create replacement for now lacking physical-to-logical pin mapping #2435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            pgrawehr
  wants to merge
  8
  commits into
  dotnet:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
pgrawehr:VirtualPinsForRpi
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 3 commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f45456e
              
                Move class (but not namespace) to prevent circular dependency later
              
              
                pgrawehr d6e49f2
              
                A first draft. Looks neater than with ChatGPT. Obviously.
              
              
                pgrawehr 638d3e0
              
                Design looks ok, now need to test this
              
              
                pgrawehr 0a7589a
              
                Add tests for new class
              
              
                pgrawehr 134c38f
              
                Remove most remains of ConvertPinNumberToLogicalNumberingScheme
              
              
                pgrawehr 96b651b
              
                Remove all remains anyway
              
              
                pgrawehr 4a587e3
              
                Remove obsolete method from bindings as well
              
              
                pgrawehr 5440d2b
              
                Some minor findings
              
              
                pgrawehr File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|  | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Device.Gpio; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|  | ||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|  | ||
| namespace Iot.Device.Gpio | ||
| { | ||
| /// <summary> | ||
| /// A virtual GPIO controller that serves primarily for a pin mapping on an existing controller. | ||
| /// Unlike <see cref="VirtualGpioController"/> it has a default controller rather than individual pins | ||
| /// and thus also supports <see cref="GpioController.OpenPin(int)"/>. | ||
| /// </summary> | ||
| public class VirtualGpioControllerWithDefault : VirtualGpioController | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider something along the lines of Mapping/Mapped(Virtual)GpioController | ||
| { | ||
| private readonly GpioController _defaultController; | ||
| private readonly Func<int, int> _fromVirtualToRealMapping; | ||
|  | ||
| /// <summary> | ||
| /// Create a controller that by default uses the given controller to open a pin, using the given mapping. | ||
| /// Note that you can still use <see cref="VirtualGpioController.Add(int, GpioPin)"/> to manually add pins from another controller. | ||
| /// </summary> | ||
| /// <param name="defaultController">The default controller</param> | ||
| /// <param name="fromVirtualToRealMapping">A mapping function from virtual to logical. This should return -1 for unknown pins.</param> | ||
| public VirtualGpioControllerWithDefault(GpioController defaultController, Func<int, int> fromVirtualToRealMapping) | ||
| { | ||
| _defaultController = defaultController ?? throw new ArgumentNullException(nameof(defaultController)); | ||
| _fromVirtualToRealMapping = fromVirtualToRealMapping ?? throw new ArgumentNullException(nameof(fromVirtualToRealMapping)); | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Opens a pin from the default controller | ||
| /// </summary> | ||
| /// <param name="pinNumber">The pin number</param> | ||
| protected override void OpenPinCore(int pinNumber) | ||
| { | ||
| int realPinNumber = MapToRealPin(pinNumber); | ||
| if (realPinNumber == -1) | ||
| { | ||
| throw new InvalidOperationException($"Virtual Pin Number {pinNumber} is unknown"); | ||
| } | ||
|  | ||
| var pin = _defaultController.OpenPin(realPinNumber); | ||
| if (!Add(pinNumber, pin)) | ||
| { | ||
| _defaultController.ClosePin(realPinNumber); | ||
| throw new InvalidOperationException($"Virtual Pin Number {pinNumber} is in use already"); | ||
| } | ||
| } | ||
|  | ||
|         
                  pgrawehr marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| public int MapToRealPin(int virtualPin) | ||
| { | ||
| return _fromVirtualToRealMapping(virtualPin); | ||
| } | ||
| } | ||
| } | ||
            File renamed without changes.
          
    
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.