-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Feature/add follower counter #4970
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2fb0a25
Add social counter skeleton
medeiroz 50bae6a
Merge branch 'wled:main' into feature/add-follower-counter
medeiroz c72e12e
Added simulator counter
medeiroz 0c8a50e
Merge branch 'feature/add-follower-counter' of github.com:medeiroz/WL…
medeiroz 3a019d7
WIP adding 7 segments social counter
medeiroz b7fb280
Added strategy pattener
medeiroz 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name:": "social_counter", | ||
"dependencies": {} | ||
} |
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,78 @@ | ||
# Social Counter Usermod | ||
|
||
This usermod allows you to display follower counts from various social networks on a 7-segment display using WLED LEDs. | ||
|
||
## Installation | ||
|
||
There are two ways to enable this usermod: | ||
|
||
### Method 1: Using platformio_override.ini (Recommended) | ||
|
||
Create or modify your `platformio_override.ini` file to include the Social Counter: | ||
|
||
```ini | ||
[env:esp32dev_social_counter] | ||
extends = env:esp32dev | ||
custom_usermods = social_counter | ||
``` | ||
|
||
### Method 2: Using the compile option | ||
|
||
Add the compile-time option `-D USERMOD_SOCIAL_COUNTER` to your `platformio.ini` (or `platformio_override.ini`) or use `#define USERMOD_SOCIAL_COUNTER` in `my_config.h`. | ||
|
||
## Usage | ||
|
||
After installation, configure the module through the WLED interface: | ||
|
||
1. Access the WLED web interface | ||
2. Go to "Config" > "Usermods" | ||
3. Find the "Social Counter" section | ||
4. Set: | ||
- Enable/disable the module | ||
- Desired social network (Instagram, TikTok, Twitch, YouTube) | ||
- Link to your profile | ||
- Update interval (in seconds) | ||
- WLED segment index to use for display | ||
- LEDs per segment | ||
- Digit spacing | ||
- Segment direction | ||
|
||
## Supported Social Networks | ||
|
||
- TikTok | ||
- Twitch | ||
- YouTube | ||
|
||
## 7-Segment Display | ||
|
||
This usermod uses a 7-segment display to show the follower count: | ||
|
||
- Segments are arranged in the FABCDEG pattern | ||
- You can define how many LEDs each segment uses | ||
- The display automatically uses WLED segments and their defined colors | ||
- The maximum number of digits displayed is automatically calculated based on segment size | ||
|
||
## Customization | ||
|
||
The code uses the Strategy pattern to implement different social networks. You can easily add support for new social networks by creating a new strategy class in the `strategies` folder. | ||
|
||
## File Structure | ||
|
||
- `usermod_v2_social_counter.cpp` - Main usermod implementation | ||
- `SocialNetworkTypes.h` - Social network type definitions | ||
- `SocialNetworkFactory.h` - Factory for creating strategy instances | ||
- `strategies/` - Folder containing implementations for each social network | ||
- `SocialNetworkStrategy.h` - Interface for strategies | ||
- `InstagramStrategy.h` - Instagram implementation | ||
- `TikTokStrategy.h` - TikTok implementation | ||
- `TwitchStrategy.h` - Twitch implementation | ||
- `YouTubeStrategy.h` - YouTube implementation | ||
|
||
## Debugging | ||
|
||
If you're experiencing issues: | ||
|
||
1. Enable serial logging in WLED | ||
2. Check for messages with the "Social Counter" prefix in the serial output | ||
3. Verify that the time interval configuration is correct |
41 changes: 41 additions & 0 deletions
41
usermods/usermod_v2_social_counter/social_network_factory.h
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,41 @@ | ||
#pragma once | ||
|
||
#include "strategies/social_network_strategy.h" | ||
#include "social_network_types.h" | ||
#include "strategies/mock_strategy.h" | ||
#include "strategies/instagram_strategy.h" | ||
#include "strategies/youtube_strategy.h" | ||
#include "strategies/tiktok_strategy.h" | ||
#include "strategies/twitch_strategy.h" | ||
#include <memory> | ||
|
||
class SocialNetworkFactory | ||
{ | ||
public: | ||
static std::unique_ptr<SocialNetworkStrategy> createStrategy(int socialType) | ||
{ | ||
switch (socialType) | ||
{ | ||
case SOCIAL_COUNTER_MOCK: | ||
return std::unique_ptr<SocialNetworkStrategy>(new MockStrategy()); | ||
|
||
case SOCIAL_COUNTER_INSTAGRAM: | ||
return std::unique_ptr<SocialNetworkStrategy>(new InstagramStrategy()); | ||
|
||
case SOCIAL_COUNTER_YOUTUBE: | ||
return std::unique_ptr<SocialNetworkStrategy>(new YouTubeStrategy()); | ||
|
||
case SOCIAL_COUNTER_TIKTOK: | ||
return std::unique_ptr<SocialNetworkStrategy>(new TikTokStrategy()); | ||
|
||
case SOCIAL_COUNTER_TWITCH: | ||
return std::unique_ptr<SocialNetworkStrategy>(new TwitchStrategy()); | ||
|
||
// Você pode adicionar outras redes sociais à medida que implementá-las | ||
|
||
default: | ||
// Se o tipo não for reconhecido, usa Instagram como fallback | ||
return std::unique_ptr<SocialNetworkStrategy>(new InstagramStrategy()); | ||
} | ||
} | ||
}; |
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,14 @@ | ||
#pragma once | ||
|
||
// Definição dos tipos de redes sociais | ||
#define SOCIAL_COUNTER_MOCK 0 | ||
#define SOCIAL_COUNTER_INSTAGRAM 1 | ||
#define SOCIAL_COUNTER_TIKTOK 2 | ||
#define SOCIAL_COUNTER_TWITCH 3 | ||
#define SOCIAL_COUNTER_YOUTUBE 4 | ||
|
||
// Tipos de métrica disponíveis (por enquanto só Instagram usa) | ||
#define METRIC_FOLLOWERS 0 | ||
#define METRIC_VIEWS 1 | ||
#define METRIC_LIVE 2 | ||
#define METRIC_SUBSCRIBERS 3 |
71 changes: 71 additions & 0 deletions
71
usermods/usermod_v2_social_counter/strategies/instagram_strategy.h
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,71 @@ | ||
#pragma once | ||
|
||
#include "social_network_strategy.h" | ||
#include "../social_network_types.h" | ||
#include <Arduino.h> | ||
#include <HTTPClient.h> | ||
|
||
// Variável global para simular o contador | ||
static int mockCounter = -1; | ||
|
||
class InstagramStrategy : public SocialNetworkStrategy | ||
{ | ||
public: | ||
bool fetchMetric(int metric, const String &link, int &count) override | ||
{ | ||
// Simula diferentes métricas para o Instagram (ainda que iguais por enquanto) | ||
switch (metric) | ||
{ | ||
case METRIC_FOLLOWERS: | ||
case METRIC_VIEWS: | ||
case METRIC_LIVE: | ||
case METRIC_SUBSCRIBERS: | ||
default: | ||
return simulateMockFollowerCount(count); | ||
} | ||
} | ||
|
||
String getName() override | ||
{ | ||
return "Instagram"; | ||
} | ||
|
||
int getType() override | ||
{ | ||
return SOCIAL_COUNTER_INSTAGRAM; | ||
} | ||
|
||
private: | ||
/** | ||
* Simula a contagem de seguidores: 111111, 222222, ... | ||
*/ | ||
bool simulateMockFollowerCount(int &count) | ||
{ | ||
mockCounter = (mockCounter + 1) % 10; | ||
|
||
int repeatedDigits = 0; | ||
for (int i = 0; i < 6; i++) | ||
{ | ||
repeatedDigits = repeatedDigits * 10 + mockCounter; | ||
} | ||
|
||
count = repeatedDigits; | ||
|
||
Serial.printf("[MOCK] Instagram seguidores simulados: %d\n", count); | ||
return true; | ||
} | ||
|
||
/** | ||
* Extrai o nome de usuário a partir de uma URL do Instagram | ||
*/ | ||
String extractUsername(const String &link) | ||
{ | ||
int start = link.indexOf("instagram.com/"); | ||
if (start == -1) | ||
return link; | ||
|
||
start += 14; | ||
int end = link.indexOf("/", start); | ||
return (end == -1) ? link.substring(start) : link.substring(start, end); | ||
} | ||
}; |
35 changes: 35 additions & 0 deletions
35
usermods/usermod_v2_social_counter/strategies/mock_strategy.h
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,35 @@ | ||
#pragma once | ||
|
||
#include "social_network_strategy.h" | ||
#include "../social_network_types.h" | ||
#include <Arduino.h> | ||
|
||
// Simula um contador incremental por métrica | ||
class MockStrategy : public SocialNetworkStrategy | ||
{ | ||
public: | ||
bool fetchMetric(int metric, const String &link, int &count) override | ||
{ | ||
static int values[4] = {0, 1000, 5000, 100}; | ||
|
||
// Simula cada métrica com incremento independente | ||
values[metric] += (metric + 1) * 111; // muda a taxa por tipo | ||
if (values[metric] > 999999) | ||
values[metric] = 0; | ||
|
||
count = values[metric]; | ||
|
||
Serial.printf("[MOCK] Métrica %d simulada: %d\n", metric, count); | ||
return true; | ||
} | ||
|
||
String getName() override | ||
{ | ||
return "Mock"; | ||
} | ||
|
||
int getType() override | ||
{ | ||
return SOCIAL_COUNTER_MOCK; | ||
} | ||
}; |
14 changes: 14 additions & 0 deletions
14
usermods/usermod_v2_social_counter/strategies/social_network_strategy.h
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,14 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
class SocialNetworkStrategy | ||
{ | ||
public: | ||
virtual ~SocialNetworkStrategy() = default; | ||
|
||
// Métodos que toda rede social deve implementar | ||
virtual bool fetchMetric(int metric, const String &link, int &count) = 0; | ||
virtual String getName() = 0; | ||
virtual int getType() = 0; | ||
}; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard the metric index before touching
values
selectedMetric
ultimately comes from user-configurable JSON/UI input. If someone saves an out-of-range value (or a future metric constant exceeds 3),values[metric]
writes past the four-element array, corrupting memory and crashing the MCU. Add a bounds check before usingmetric
, bail out on invalid input, and keep the rest of the logic unchanged.📝 Committable suggestion
🤖 Prompt for AI Agents