Skip to content

Commit

Permalink
Merge pull request #145 from laamaa/model2_support
Browse files Browse the repository at this point in the history
Model2 support
  • Loading branch information
laamaa authored Apr 18, 2024
2 parents c4925e5 + 63e5f55 commit 95591f0
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 321 deletions.
5 changes: 5 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build": {
"dockerfile": "Dockerfile"
}
}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM mcr.microsoft.com/devcontainers/cpp
RUN apt-get update && apt-get install -y libsdl2-dev libserialport-dev
6 changes: 3 additions & 3 deletions src/SDL2_inprint.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Bitmap font routine by driedfruit, https://github.com/driedfruit/SDL_inprint
// Based on bitmap font routine by driedfruit, https://github.com/driedfruit/SDL_inprint
// Released into public domain.
// Modified to support adding a background to text.

#ifndef SDL2_inprint_h
#define SDL2_inprint_h

#include "inline_font.h"
#include <SDL.h>

extern void prepare_inline_font(unsigned char bits[],int font_width, int font_height);
extern void prepare_inline_font(struct inline_font *font);
extern void kill_inline_font(void);

extern void inrenderer(SDL_Renderer *renderer);
Expand Down
16 changes: 10 additions & 6 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum m8_command_bytes {
draw_character_command_datalength = 12,
draw_oscilloscope_waveform_command = 0xFC,
draw_oscilloscope_waveform_command_mindatalength = 1 + 3,
draw_oscilloscope_waveform_command_maxdatalength = 1 + 3 + 320,
draw_oscilloscope_waveform_command_maxdatalength = 1 + 3 + 480,
joypad_keypressedstate_command = 0xFB,
joypad_keypressedstate_command_datalength = 3,
system_info_command = 0xFF,
Expand Down Expand Up @@ -58,6 +58,7 @@ int process_command(uint8_t *data, uint32_t size) {
{decodeInt16(recv_buf, 5), decodeInt16(recv_buf, 7)}, // size w/h
{recv_buf[9], recv_buf[10], recv_buf[11]}}; // color r/g/b

//SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,"x:%i, y:%i, w:%i, h:%i",rectcmd.pos.x,rectcmd.pos.y,rectcmd.size.width,rectcmd.size.height);
draw_rectangle(&rectcmd);
return 1;
}
Expand Down Expand Up @@ -144,7 +145,8 @@ int process_command(uint8_t *data, uint32_t size) {
break;
}

char *hwtype[3] = {"Headless", "Beta M8", "Production M8"};
char *hwtype[4] = {"Headless", "Beta M8", "Production M8",
"Production M8 Model:02"};

static int system_info_printed = 0;

Expand All @@ -154,17 +156,19 @@ int process_command(uint8_t *data, uint32_t size) {
system_info_printed = 1;
}

if (recv_buf[5] == 0x01) {
set_large_mode(1);
if (recv_buf[1] == 0x03) {
set_m8_model(1);
} else {
set_large_mode(0);
set_m8_model(0);
}

set_font_mode(recv_buf[5]);

return 1;
break;
}

default:

SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Invalid packet\n");
dump_packet(size, recv_buf);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct draw_character_command {

struct draw_oscilloscope_waveform_command {
struct color color;
uint8_t waveform[320];
uint8_t waveform[480];
uint16_t waveform_size;
};

Expand Down
15 changes: 15 additions & 0 deletions src/font1.h

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/font2.h

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/font3.h

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/font4.h

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/font5.h

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/fx_cube.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color) {
SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(fx_renderer);

inprint(fx_renderer, text_disconnected, 150, 228, 0xFFFFFF, 0x000000);
inprint(fx_renderer, text_disconnected, 130, 228, 0xFFFFFF, 0x000000);
inprint(fx_renderer, text_m8c, 2, 2, 0xFFFFFF, 0x000000);

SDL_SetRenderTarget(fx_renderer, og_target);
Expand All @@ -79,7 +79,7 @@ void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color) {
SDL_memcpy(nodes, default_nodes, sizeof(default_nodes));

scale(50, 50, 50);
rotate_cube(M_PI / 4, SDL_atan(SDL_sqrt(2)));
rotate_cube(M_PI / 6, SDL_atan(SDL_sqrt(2)));

SDL_SetTextureBlendMode(texture_cube, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(texture_text, SDL_BLENDMODE_BLEND);
Expand All @@ -99,8 +99,8 @@ void fx_cube_update() {
SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(fx_renderer);

int seconds = SDL_GetTicks() / 1000;
float scalefactor = 1 + (SDL_sin(seconds) * 0.01);
unsigned int seconds = SDL_GetTicks() / 1000;
float scalefactor = 1 + (SDL_sin(seconds) * 0.005);

scale(scalefactor, scalefactor, scalefactor);
rotate_cube(M_PI / 180, M_PI / 270);
Expand Down
12 changes: 9 additions & 3 deletions src/inline_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
#define INLINE_FONT_H_

struct inline_font {
int width;
int height;
unsigned char bits[];
const int width;
const int height;
const int glyph_x;
const int glyph_y;
const int screen_offset_x;
const int screen_offset_y;
const int text_offset_y;
const long image_size;
const unsigned char image_data[];
};

#endif
133 changes: 0 additions & 133 deletions src/inline_font_large.h

This file was deleted.

84 changes: 0 additions & 84 deletions src/inline_font_small.h

This file was deleted.

Loading

0 comments on commit 95591f0

Please sign in to comment.