<commit_before>#ifndef PEBBLEBIKE_H
#define PEBBLEBIKE_H

#include "pebble.h"
#include "config.h"
#include "colors.h"
#include "sizes.h"

#ifndef PBL_IF_ROUND_ELSE
#define PBL_IF_ROUND_ELSE(if_true, if_false) (if_false)
#endif

enum {
  MSG_LOCATION_DATA = 0x13,  // TUPLE_BYTE_ARRAY
  STATE_CHANGED = 0x14,
  MSG_VERSION_PEBBLE = 0x15,
  MSG_VERSION_ANDROID = 0x16,
  MSG_LIVE_SHORT = 0x17,
  //MSG_LIVE_ASK_NAMES = 0x18,
  MSG_LIVE_NAME0 = 0x19,
  MSG_LIVE_NAME1 = 0x20,
  MSG_LIVE_NAME2 = 0x21,
  MSG_LIVE_NAME3 = 0x22,
  MSG_LIVE_NAME4 = 0x23,
  MSG_BATTERY_LEVEL = 0x24,
  MSG_LOCATION_DATA_V2 = 0x25,
  MSG_LOCATION_DATA_V3 = 0x26,
  MSG_SENSOR_TEMPERATURE = 0x27,
  MSG_CONFIG = 0x28,
};

enum {
  STATE_STOP = 0,
  STATE_START = 1,
};

enum {
  PLAY_PRESS = 0x0,
  STOP_PRESS = 0x1,
  REFRESH_PRESS = 0x2,
  CMD_BUTTON_PRESS = 0x4,

  ORUXMAPS_START_RECORD_CONTINUE_PRESS = 0x5,
  ORUXMAPS_STOP_RECORD_PRESS = 0x6,
  ORUXMAPS_NEW_WAYPOINT_PRESS = 0x7,
};

enum {
  UNITS_IMPERIAL = 0x0,
  UNITS_METRIC = 0x1,
  UNITS_NAUTICAL_IMPERIAL = 0x2,
  UNITS_NAUTICAL_METRIC = 0x3,
  UNITS_RUNNING_IMPERIAL = 0x4,
  UNITS_RUNNING_METRIC = 0x5,
};

enum {
  PAGE_SPEED = 0,
  PAGE_HEARTRATE = 1,
  PAGE_ALTITUDE = 2,
  PAGE_LIVE_TRACKING = 3,
  PAGE_MAP = 4,
  PAGE_DEBUG1 = 5,
  PAGE_DEBUG2 = 6,
};
#define PAGE_FIRST PAGE_SPEED
enum {
  PERSIST_UNITS_KEY = 0x0,
  PERSIST_CONFIG_KEY = 0x1,
  PERSIST_VERSION = 0x2,
};

#if DEBUG
#define NUMBER_OF_PAGES 7
#endif

#if !DEBUG
#define NUMBER_OF_PAGES 5
#endif

#ifdef PBL_PLATFORM_APLITE
// don't deinit objects in deinit -- save at least 700 bytes
#define APP_DEINIT false
#else
#define APP_DEINIT true
#endif

#define SPEED_UNIT_IMPERIAL "mph"
#define SPEED_UNIT_METRIC "km/h"
#define SPEED_UNIT_NAUTICAL "kn"
#define SPEED_UNIT_RUNNING_IMPERIAL "min/m"
#define SPEED_UNIT_RUNNING_METRIC "min/km"
#define DISTANCE_UNIT_IMPERIAL "miles"
#define DISTANCE_UNIT_METRIC "km"
#define DISTANCE_UNIT_NAUTICAL "nm"
#define ALTITUDE_UNIT_METRIC "m"
#define ALTITUDE_UNIT_IMPERIAL "ft"
#define ASCENT_RATE_UNIT_METRIC "m/h"
#define ASCENT_RATE_UNIT_IMPERIAL "ft/h"
#define HEART_RATE_UNIT "bpm"
#define TEMPERATURE_UNIT_METRIC "°C"
#define TEMPERATURE_UNIT_IMPERIAL "°F"
// Don't use field values to sort (only to save - persistent)
enum {
  FIELD_ACCURACY,
  FIELD_ALTITUDE,
  FIELD_ASCENT,
  FIELD_ASCENTRATE,
  FIELD_AVGSPEED,
  FIELD_BEARING,
  FIELD_CADENCE,
  FIELD_DISTANCE,
  FIELD_DURATION,
  FIELD_HEARTRATE,
  //FIELD_LAT,
  //FIELD_LON,
  FIELD_MAXSPEED,
  //FIELD_NBASCENT,
  FIELD_SLOPE,
  FIELD_SPEED,
  FIELD_TEMPERATURE,
  //FIELD_TIME,
#ifdef PBL_HEALTH
  FIELD_STEPS,
  FIELD_STEPS_CADENCE,
#endif
  FIELD_ALTITUDE_DATA_AND_GRAPH,
  FIELD_ALTITUDE_GRAPH_ONLY,
  FIELD_ASCENTRATE_DATA_AND_GRAPH,
  FIELD_ASCENTRATE_GRAPH_ONLY,
  FIELD_HEARTRATE_DATA_AND_GRAPH,
  FIELD_HEARTRATE_GRAPH_ONLY,
  FIELD_SPEED_DATA_AND_GRAPH,
  FIELD_SPEED_GRAPH_ONLY,
  FIELD__UNUSED,
};
typedef struct TopBarLayer {
  Layer *layer;
  TextLayer *time_layer;
  TextLayer *accuracy_layer;
  GBitmap *bluetooth_image;
  BitmapLayer *bluetooth_layer;
} TopBarLayer;

/*typedef struct SpeedLayer {
 Layer *layer;
 char* text;
 } SpeedLayer;*/

typedef struct FieldConfig {
  uint8_t type;
  ///todo remove type_index?
  uint8_t type_index;
} FieldConfig;
typedef struct ScreenConfig {
  FieldConfig field_top;
  FieldConfig field_top2;
  FieldConfig field_bottom_left;
  FieldConfig field_bottom_right;
} ScreenConfig;
typedef struct FieldLayer {
  //Layer *main_layer;
  ///@todo remove title_layer ? used only for ScreenBLayer
  //TextLayer *title_layer;
  TextLayer *data_layer;
  TextLayer *unit_layer;
} FieldLayer;

typedef struct ScreenLayer {
  FieldLayer field_top;
  FieldLayer field_top2;
  FieldLayer field_bottom_left;
  FieldLayer field_bottom_right;
} ScreenLayer;

typedef struct AppData {
  Window *window;

  Layer *page_speed;
  MenuLayer *page_live_tracking;
  Layer *page_map;

#if DEBUG
  Layer *page_debug1;
  Layer *page_debug2;
#endif

  TopBarLayer topbar_layer;

  ScreenLayer screenSpeed_layer;
  //ScreenBLayer screenB_layer;

  ScreenConfig screenA_config;
  ScreenConfig screenB_config;

  //FieldLayer altitude_accuracy;

  TextLayer *live_tracking_layer;
#if DEBUG
  TextLayer *debug1_layer;
  TextLayer *debug2_layer;
#endif

  char time[6];  // xx:xx, \0 terminated
  char speed[16];
  char distance[6];
  char avgspeed[6];
  char altitude[6];
  char ascent[8];
  char ascentrate[8];
  char slope[8];
  char accuracy[5];
  char bearing[4];
  char elapsedtime[8];
  char maxspeed[8];
  //char lat[8];
  //char lon[8];
  //char nbascent[8];
  char heartrate[8];
  char cadence[8];
  char temperature[7];
  char steps[7];
  char steps_cadence[7];

#if DEBUG
  char debug1[200];
  char debug2[200];
#endif
  char unitsSpeedOrHeartRate[8];
  char unitsSpeed[8];<commit_msg>Fix duration (>10h)<commit_after>#ifndef PEBBLEBIKE_H
#define PEBBLEBIKE_H

#include "pebble.h"
#include "config.h"
#include "colors.h"
#include "sizes.h"

#ifndef PBL_IF_ROUND_ELSE
#define PBL_IF_ROUND_ELSE(if_true, if_false) (if_false)
#endif

enum {
  MSG_LOCATION_DATA = 0x13,  // TUPLE_BYTE_ARRAY
  STATE_CHANGED = 0x14,
  MSG_VERSION_PEBBLE = 0x15,
  MSG_VERSION_ANDROID = 0x16,
  MSG_LIVE_SHORT = 0x17,
  //MSG_LIVE_ASK_NAMES = 0x18,
  MSG_LIVE_NAME0 = 0x19,
  MSG_LIVE_NAME1 = 0x20,
  MSG_LIVE_NAME2 = 0x21,
  MSG_LIVE_NAME3 = 0x22,
  MSG_LIVE_NAME4 = 0x23,
  MSG_BATTERY_LEVEL = 0x24,
  MSG_LOCATION_DATA_V2 = 0x25,
  MSG_LOCATION_DATA_V3 = 0x26,
  MSG_SENSOR_TEMPERATURE = 0x27,
  MSG_CONFIG = 0x28,
};

enum {
  STATE_STOP = 0,
  STATE_START = 1,
};

enum {
  PLAY_PRESS = 0x0,
  STOP_PRESS = 0x1,
  REFRESH_PRESS = 0x2,
  CMD_BUTTON_PRESS = 0x4,

  ORUXMAPS_START_RECORD_CONTINUE_PRESS = 0x5,
  ORUXMAPS_STOP_RECORD_PRESS = 0x6,
  ORUXMAPS_NEW_WAYPOINT_PRESS = 0x7,
};

enum {
  UNITS_IMPERIAL = 0x0,
  UNITS_METRIC = 0x1,
  UNITS_NAUTICAL_IMPERIAL = 0x2,
  UNITS_NAUTICAL_METRIC = 0x3,
  UNITS_RUNNING_IMPERIAL = 0x4,
  UNITS_RUNNING_METRIC = 0x5,
};

enum {
  PAGE_SPEED = 0,
  PAGE_HEARTRATE = 1,
  PAGE_ALTITUDE = 2,
  PAGE_LIVE_TRACKING = 3,
  PAGE_MAP = 4,
  PAGE_DEBUG1 = 5,
  PAGE_DEBUG2 = 6,
};
#define PAGE_FIRST PAGE_SPEED
enum {
  PERSIST_UNITS_KEY = 0x0,
  PERSIST_CONFIG_KEY = 0x1,
  PERSIST_VERSION = 0x2,
};

#if DEBUG
#define NUMBER_OF_PAGES 7
#endif

#if !DEBUG
#define NUMBER_OF_PAGES 5
#endif

#ifdef PBL_PLATFORM_APLITE
// don't deinit objects in deinit -- save at least 700 bytes
#define APP_DEINIT false
#else
#define APP_DEINIT true
#endif

#define SPEED_UNIT_IMPERIAL "mph"
#define SPEED_UNIT_METRIC "km/h"
#define SPEED_UNIT_NAUTICAL "kn"
#define SPEED_UNIT_RUNNING_IMPERIAL "min/m"
#define SPEED_UNIT_RUNNING_METRIC "min/km"
#define DISTANCE_UNIT_IMPERIAL "miles"
#define DISTANCE_UNIT_METRIC "km"
#define DISTANCE_UNIT_NAUTICAL "nm"
#define ALTITUDE_UNIT_METRIC "m"
#define ALTITUDE_UNIT_IMPERIAL "ft"
#define ASCENT_RATE_UNIT_METRIC "m/h"
#define ASCENT_RATE_UNIT_IMPERIAL "ft/h"
#define HEART_RATE_UNIT "bpm"
#define TEMPERATURE_UNIT_METRIC "°C"
#define TEMPERATURE_UNIT_IMPERIAL "°F"
// Don't use field values to sort (only to save - persistent)
enum {
  FIELD_ACCURACY,
  FIELD_ALTITUDE,
  FIELD_ASCENT,
  FIELD_ASCENTRATE,
  FIELD_AVGSPEED,
  FIELD_BEARING,
  FIELD_CADENCE,
  FIELD_DISTANCE,
  FIELD_DURATION,
  FIELD_HEARTRATE,
  //FIELD_LAT,
  //FIELD_LON,
  FIELD_MAXSPEED,
  //FIELD_NBASCENT,
  FIELD_SLOPE,
  FIELD_SPEED,
  FIELD_TEMPERATURE,
  //FIELD_TIME,
#ifdef PBL_HEALTH
  FIELD_STEPS,
  FIELD_STEPS_CADENCE,
#endif
  FIELD_ALTITUDE_DATA_AND_GRAPH,
  FIELD_ALTITUDE_GRAPH_ONLY,
  FIELD_ASCENTRATE_DATA_AND_GRAPH,
  FIELD_ASCENTRATE_GRAPH_ONLY,
  FIELD_HEARTRATE_DATA_AND_GRAPH,
  FIELD_HEARTRATE_GRAPH_ONLY,
  FIELD_SPEED_DATA_AND_GRAPH,
  FIELD_SPEED_GRAPH_ONLY,
  FIELD__UNUSED,
};
typedef struct TopBarLayer {
  Layer *layer;
  TextLayer *time_layer;
  TextLayer *accuracy_layer;
  GBitmap *bluetooth_image;
  BitmapLayer *bluetooth_layer;
} TopBarLayer;

/*typedef struct SpeedLayer {
 Layer *layer;
 char* text;
 } SpeedLayer;*/

typedef struct FieldConfig {
  uint8_t type;
  ///todo remove type_index?
  uint8_t type_index;
} FieldConfig;
typedef struct ScreenConfig {
  FieldConfig field_top;
  FieldConfig field_top2;
  FieldConfig field_bottom_left;
  FieldConfig field_bottom_right;
} ScreenConfig;
typedef struct FieldLayer {
  //Layer *main_layer;
  ///@todo remove title_layer ? used only for ScreenBLayer
  //TextLayer *title_layer;
  TextLayer *data_layer;
  TextLayer *unit_layer;
} FieldLayer;

typedef struct ScreenLayer {
  FieldLayer field_top;
  FieldLayer field_top2;
  FieldLayer field_bottom_left;
  FieldLayer field_bottom_right;
} ScreenLayer;

typedef struct AppData {
  Window *window;

  Layer *page_speed;
  MenuLayer *page_live_tracking;
  Layer *page_map;

#if DEBUG
  Layer *page_debug1;
  Layer *page_debug2;
#endif

  TopBarLayer topbar_layer;

  ScreenLayer screenSpeed_layer;
  //ScreenBLayer screenB_layer;

  ScreenConfig screenA_config;
  ScreenConfig screenB_config;

  //FieldLayer altitude_accuracy;

  TextLayer *live_tracking_layer;
#if DEBUG
  TextLayer *debug1_layer;
  TextLayer *debug2_layer;
#endif

  char time[6];  // xx:xx, \0 terminated
  char speed[16];
  char distance[6];
  char avgspeed[6];
  char altitude[6];
  char ascent[8];
  char ascentrate[8];
  char slope[8];
  char accuracy[5];
  char bearing[4];
  char elapsedtime[9]; // xx:xx:xx, \0 terminated
  char maxspeed[8];
  //char lat[8];
  //char lon[8];
  //char nbascent[8];
  char heartrate[8];
  char cadence[8];
  char temperature[7];
  char steps[7];
  char steps_cadence[7];

#if DEBUG
  char debug1[200];
  char debug2[200];
#endif
  char unitsSpeedOrHeartRate[8];
  char unitsSpeed[8];
{'fraction_non_alphanumeric': 0.09083410660892875, 'fraction_numerical': 0.029796886276935768, 'mean_word_length': 4.900243309002433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7559924', 'n_tokens_mistral': 4420, 'n_tokens_neox': 4044, 'n_words': 804}