fusion_hat._utils モジュール

fusion_hat._utils.retry(times: int = 5)[ソース]

エラーが発生した場合に、指定した回数だけ再試行するためのデコレータ

パラメータ:

times (int, optional) -- 再試行回数。デフォルトは 5 です。

戻り値:

ラッパー関数

戻り値の型:

function

fusion_hat._utils.command_exists(cmd: str) bool[ソース]

コマンドが存在するかを確認します

パラメータ:

cmd (str) -- 確認するコマンド

戻り値:

存在する場合は True

戻り値の型:

bool

fusion_hat._utils.run_command(cmd: str, timeout: float | None = None) tuple[ソース]

コマンドを実行し、ステータスと出力を返します

パラメータ:
  • cmd (str) -- 実行するコマンド

  • timeout (float | None) -- timeout in seconds, None for no timeout

戻り値:

status, output. On timeout, returns (124, "timed out after Ns")

戻り値の型:

tuple

fusion_hat._utils.is_installed(cmd: str) bool[ソース]

コマンドがインストールされているかを確認します

パラメータ:

cmd (str) -- 確認するコマンド

戻り値:

インストールされている場合は True

戻り値の型:

bool

fusion_hat._utils.mapping(x: float, in_min: float, in_max: float, out_min: float, out_max: float) float[ソース]

値をある範囲から別の範囲へマッピングします

パラメータ:
  • x (float) -- マッピングする値

  • in_min (float) -- 入力の最小値

  • in_max (float) -- 入力の最大値

  • out_min (float) -- 出力の最小値

  • out_max (float) -- 出力の最大値

戻り値:

マッピング後の値

戻り値の型:

float

fusion_hat._utils.get_ip(ifaces: list = ['wlan0', 'eth0']) str[ソース]

IP アドレスを取得します

パラメータ:

ifaces (list, optional) -- 確認するインターフェース。デフォルトは ['wlan0', 'eth0'] です。

戻り値:

IP アドレス。見つからない場合は False

戻り値の型:

str/False

fusion_hat._utils.get_username() str[ソース]

ユーザー名を取得します

戻り値:

ユーザー名

戻り値の型:

str

fusion_hat._utils.constrain(value: float, min_value: float, max_value: float) float[ソース]

値を指定した範囲内に制限します

パラメータ:
  • value (float) -- 制限する値

  • min_value (float) -- 最小値

  • max_value (float) -- 最大値

戻り値:

制限後の値

戻り値の型:

float