diff --git a/aad_coin_miner_wasm.c b/aad_coin_miner_wasm.c index 58d33d6..e2bbf07 100644 --- a/aad_coin_miner_wasm.c +++ b/aad_coin_miner_wasm.c @@ -24,6 +24,8 @@ static volatile int keep_running = 1; static u64_t total_attempts = 0; static u32_t coins_found = 0; static double mining_start_time = 0; +static double pause_time_offset = 0; // Track paused time +static double last_pause_time = 0; // When mining was paused static u32_t found_coins[1024][14]; // Store up to 1024 found coins static u32_t found_coins_count = 0; @@ -158,8 +160,20 @@ void get_statistics(u64_t *attempts, u32_t *coins, double *hash_rate, double *el { *attempts = total_attempts; *coins = coins_found; - *elapsed_time = get_time() - mining_start_time; - *hash_rate = (*elapsed_time > 0) ? (total_attempts / *elapsed_time) : 0; + + double current_time = get_time(); + double actual_elapsed; + + if(!keep_running && last_pause_time > 0) { + // If paused, use the paused time + actual_elapsed = last_pause_time - mining_start_time - pause_time_offset; + } else { + // If running, calculate normally + actual_elapsed = current_time - mining_start_time - pause_time_offset; + } + + *elapsed_time = actual_elapsed; + *hash_rate = (actual_elapsed > 0) ? (total_attempts / actual_elapsed) : 0; } // @@ -170,7 +184,26 @@ EMSCRIPTEN_KEEPALIVE #endif void stop_mining() { - keep_running = 0; + if(keep_running) { + keep_running = 0; + last_pause_time = get_time(); + } +} + +// +// Resume mining +// +#ifdef __EMSCRIPTEN__ +EMSCRIPTEN_KEEPALIVE +#endif +void resume_mining() +{ + if(!keep_running && last_pause_time > 0) { + double pause_duration = get_time() - last_pause_time; + pause_time_offset += pause_duration; + keep_running = 1; + last_pause_time = 0; + } } // @@ -209,6 +242,8 @@ void reset_mining() total_attempts = 0; coins_found = 0; found_coins_count = 0; + pause_time_offset = 0; + last_pause_time = 0; mining_start_time = get_time(); } diff --git a/index.html b/index.html index fcc9b9a..d6ed4d9 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,8 @@ body { font-family: monospace; padding: 20px; + max-width: 1200px; + margin: 0 auto; } button { padding: 10px 20px; @@ -17,6 +19,24 @@ padding: 10px; background: #f0f0f0; border-radius: 5px; + box-sizing: border-box; + } + #coins-container { + margin-top: 20px; + } + #coins { + width: 100%; + height: 300px; + padding: 10px; + background: #f9f9f9; + border: 2px solid #ccc; + border-radius: 5px; + font-family: monospace; + font-size: 12px; + overflow-y: auto; + white-space: pre-wrap; + word-wrap: break-word; + box-sizing: border-box; } .control-group { margin: 10px 0; @@ -25,6 +45,17 @@ display: inline-block; width: 200px; } + h2 { + margin-top: 20px; + margin-bottom: 10px; + } + .coin-entry { + color: #006400; + font-weight: bold; + } + .coin-data { + color: #000080; + }
@@ -40,16 +71,25 @@ + +