Skip to content

Commit

Permalink
Anti aliasing / Analog-Fitness Watchface / Cleanups (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmicro authored May 20, 2024
2 parents 12f69e1 + 77ed9b8 commit 2b56c3d
Show file tree
Hide file tree
Showing 53 changed files with 2,534 additions and 1,324 deletions.
20 changes: 16 additions & 4 deletions include/Arduino_Canvas_Graphics2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Arduino_GFX.h>
#include <gfx_2d_print.h>
#include "config_defaults.h"

class Arduino_Canvas_Graphics2D : public Graphics2DPrint {
public:
Expand All @@ -22,12 +23,23 @@ class Arduino_Canvas_Graphics2D : public Graphics2DPrint {
* we have copy-pasted this utility together...
*/

void begin(int32_t speed = GFX_NOT_DEFINED);
void writePixelPreclipped(int16_t x, int16_t y, uint16_t color);
void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void flush();

inline void begin(int32_t speed = GFX_NOT_DEFINED) {
_output->begin(speed);
// _output->fillScreen(BLACK);
}

inline void writePixelPreclipped(int16_t x, int16_t y, uint16_t color) {
this->drawPixel(x, y, color);
}
inline void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
this->drawVLine(x, y, h, color);
}
inline void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) {
this->drawHLine(x, y, w, color);
}

protected:
Arduino_G* _output;
int16_t _output_x, _output_y;
Expand Down
2 changes: 1 addition & 1 deletion include/OswAppV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class OswAppV2 {
};
// We intentionally do not provide an operation to implicitly convert to OswHal* to prevent accidental use of the wrong instance
};
OswHalProxy hal; // You guys are needing that anyways (but you often cache incorrectly), so it is now given to you <3
OswHalProxy hal; // You guys are needing that anyway (but you often cache incorrectly), so it is now given to you <3
class OswUiProxy {
public:
OswUI* operator->() {
Expand Down
34 changes: 17 additions & 17 deletions include/apps/games/brick_breaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class OswAppBrickBreaker : public OswApp {
const int playerY = 184;
const int gridW = 8;
const int gridH = 4;
const float xSensitivity = 0.75;
const float ySensitivity = 0.75;
const float xSensitivity = 0.75f;
const float ySensitivity = 0.75f;
const bool newGrid[4][8] = {
{0, 0, 1, 1, 1, 1, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1}
};
Expand All @@ -41,28 +41,28 @@ class OswAppBrickBreaker : public OswApp {
unsigned long lastmove = 0;
int lastpos = 0;

double ballPosx = 160;
double ballPosy = 120;
double ballSpdx = -2;
double ballSpdy = 4;
double absspd = 0;
double angleVar = 0;
double angleout = 0;
double angleout2 = 0;
double pHitPosition = 0;
double pHitAngle = 0;
double posAngle = 0;
double wallPosx = 0;
double wallPosy = 0;
double playerSpd = 0;
float ballPosx = 160;
float ballPosy = 120;
float ballSpdx = -2;
float ballSpdy = 4;
float absspd = 0;
float angleVar = 0;
float angleout = 0;
float angleout2 = 0;
float pHitPosition = 0;
float pHitAngle = 0;
float posAngle = 0;
float wallPosx = 0;
float wallPosy = 0;
float playerSpd = 0;

bool scoreUpdated = false;
bool grid[4][8] = {};
int hasbounced = 0;

int previousTime = 0;
int gameStart = 0;
double spd = 1;
float spd = 1;

float deltaSeconds = 0;

Expand Down
4 changes: 2 additions & 2 deletions include/apps/games/snake_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class OswAppSnakeGame : public OswApp {
//#define demo 1

// Change these values if sensitivity is too much/low
const float xSensitivity = 0.75;
const float ySensitivity = 0.75;
const float xSensitivity = 0.75f;
const float ySensitivity = 0.75f;

int score = 1;
int snake[snakeLength][2] = {{10, 10}};
Expand Down
46 changes: 46 additions & 0 deletions include/apps/watchfaces/OswAppWatchfaceFitnessAnalog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <osw_hal.h>
#include <osw_ui.h>
#include <OswAppV2.h>

// if you want a cool background image, enable the following define
//#define GIF_BG

#ifdef GIF_BG
class OswAppGifPlayer;
#endif
class OswAppWatchfaceFitnessAnalog : public OswAppV2
{
public:
constexpr static const char *APP_ID = "osw.wf.afit";

const char *getAppId() override;
const char *getAppName() override;

void onStart();
void onLoop() override;
void onDraw() override;
void onButton(Button id, bool up, ButtonStateNames state) override;
void onStop() override;

static uint32_t calculateDistance(uint32_t steps);

void timeDisplay(OswHal *hal, uint32_t hour, uint32_t minute, uint32_t second);
void timeDisplay(OswHal *hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon);
void dateDisplay(OswHal *hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon);

void test();

~OswAppWatchfaceFitnessAnalog() {}

private:
time_t lastTime = 0;
unsigned screen = 0;

void showFitnessTracking(OswHal *hal);
void drawWatchFace(OswHal *hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon);
void drawDateFace(OswHal *hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon);

#ifdef GIF_BG
OswAppGifPlayer* bgGif = nullptr;
#endif
};
10 changes: 6 additions & 4 deletions include/config_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#define DISP_H 240
#endif

// !! IMPORTANT: DISP_H must be divisible by DISP_CHUNK_H !!
#ifndef DISP_CHUNK_H
#define DISP_CHUNK_H 8
// !! IMPORTANT: DISP_H must be divisible by (1<<DISP_CHUNK_H_LD) !!
// DISP_H % (1<<DISP_CHUNK_H_LD) has to be zero
#ifndef DISP_CHUNK_H_LD
// 2^DISP_CHUNK_H_LD must be DISP_CHUNK_H
#define DISP_CHUNK_H_LD 3
#endif

/*
Expand Down Expand Up @@ -304,4 +306,4 @@
"zZOFli9d31kWTz9RvdVFGD/tSo7oBmF0Ixa1DVBzJ0RHfxBdiSprhTEUxOipakyA\n" \
"vGp4z7h/jnZymQyd/teRCBaho1+V\n" \
"-----END CERTIFICATE-----\n"
#endif
#endif
Loading

0 comments on commit 2b56c3d

Please sign in to comment.