Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo clean up and retiring old code #119

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
using System;
using System.Threading.Tasks;
class ThresholdWorkout {
// Define the constants for the workout
const int IntervalDuration = 20; // in seconds
static int NumIntervals ;
const int RestDuration = 15; // in seconds
const int WarmupDuration = 20; // in seconds
const int CooldownDuration = 10; // in seconds
// Define the power output percentages for each part of the workout
static int ThresholdPower;
const double IntervalPowerPercentage = 0.90; // 90% of the threshold power
const double RestPowerPercentage = 0.50; // 50% of the threshold power
const double WarmupPowerPercentage = 0.30; // 30% of the threshold power
const double CooldownPowerPercentage = 0.30; // 30% of the threshold power
// Define a function to calculate the power output for a given time during the workout
static int CalculatePowerOutput(int time) {
if (time < WarmupDuration) {
return (int)(ThresholdPower * WarmupPowerPercentage);
} else if (time < WarmupDuration + NumIntervals * (IntervalDuration + RestDuration)) {
int intervalIndex = (time - WarmupDuration) / (IntervalDuration + RestDuration);
int intervalStartTime = WarmupDuration + intervalIndex * (IntervalDuration + RestDuration);
int intervalElapsedTime = time - intervalStartTime;
if (intervalElapsedTime < IntervalDuration) {
return (int)(ThresholdPower * IntervalPowerPercentage);
} else {
return (int)(ThresholdPower * RestPowerPercentage);
}
} else {
return (int)(ThresholdPower * CooldownPowerPercentage);
}
}
// Define a function to simulate the workout
static async Task SimulateWorkout() {
Console.WriteLine("Starting workout...");
await Task.Delay(2000); // Wait for 2 seconds before starting to simulate the workout
int currentTime = 0;
int TotalDuration = (NumIntervals * IntervalDuration) + (NumIntervals - 1) * RestDuration + WarmupDuration + CooldownDuration;
while (currentTime < TotalDuration) {
int powerOutput = CalculatePowerOutput(currentTime);
Console.WriteLine($"Power output for time {currentTime} is {powerOutput}");
await Task.Delay(1000); // Wait for 1 second
currentTime += 1;
}
Console.WriteLine("Workout complete!");
}
// Define a function to turn off the smart bike
static void TurnOffBike() {
Console.WriteLine("Smart bike turned off.");
}
// Main function
static async Task Main() {
// Take input from user about the threshold power
Console.Write("Enter the threshold power (in watts): ");
int.TryParse(Console.ReadLine(), out ThresholdPower);
// Take input from user about number of intervals
Console.Write("Please enter the number of intervals for the workout");
int.TryParse(Console.ReadLine(), out NumIntervals );
// Simulate the workout
await SimulateWorkout();
// Turn off the smart bike
TurnOffBike();
}
}
using System;
using System.Threading.Tasks;

class ThresholdWorkout {
// Define the constants for the workout
const int IntervalDuration = 20; // in seconds
static int NumIntervals ;
const int RestDuration = 15; // in seconds
const int WarmupDuration = 20; // in seconds
const int CooldownDuration = 10; // in seconds

// Define the power output percentages for each part of the workout
static int ThresholdPower;
const double IntervalPowerPercentage = 0.90; // 90% of the threshold power
const double RestPowerPercentage = 0.50; // 50% of the threshold power
const double WarmupPowerPercentage = 0.30; // 30% of the threshold power
const double CooldownPowerPercentage = 0.30; // 30% of the threshold power

// Define a function to calculate the power output for a given time during the workout
static int CalculatePowerOutput(int time) {
if (time < WarmupDuration) {
return (int)(ThresholdPower * WarmupPowerPercentage);
} else if (time < WarmupDuration + NumIntervals * (IntervalDuration + RestDuration)) {
int intervalIndex = (time - WarmupDuration) / (IntervalDuration + RestDuration);
int intervalStartTime = WarmupDuration + intervalIndex * (IntervalDuration + RestDuration);
int intervalElapsedTime = time - intervalStartTime;
if (intervalElapsedTime < IntervalDuration) {
return (int)(ThresholdPower * IntervalPowerPercentage);
} else {
return (int)(ThresholdPower * RestPowerPercentage);
}
} else {
return (int)(ThresholdPower * CooldownPowerPercentage);
}
}

// Define a function to simulate the workout
static async Task SimulateWorkout() {
Console.WriteLine("Starting workout...");
await Task.Delay(2000); // Wait for 2 seconds before starting to simulate the workout

int currentTime = 0;
int TotalDuration = (NumIntervals * IntervalDuration) + (NumIntervals - 1) * RestDuration + WarmupDuration + CooldownDuration;

while (currentTime < TotalDuration) {
int powerOutput = CalculatePowerOutput(currentTime);
Console.WriteLine($"Power output for time {currentTime} is {powerOutput}");

await Task.Delay(1000); // Wait for 1 second
currentTime += 1;
}

Console.WriteLine("Workout complete!");

}

// Define a function to turn off the smart bike
static void TurnOffBike() {
Console.WriteLine("Smart bike turned off.");
}

// Main function
static async Task Main() {
// Take input from user about the threshold power
Console.Write("Enter the threshold power (in watts): ");
int.TryParse(Console.ReadLine(), out ThresholdPower);
// Take input from user about number of intervals
Console.Write("Please enter the number of intervals for the workout");
int.TryParse(Console.ReadLine(), out NumIntervals );

// Simulate the workout
await SimulateWorkout();

// Turn off the smart bike
TurnOffBike();
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
import bluetooth
from mqtt_client import MQTTClient
import os
import time
from dotenv import load_dotenv
hc06_address = "98:D3:51:FE:68:16"
port = 1
bike_resistance = 0
bike_incline = -10
load_dotenv('/home/pi/.env')
mqtt_client = MQTTClient(os.getenv('MQTT_HOSTNAME'), os.getenv('MQTT_USERNAME'), os.getenv('MQTT_PASSWORD'))
mqtt_client.setup_mqtt_client()
print("Connecting to HC-06...")
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((hc06_address, port))
sock.send("Hello from Raspberry Pi!")
print("Connected, waiting for data")
mqtt_client.get_client().loop_start()
mqtt_client.publish(f"bike/000001/resistance/control", bike_resistance)
mqtt_client.publish(f"bike/000001/incline/control", bike_incline)
buffer = " "
try:
while True:
data = sock.recv(1024).decode('utf-8')
buffer += data
while '\n' in buffer:
line, buffer = buffer.split('\n', 1)
print("Receieved: " + line.strip())
if(line.strip() == "increaseResistance"):
if bike_resistance < 100:
bike_resistance += 5
mqtt_client.publish(f"bike/000001/resistance/control", bike_resistance)
else:
print("Resistance at max")
elif(line.strip() == "decreaseResistance"):
if bike_resistance > 0:
bike_resistance -= 5
mqtt_client.publish(f"bike/000001/resistance/control", bike_resistance)
else:
print("Resistance at min")
elif(line.strip() == "increaseIncline"):
if bike_incline < 19:
bike_incline += 1
mqtt_client.publish(f"bike/000001/incline/control", bike_incline)
else:
print("Incline at max")
elif(line.strip() == "decreaseIncline"):
if bike_incline > -10:
bike_incline -= 1
mqtt_client.publish(f"bike/000001/incline/control", bike_incline)
else:
print("Incline at min")
except KeyboardInterrupt:
print("Closing socket")
sock.close()
mqtt_client.get_client().loop_stop()
print("Done")
import bluetooth
from mqtt_client import MQTTClient
import os
import time
from dotenv import load_dotenv

hc06_address = "98:D3:51:FE:68:16"
port = 1
bike_resistance = 0
bike_incline = -10

load_dotenv('/home/pi/.env')
mqtt_client = MQTTClient(os.getenv('MQTT_HOSTNAME'), os.getenv('MQTT_USERNAME'), os.getenv('MQTT_PASSWORD'))
mqtt_client.setup_mqtt_client()

print("Connecting to HC-06...")
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((hc06_address, port))
sock.send("Hello from Raspberry Pi!")
print("Connected, waiting for data")
mqtt_client.get_client().loop_start()

mqtt_client.publish(f"bike/000001/resistance/control", bike_resistance)
mqtt_client.publish(f"bike/000001/incline/control", bike_incline)


buffer = " "
try:
while True:
data = sock.recv(1024).decode('utf-8')
buffer += data
while '\n' in buffer:
line, buffer = buffer.split('\n', 1)
print("Receieved: " + line.strip())

if(line.strip() == "increaseResistance"):
if bike_resistance < 100:
bike_resistance += 5
mqtt_client.publish(f"bike/000001/resistance/control", bike_resistance)
else:
print("Resistance at max")

elif(line.strip() == "decreaseResistance"):
if bike_resistance > 0:
bike_resistance -= 5
mqtt_client.publish(f"bike/000001/resistance/control", bike_resistance)
else:
print("Resistance at min")

elif(line.strip() == "increaseIncline"):
if bike_incline < 19:
bike_incline += 1
mqtt_client.publish(f"bike/000001/incline/control", bike_incline)
else:
print("Incline at max")

elif(line.strip() == "decreaseIncline"):
if bike_incline > -10:
bike_incline -= 1
mqtt_client.publish(f"bike/000001/incline/control", bike_incline)
else:
print("Incline at min")


except KeyboardInterrupt:
print("Closing socket")

sock.close()
mqtt_client.get_client().loop_stop()
print("Done")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dotenv import set_key
bot_token_input = input("Enter Bot Token:\n")
env_path = '/home/pi/.env'
set_key(env_path, 'BOT_TOKEN', str(bot_token_input))
set_key(env_path, 'ETH0_IP', " ")
from dotenv import set_key
bot_token_input = input("Enter Bot Token:\n")

env_path = '/home/pi/.env'

set_key(env_path, 'BOT_TOKEN', str(bot_token_input))
set_key(env_path, 'ETH0_IP', " ")
set_key(env_path, 'WLAN0_IP', " ")
File renamed without changes.
Loading