Skip to content

Commit

Permalink
Text scroller driver
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Oct 29, 2023
1 parent 97d1be5 commit efb30a3
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 7 deletions.
1 change: 1 addition & 0 deletions openBeken_win32_mvsc2017.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
<ClCompile Include="src\driver\drv_test_drivers.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Win32 ScriptOnly|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\driver\drv_textScroller.c" />
<ClCompile Include="src\driver\drv_tm1637.c" />
<ClCompile Include="src\driver\drv_tm1638.c" />
<ClCompile Include="src\driver\drv_tm_gn_display_shared.c" />
Expand Down
3 changes: 3 additions & 0 deletions openBeken_win32_mvsc2017.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,9 @@
<ClCompile Include="src\driver\drv_pt6523.c">
<Filter>Drv</Filter>
</ClCompile>
<ClCompile Include="src\driver\drv_textScroller.c">
<Filter>Drv</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\new_cfg.h" />
Expand Down
5 changes: 5 additions & 0 deletions src/driver/drv_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ void DRV_ADCButton_RunFrame();

void PT6523_Init();
void PT6523_RunFrame();
void PT6523_DrawString(char gk[], int startOfs);
void PT6523_ClearString();

void TS_RunQuickTick();
void TS_Init();

void SM2135_Init();

Expand Down
7 changes: 7 additions & 0 deletions src/driver/drv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ static driver_t g_drivers[] = {
//drvdetail:"requires":""}
{ "PT6523", PT6523_Init, PT6523_RunFrame, NULL, NULL, NULL, NULL, false },
#endif
#ifdef ENABLE_DRIVER_TEXTSCROLLER
//drvdetail:{"name":"TextScroller",
//drvdetail:"title":"TODO",
//drvdetail:"descr":"BQQQK",
//drvdetail:"requires":""}
{ "TextScroller", TS_Init, NULL, NULL, TS_RunQuickTick, NULL, NULL, false },
#endif
#if PLATFORM_BEKEN
#if PLATFORM_BK7231N
//drvdetail:{"name":"SM16703P",
Expand Down
19 changes: 12 additions & 7 deletions src/driver/drv_pt6523.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void PT6523_shiftOut(byte *data, int totalBytes) {
}
}

void PT6523_Print() {
void PT6523_Refresh() {
HAL_PIN_SetOutputValue(pt_ce, 0);
// Address Data (A1- A8)
PT6523_shiftOut(&g_address,1);
Expand Down Expand Up @@ -130,10 +130,13 @@ void PT6523_SetLetters() {
j++;
}
}
void PT6523_DrawString(char gk[]) {
int d = 0;
for (int i = 0; i < 8; i++) {
int c = gk[i] - 32;
void PT6523_ClearString() {
memset(g_container, 0, sizeof(g_container));
}
void PT6523_DrawString(char gk[], int startOfs) {
int d = startOfs*2;
for (int i = startOfs; i < 8; i++) {
int c = gk[i- startOfs] - 32;
if (c >= 0 && c <= 94) {
g_container[d] = pt_character14SEG[c][0];
g_container[d + 1] = pt_character14SEG[c][1];
Expand All @@ -144,9 +147,11 @@ void PT6523_DrawString(char gk[]) {
}
d += 2;
}
PT6523_SetLetters();
}
void PT6523_RunFrame()
{
#if 0
for (int i = 0; i < sizeof(g_screen); i++) {
g_screen[i] = rand();
}
Expand All @@ -156,13 +161,13 @@ void PT6523_RunFrame()
g_symbols[i] = 0x0;// ff;// rand();
}
PT6523_DrawString("OpenBK ");
PT6523_SetLetters();
PT6523_AnimateVolume(loop);
g_symbolDisc = loop % 2;
BIT_SET_TO(g_screen[7], 3, g_symbolDisc);
loop++;
loop %= 8;
PT6523_Print();
PT6523_Refresh();
#endif
}


Expand Down
121 changes: 121 additions & 0 deletions src/driver/drv_textScroller.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@


#include "../new_common.h"
#include "../new_cfg.h"
#include "../quicktick.h"
// Commands register, execution API and cmd tokenizer
#include "../cmnds/cmd_public.h"
#include "../httpserver/new_http.h"
#include "../logging/logging.h"
#include "drv_local.h"

int g_maxScrollingText = 128;
int g_stepTimeMS = 500;
int g_stepCurMS = 0;
int g_curOfs;
int g_len;
char *g_buffer;

void TS_RunQuickTick() {
g_stepCurMS += g_deltaTimeMS;
if (g_stepCurMS > g_stepTimeMS) {
g_stepCurMS = 0;

int screenSize = 8;
#ifdef ENABLE_DRIVER_PT6523
if (DRV_IsRunning("PT6523")) {
screenSize = 8;
PT6523_ClearString();
if (g_curOfs < 0) {
PT6523_DrawString(g_buffer,-g_curOfs);
}
else {
PT6523_DrawString(g_buffer + g_curOfs,0);
}
PT6523_Refresh();
}
#endif
#ifdef ENABLE_DRIVER_MAX72XX
if (DRV_IsRunning("MAX72XX")) {
// TODO
// TODO screenSize = qqq;
}
#endif
#ifdef ENABLE_DRIVER_HT16K33
if (DRV_IsRunning("HT16K33")) {
// TODO
// TODO screenSize = qqq;
}
#endif
g_curOfs++;
if (g_curOfs + 1 >= g_len) {
g_curOfs = -screenSize;
}
}
}
void TS_PrintStringAt(const char *s, int ofs, int maxLen) {
while (*s && maxLen) {
g_buffer[ofs] = *s;
ofs++;
maxLen--;
s++;
}
g_len = strlen(g_buffer);
}
void TS_SetText(const char *s) {
memset(g_buffer, 0, g_maxScrollingText);
strcpy(g_buffer, s);
g_len = strlen(g_buffer);
}
static commandResult_t CMD_TS_Clear(const void *context, const char *cmd, const char *args, int flags) {
TS_SetText("");


return CMD_RES_OK;
}
// TS_Print [StartOfs] [MaxLenOr0] [StringText] [optionalBClampWithZeroesForClock]
// setChannel 10 12
// TS_Print 0 2 $CH10 1
// TS_Print 0 9999 "2023-10-29 15 54"
static commandResult_t CMD_TS_Print(const void *context, const char *cmd, const char *args, int flags) {
int ofs;
int maxLen;
const char *s;
int sLen;
int iPadZeroes;

Tokenizer_TokenizeString(args, TOKENIZER_ALLOW_QUOTES);

if (Tokenizer_GetArgsCount() <= 2) {
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}

ofs = Tokenizer_GetArgInteger(0);
maxLen = Tokenizer_GetArgInteger(1);
s = Tokenizer_GetArg(2);


if (maxLen <= 0) {
maxLen = 999;
}
if (Tokenizer_GetArgInteger(3)) {
sLen = strlen(s);
if (sLen < maxLen) {
iPadZeroes = maxLen - sLen;
TS_PrintStringAt("00000", ofs, iPadZeroes);
ofs += iPadZeroes;
maxLen -= iPadZeroes;
}
}
TS_PrintStringAt(s, ofs, maxLen);

return CMD_RES_OK;
}
void TS_Init() {
g_buffer = malloc(g_maxScrollingText);
TS_SetText("THIS IS A SCROLLING TEXT 123456789");

CMD_RegisterCommand("TS_Clear", CMD_TS_Clear, NULL);
CMD_RegisterCommand("TS_Print", CMD_TS_Print, NULL);
}

2 changes: 2 additions & 0 deletions src/obk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define ENABLE_DRIVER_CHARGINGLIMIT 1
#define ENABLE_DRIVER_BATTERY 1
#define ENABLE_DRIVER_PT6523 1
#define ENABLE_DRIVER_TEXTSCROLLER 1


#elif PLATFORM_BL602
Expand All @@ -75,6 +76,7 @@
#define ENABLE_DRIVER_BL0942SPI 1
#define ENABLE_DRIVER_CSE7766 1
#define ENABLE_DRIVER_PT6523 0
#define ENABLE_DRIVER_TEXTSCROLLER 0
#define ENABLE_DRIVER_TUYAMCU 1
//#define ENABLE_DRIVER_HT16K33 1
//#define ENABLE_DRIVER_MAX72XX 1
Expand Down

0 comments on commit efb30a3

Please sign in to comment.