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

Fix get_lamp_coordinates #12

Open
wants to merge 11 commits into
base: indexable_strip_base
Choose a base branch
from
Open

Conversation

epsln
Copy link
Collaborator

@epsln epsln commented Aug 28, 2024

Refers to issue #11

  • Coordinates from strip.get_lamp_coordinates are now actually in Cartesian fomat
  • They are obtained using a spiral equation instead of division rules. Those coordinates are normalized between -1 and 1 and casted to int16 by multiplying by INT16_MAX.
  • The Lamp is basically modeled as a unit cylinder, with no care given to the actual size to preserve normalization. This does mean that it might be a bit stretched.
  • Using those coordinates means that you have to map from int16 to float by dividing by INT16_MAX, which is not ideal

TODO:
Change coordinates in Cartesian struct from int16 to half floats. Should fix those issues with mapping, but will slow down booting.

@epsln epsln requested a review from BaptisteHudyma August 28, 2024 14:57
if (ledIndex > LED_COUNT) return 0;

return round(std::fmod(ledIndex, stripXCoordinates));
return cos16(ledIndex * 1.0/ledPerTurn * 2 * 3.14159265358 * ceil(ledPerTurn));
Copy link
Owner

@BaptisteHudyma BaptisteHudyma Aug 28, 2024

Choose a reason for hiding this comment

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

use constants like PI (available with #include <Arduino.h>")

Put temporary computations in preprocessed :

static constexpr uint16_t temp = 1.0/ledPerTurn * 2 * 3.14159265358 * ceil(ledPerTurn);
return cos16(ledIndex * temp);

if (ledIndex > LED_COUNT) return 0;
return (ledIndex * 1.0/LED_COUNT) * INT16_MAX;

}

uint16_t to_strip(uint16_t screenX, uint16_t screenY) {
Copy link
Owner

Choose a reason for hiding this comment

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

now that the to_screen_x/y/z returns a signed int, this should also take in a signed int

@@ -6,19 +6,21 @@
#include "../ext/math8.h"
#include "constants.h"

uint16_t to_screen_x(const uint16_t ledIndex) {
int16_t to_screen_x(const uint16_t ledIndex) {
if (ledIndex > LED_COUNT) return 0;
Copy link
Owner

Choose a reason for hiding this comment

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

return LED_COUNT would be better

uint16_t to_screen_z(const uint16_t ledIndex) { return 1; }
int16_t to_screen_z(const uint16_t ledIndex){
if (ledIndex > LED_COUNT) return 0;
return (ledIndex * 1.0/LED_COUNT) * INT16_MAX;
Copy link
Owner

@BaptisteHudyma BaptisteHudyma Aug 28, 2024

Choose a reason for hiding this comment

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

static constexpr float temp = * 1.0/LED_COUNT) * INT16_MAX;
return ledIndex * temp;

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.

2 participants