Skip to content
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

hub75: fix data buffering #722

Merged
merged 1 commit into from
Jan 4, 2025

Conversation

ehime-iyokan
Copy link

I fixed buffering of red data. ( #691 (comment) )

The red data seems to be misaligned, so the display position is incorrect;
however, the other colors are fine.

// Sample code for order of operations
package main

import "fmt"

func main() {
	bitSelect := 2
	data_1 := 0x05
	data_2 := 0x05

	fmt.Println("before")
	fmt.Printf("%08b\n", data_1)
	data_1 = data_1 &^ 1 << bitSelect
	fmt.Printf("%08b\n", data_1)

	fmt.Println("after")
	fmt.Printf("%08b\n", data_2)
	data_2 &^= 1 << bitSelect
	fmt.Printf("%08b\n", data_2)
}
// before: it setting bits to 1 in unintended positions.
// after: it is clearing the bits in the intended positions.
$ go run .    
before
00000101
00010000
after
00000101
00000001

@ehime-iyokan
Copy link
Author

I have confirmed sample-program works without any problems. ehime-iyokan/DisplayWeatherInfoOnLEDmatrix@4ec0054

ledmatrix

@deadprogram
Copy link
Member

@conejoninja PTAL

@conejoninja
Copy link
Member

It's on my list, I need to check it doesn't have any unintended consecuences

@deadprogram deadprogram changed the base branch from release to dev December 17, 2024 09:52
@conejoninja conejoninja requested a review from aykevl December 18, 2024 10:45
@conejoninja
Copy link
Member

I'm having some hardware issues that doesn't allow me to test this, adding @aykevl just in case I can't review it before next release

@ehime-iyokan
Copy link
Author

ehime-iyokan commented Dec 19, 2024

It's on my list, I need to check it doesn't have any unintended consecuences

I'll try to consider test patterns. @conejoninja
However, I don't have much experience contributing, so I'd appreciate any advice.

@ehime-iyokan
Copy link
Author

ehime-iyokan commented Dec 21, 2024

I have summarized the code fix and test patterns. @conejoninja

🔧 Details of Fix

  • Terminology:
    • The if clause refers to the processing starting at line 168.
    • The else clause refers to the processing starting at line 170.

🛠️ Fix Implementation

  • The else clause should be corrected as follows:

    d.buffer[c][offsetR] &^= 1 << bitSelect
  • This ensures that only the bit at the bitSelect position is cleared, leaving other bits unaffected.

🔍 Observations

  • Expected Behavior:

    • The if clause sets the bit at the bitSelect position to 1.
    • Correspondingly, the else clause should set the bit at the bitSelect position to 0.
  • Current Implementation Issue:

    • The current code in the else clause is as follows:
      d.buffer[c][offsetR] = d.buffer[c][offsetR] &^ 1 << bitSelect
    • This produces the same result as the following incorrect operation:
      d.buffer[c][offsetR] = (d.buffer[c][offsetR] &^ 1) << bitSelect
    • This does not achieve the desired behavior of clearing the specific bit.
  • Analysis:

    • The goal is to set the bit at the position indicated by bitSelect to 0.
    • The current implementation is incorrect and needs to be fixed.

🧪 Sample Code for Behavior Verification

  • Go Playground Sample
    • before: Demonstrates behavior before the fix.
    • after: Demonstrates behavior after the fix.

📝 Test Verification

Verification of Red LED Operation

  • Test Steps:
      1. Illuminate all red LEDs.
      1. Turn off a single red LED while others remain on.
  • Expected Result:
    • Only red LEDs should illuminate or turn off as expected, with no impact on green or blue LEDs.

No Interference with Other Colors

  • Test Steps:
      1. Illuminate red and green LEDs simultaneously.
      1. Illuminate red and blue LEDs simultaneously.
  • Expected Result:
    • Red and green, or red and blue, should display correctly without color interference.

Note


📋 Test Results

Test Case Result Notes
Red LED Operation Pending Red LEDs illuminate correctly
No Interference with Other Colors Pending No impact on green or blue
? Pending ?

Copy link
Member

@sago35 sago35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the correctness of this PR is demonstrated by the following code. The intended behavior is to clear a specific bit, but the previous code cleared all bits below it as well.

https://go.dev/play/p/cVr8fXGKSSi

before 
11111110
11111100
11111000
11110000
11100000
11000000
10000000
00000000

after
11111110
11111101
11111011
11110111
11101111
11011111
10111111
01111111

This is evident when looking at the handling of other colors as well.

image

@deadprogram
Copy link
Member

Thanks for review @sago35 and to @ehime-iyokan for the fix. Now merging.

@deadprogram deadprogram merged commit 17f2732 into tinygo-org:dev Jan 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants