Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Removed use of float
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpMaster committed Jul 3, 2015
1 parent 3f8077e commit f86accc
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 48 deletions.
2 changes: 1 addition & 1 deletion appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"basalt"
],
"uuid": "1f4d9835-3b9a-4ddd-907e-41a25d06f19c",
"versionLabel": "2.4",
"versionLabel": "2.5",
"watchapp": {
"watchface": false
}
Expand Down
1 change: 0 additions & 1 deletion src/base32.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
// output buffer is too small, the result will silently be truncated.

#pragma once

#include <stdint.h>

int base32_decode(const uint8_t *encoded, uint8_t *result, int bufSize)
Expand Down
7 changes: 3 additions & 4 deletions src/google-authenticator.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "google-authenticator.h"

char *generateCode(const char *key, int timezone_offset) {
//long tm = time(NULL)/30;

#ifdef PBL_SDK_2
long tm = (time(NULL) + (timezone_offset*60))/30;
Expand All @@ -48,17 +47,17 @@ char *generateCode(const char *key, int timezone_offset) {
// Sanity check, that our secret will fixed into a reasonably-sized static
// array.
if (secretLen < 0 || secretLen > 100) {
return "FAILED";
return "000000";
}

// Decode secret from Base32 to a binary representation, and check that we
// have at least one byte's worth of secret data.
uint8_t secret[100];
if ((secretLen = base32_decode((const uint8_t *)key, secret, secretLen))<1) {
return "FAILED";
return "000000";
}

// Compute the HMAC_SHA1 of the secrete and the challenge.
// Compute the HMAC_SHA1 of the secret and the challenge.
uint8_t hash[SHA1_DIGEST_LENGTH];
hmac_sha1(secret, secretLen, challenge, 8, hash, SHA1_DIGEST_LENGTH);

Expand Down
9 changes: 5 additions & 4 deletions src/js/pebble-js-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var MAX_OTP_COUNT = 16;
var MAX_LABEL_LENGTH = 20;
var MAX_KEY_LENGTH = 128;
var MAX_MESSAGE_RETRIES = 5;
var APP_VERSION = 24;
var APP_VERSION = 25;

var otp_count = 0;
var aplite_theme = -1;
Expand Down Expand Up @@ -321,9 +321,10 @@ Pebble.addEventListener("webviewclosed",
if(configuration.label && configuration.secret) {

var secret = configuration.secret
.replace(/0/g,"O") // replace 0 with O
.replace(/1/g, "I") // replace 1 with I
.replace(/\W/g, '') // replace non-alphanumeric characters
.replace(/0/g,"O") // replace 0 with O
.replace(/1/g, "I") // replace 1 with I
.replace(/\W/g, '') // replace non-alphanumeric characters
.replace(/_/g, '') // replace underscore
.toUpperCase()
.substring(0, MAX_KEY_LENGTH);
var label = configuration.label
Expand Down
34 changes: 12 additions & 22 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "main.h"
#include "single_code_window.h"
#include "multi_code_window.h"
#include <ctype.h>
#include "ctype.h"

// Colors
GColor bg_color;
Expand Down Expand Up @@ -677,29 +677,15 @@ void main_animate_second_counter(int seconds, bool off_screen) {
// update countdown layer
GRect start = layer_get_frame(text_layer_get_layer(countdown_layer));
GRect finish = countdown_rect;
finish.size.w = ((float)4.8) * reverse_seconds; // 4.8 == Pebble screen width / 30
// finish.size.w = ((float)4.8) * reverse_seconds; // 4.8 == Pebble screen width / 30
finish.size.w = (24 * reverse_seconds) / 5; // Same result as the above line but it avoids floats so is Pebble friendly.

#ifdef PBL_COLOR
switch(reverse_seconds)
{
case 6 :
text_layer_set_background_color(countdown_layer, GColorRed);
break;
case 5 :
text_layer_set_background_color(countdown_layer, fg_color);
break;
case 4 :
text_layer_set_background_color(countdown_layer, GColorRed);
break;
case 3 :
text_layer_set_background_color(countdown_layer, fg_color);
break;
case 2 :
text_layer_set_background_color(countdown_layer, GColorRed);
break;
case 1 :
text_layer_set_background_color(countdown_layer, fg_color);
break;
if (reverse_seconds <= 6) {
if (reverse_seconds % 2 == 0)
text_layer_set_background_color(countdown_layer, GColorRed);
else
text_layer_set_background_color(countdown_layer, fg_color);
}
#endif

Expand Down Expand Up @@ -762,12 +748,16 @@ void handle_init(void) {
void handle_deinit(void) {
if (DEBUG)
APP_LOG(APP_LOG_LEVEL_DEBUG, "INFO: EXITING");

tick_timer_service_unsubscribe();
animation_unschedule_all();
text_layer_destroy(countdown_layer);

if (window_layout == 1)
multi_code_window_remove();
else
single_code_window_remove();

if (font_label.isCustom)
fonts_unload_custom_font(font_label.font);
if (font_pin.isCustom)
Expand Down
8 changes: 1 addition & 7 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@
//

#pragma once

#include "pebble.h"

typedef struct {
GFont font;
bool isCustom;
} AppFont;

#define ASCII_0_VALU 48
#define ASCII_9_VALU 57
#define ASCII_A_VALU 65
#define ASCII_F_VALU 70

#define MAX_OTP 16
#define MAX_LABEL_LENGTH 21 // 20 + termination
#define MAX_KEY_LENGTH 129 // 128 + termination
#define MAX_COMBINED_LENGTH MAX_LABEL_LENGTH+MAX_KEY_LENGTH
#define APP_VERSION 24
#define APP_VERSION 25
#define DEBUG false

#define MyTupletCString(_key, _cstring) \
Expand Down
3 changes: 0 additions & 3 deletions src/multi_code_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ static void multi_code_menu_selection_changed_callback(struct MenuLayer *menu_la
resetIdleTime();
}

AppFont font_pin;
AppFont font_label;

void multi_code_set_fonts(void) {
fonts_changed = false;

Expand Down
2 changes: 1 addition & 1 deletion src/multi_code_window.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "pebble.h"

#define MULTI_CODE_CELL_HEIGHT 55

void multi_code_window_push(void);
Expand Down
2 changes: 1 addition & 1 deletion src/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*
*****************************************************************************
*/
#include <string.h>
#include "string.h"
#include "sha1.h"

/* SHA f()-functions */
Expand Down
3 changes: 1 addition & 2 deletions src/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
// limitations under the License.

#pragma once

#include <stdint.h>
#include "stdint.h"

#define SHA1_BLOCKSIZE 64
#define SHA1_DIGEST_LENGTH 20
Expand Down
2 changes: 1 addition & 1 deletion src/single_code_window.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <pebble.h>
#include "pebble.h"
#include "single_code_window.h"
#include "main.h"
#include "select_window.h"
Expand Down
1 change: 0 additions & 1 deletion src/single_code_window.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "pebble.h"

void single_code_window_push(void);
void single_code_window_remove(void);
Expand Down

0 comments on commit f86accc

Please sign in to comment.