Skip to content

Commit

Permalink
Merge pull request #6 from vladkorotnev/develop
Browse files Browse the repository at this point in the history
v2.2
  • Loading branch information
vladkorotnev authored Jul 24, 2024
2 parents 600014d + f031d19 commit 23aa164
Show file tree
Hide file tree
Showing 34 changed files with 518 additions and 251 deletions.
10 changes: 10 additions & 0 deletions include/app/stopwatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <views/framework.h>

class AppShimStopwatch: public Composite {
public:
AppShimStopwatch(Beeper *);
~AppShimStopwatch();
private:
class StopwatchMainScreen;
StopwatchMainScreen * appRoot;
};
2 changes: 1 addition & 1 deletion include/app/timer_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <app/proto/navigation_stack.h>
#include <sound/sequencer.h>

class AppShimTimerEditor: public ProtoShimNavigationStack, DroppingDigits {
class AppShimTimerEditor: public ProtoShimNavigationStack {
public:
AppShimTimerEditor(Beeper *);
~AppShimTimerEditor();
Expand Down
1 change: 1 addition & 0 deletions include/app/weighing.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AppShimWeighing: public Composite {
WAIT_CONNECT,
WEIGHING
};
WeighingAppState curState;
void update_state(transition_type_t);
};
#endif
2 changes: 1 addition & 1 deletion include/devices/big_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Plasma Information System OS (not DOS, there's no disk in it!)
#define PRODUCT_NAME "PIS-OS"
#define PRODUCT_VERSION "2.1"
#define PRODUCT_VERSION "2.2"

// ---- Connection to DISP BOARD ----
const gpio_num_t HWCONF_PLASMA_DATABUS_GPIOS[] = {
Expand Down
2 changes: 1 addition & 1 deletion include/devices/smol_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// Plasma Information System OS (not DOS, there's no disk in it!)
#define PRODUCT_NAME "microPIS-OS"
#define PRODUCT_VERSION "2.1"
#define PRODUCT_VERSION "2.2"

// ---- Connection to beeper ----
const gpio_num_t HWCONF_BEEPER_GPIO = GPIO_NUM_12;
Expand Down
1 change: 1 addition & 0 deletions include/service/balance_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ void balance_board_start(SensorPool*);
void balance_board_scan(bool);
balance_board_state_t balance_board_state();
void balance_board_zero();
void balance_board_led(bool);
#endif
4 changes: 3 additions & 1 deletion include/service/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ tk_date_t get_current_date();
void set_current_time(tk_time_of_day_t);
/// @brief Set the current date without changing the timezone et al
void set_current_date(tk_date_t);
/// @brief Returns the system uptime as human-readable components
tk_time_of_day_t get_uptime();

tk_time_of_day operator -(const tk_time_of_day_t& a, const tk_time_of_day_t& b);
tk_time_of_day_t operator -(const tk_time_of_day_t& a, const tk_time_of_day_t& b);
bool operator==(const tk_time_of_day_t& a, const tk_time_of_day_t& b);
bool operator<(const tk_time_of_day_t& a, const tk_time_of_day_t& b);
bool operator<=(const tk_time_of_day_t& a, const tk_time_of_day_t& b);
Expand Down
1 change: 1 addition & 0 deletions include/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typedef enum device_state {
STATE_TIMER_EDITOR,
STATE_IDLE,
STATE_ALARMING,
STATE_STOPWATCH,
#if HAS(BALANCE_BOARD_INTEGRATION)
STATE_WEIGHING,
#endif
Expand Down
78 changes: 78 additions & 0 deletions include/views/common/dropping_digits.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,82 @@ class DroppingDigits {
void draw_dropping_number(FantaManipulator *fb, int current, int next, int phase, int left_offset);
void draw_dropping_digit(FantaManipulator *framebuffer, char current, char next, int phase, int left_offset);
const font_definition_t * font;
};

class DroppingDigitView: public Composable, DroppingDigits {
public:
int value;
DroppingDigitView(unsigned int digits, int initialValue, Beeper * b = nullptr):
DroppingDigits(),
value(initialValue),
digits(digits),
beeper(b),
disp_value { value },
phase { 0 },
dir { true } {
snprintf(fmt, 16, "%%0%dd", digits);
snprintf(buf_old, 16, fmt, disp_value);
snprintf(buf_new, 16, fmt, value);
width = digits * font->width;
}

void prepare() {
disp_value = value;
snprintf(buf_old, 16, fmt, value);
snprintf(buf_new, 16, fmt, disp_value);
}

void render(FantaManipulator *fb) {
if(phase > 0) {
if(dir) {
phase++;
} else {
phase--;
}
if(phase == 16 || phase == 0) {
phase = 0;
disp_value = value;
snprintf(buf_old, 16, fmt, disp_value);
}
}

int left_offset = 0;
for(int i = 0; i < digits; i++) {
draw_dropping_digit(fb, buf_old[i], buf_new[i], phase, left_offset);
left_offset += font->width;
}
}

void step() {
if(disp_value != value && phase == 0) {
if(disp_value - value == 1 || value - disp_value > 1) {
// scroll backward
phase = 16;
snprintf(buf_old, 16, fmt, value);
snprintf(buf_new, 16, fmt, disp_value);
dir = false;
} else {
// scroll forward
phase = 1;
snprintf(buf_old, 16, fmt, disp_value);
snprintf(buf_new, 16, fmt, value);
dir = true;
}
}

if(phase == 8 && beeper) {
beeper->beep_blocking(CHANNEL_AMBIANCE, 100, 10);
}
}

private:
char buf_old[16];
char buf_new[16];
char fmt[16];
int disp_value;
int digits;
int phase;
int wrapping_point;
bool dir;
Beeper * beeper;
};
2 changes: 1 addition & 1 deletion include/views/common/multiplexor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
typedef uint16_t view_id_t;

/// @brief Switches across multiple Renderables as desired
class ViewMultiplexor: public Renderable {
class ViewMultiplexor: public Composable {
public:
ViewMultiplexor();
~ViewMultiplexor();
Expand Down
3 changes: 2 additions & 1 deletion include/views/common/string_scroll.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#include <views/framework.h>

/// @brief Scrolling string view
class StringScroll: public Renderable {
class StringScroll: public Composable {
public:
StringScroll(const font_definition_t*, const char* string = nullptr);
int string_width;
bool scroll_only_if_not_fit;
bool stopped;
bool align_to_right;
bool start_at_visible;
int holdoff;
Expand Down
43 changes: 36 additions & 7 deletions include/views/common/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,52 @@ class Renderable {
virtual void cleanup() { }
};

class Composite: public Renderable {
class Composable: public Renderable {
public:
void add_subrenderable(Renderable * r) { subrenderables.push_back(r); }
int x_offset = 0;
int width = -1;
};

class ClipView: public Composable {
public:
ClipView(Renderable* content):
content(content)
{}

~ClipView() {
delete content;
}

protected:
Renderable * content;
};

class Composite: public Composable {
public:
void add_composable(Composable * r) { composables.push_back(r); }
void add_subrenderable(Renderable * r) { add_composable(new ClipView(r)); }
void prepare() {
for(Renderable *r: subrenderables) r->prepare();
for(Composable *r: composables) r->prepare();
}
void render(FantaManipulator*fb) {
for(Renderable *r: subrenderables) r->render(fb);
for(Composable *r: composables) {
if(r->x_offset <= 0 && r->width < 0) {
r->render(fb);
} else if(r->width > 0) {
FantaManipulator * temp = fb->slice(r->x_offset, r->width);
r->render(temp);
delete temp;
}
}
}
void step() {
for(Renderable *r: subrenderables) r->step();
for(Composable *r: composables) r->step();
}
void cleanup() {
for(Renderable *r: subrenderables) r->cleanup();
for(Renderable *r: composables) r->cleanup();
}
protected:
std::vector<Renderable*> subrenderables = {};
std::vector<Composable*> composables = {};
};

/// @brief Do not override the user-specified display time
Expand Down
10 changes: 5 additions & 5 deletions include/views/idle_screens/next_alarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include <views/common/dropping_digits.h>

/// @brief A view that shows the time remaining until the next alarm.
class NextAlarmView: public Screen, DroppingDigits {
class NextAlarmView: public Screen {
public:
NextAlarmView();
~NextAlarmView();
void prepare();
void render(FantaManipulator*);
void step();
Expand All @@ -18,9 +19,8 @@ class NextAlarmView: public Screen, DroppingDigits {
tk_time_of_day_t time_remaining;
bool show_alarm;

// For dropping digits
int disp_h, next_h, disp_m, next_m;
int phase;
const font_definition_t * font;
int disp_h, disp_m;
DroppingDigitView *hourView;
DroppingDigitView *minuteView;
};

36 changes: 25 additions & 11 deletions include/views/menu/date_setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <fonts.h>
#include <functional>

class MenuDateSettingView: public Renderable, DroppingDigits {
class MenuDateSettingView: public Composite {
public:
int year;
int month;
Expand All @@ -14,17 +14,32 @@ class MenuDateSettingView: public Renderable, DroppingDigits {
year(initialYear),
month(initialMonth),
day(initialDay),
prevYear(initialYear),
prevMonth(initialMonth),
prevDay(initialDay),
animationPhase { -1 },
yearView(new DroppingDigitView(4, initialYear, b)),
monthView(new DroppingDigitView(2, initialMonth, b)),
dayView(new DroppingDigitView(2, initialDay, b)),
cursorTimer { 0 },
cursorPosition { YEAR },
isShowingCursor { false },
onFinish(onFinish),
beeper(b),
DroppingDigits() {}
beeper(b) {
int char_count = 10; // YYYY/MM/dd
int text_width = char_count * xnu_font.width;
int left_offset = HWCONF_DISPLAY_WIDTH_PX/2 - text_width/2;

yearView->x_offset = left_offset;
monthView->x_offset = yearView->x_offset + yearView->width + xnu_font.width;
dayView->x_offset = monthView->x_offset + monthView->width + xnu_font.width;

add_composable(yearView);
add_composable(monthView);
add_composable(dayView);
}

~MenuDateSettingView() {
delete yearView, monthView, dayView;
}

void prepare();
void step();
void render(FantaManipulator *fb);

Expand All @@ -36,10 +51,9 @@ class MenuDateSettingView: public Renderable, DroppingDigits {
MONTH,
DAY
};
int prevYear;
int prevMonth;
int prevDay;
int animationPhase;
DroppingDigitView * yearView;
DroppingDigitView * monthView;
DroppingDigitView * dayView;
uint8_t cursorTimer;
DateCursorPosition cursorPosition;
bool isShowingCursor;
Expand Down
2 changes: 1 addition & 1 deletion include/views/menu/info_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MenuInfoItemView: public Composite {
MenuInfoItemView(const char * title, const char * subtitle);
~MenuInfoItemView();

private:
protected:
StringScroll * top_label;
StringScroll * bottom_label;
};
34 changes: 23 additions & 11 deletions include/views/menu/time_setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <fonts.h>
#include <sound/beeper.h>

class MenuTimeSettingView: public Renderable, DroppingDigits {
class MenuTimeSettingView: public Composite {
public:
int hour;
int minute;
Expand All @@ -15,18 +15,31 @@ class MenuTimeSettingView: public Renderable, DroppingDigits {
hour(initialHour),
minute(initialMinute),
second(initialSeconds),
prevHour(initialHour),
prevMinute(initialMinute),
prevSecond(initialSeconds),
hourView(new DroppingDigitView(2, initialHour, b)),
minuteView(new DroppingDigitView(2, initialMinute, b)),
secondView(new DroppingDigitView(2, initialSeconds, b)),
showSeconds(showSeconds),
animationPhase { -1 },
cursorTimer { 0 },
cursorPosition { CursorPosition::HOUR },
isShowingCursor { false },
onFinish(onFinish),
beeper(b),
DroppingDigits() {}
beeper(b) {
int char_count = showSeconds ? 8 : 5; // XX:XX:XX or XX:XX
int text_width = char_count * xnu_font.width;
int left_offset = HWCONF_DISPLAY_WIDTH_PX/2 - text_width/2;

hourView->x_offset = left_offset;
minuteView->x_offset = hourView->x_offset + hourView->width + xnu_font.width;
secondView->x_offset = minuteView->x_offset + minuteView->width + xnu_font.width;

add_composable(hourView);
add_composable(minuteView);
if(showSeconds) {
add_composable(secondView);
}
}

void prepare();
void step();
void render(FantaManipulator *fb);

Expand All @@ -38,11 +51,10 @@ class MenuTimeSettingView: public Renderable, DroppingDigits {
MINUTE,
SECOND
};
DroppingDigitView * hourView;
DroppingDigitView * minuteView;
DroppingDigitView * secondView;
bool showSeconds;
int prevHour;
int prevMinute;
int prevSecond;
int animationPhase;
uint8_t cursorTimer;
CursorPosition cursorPosition;
bool isShowingCursor;
Expand Down
Loading

0 comments on commit 23aa164

Please sign in to comment.