Fix calendar generation

This commit is contained in:
Connor Rigby 2017-12-28 15:30:56 -08:00 committed by Connor Rigby
parent dcabe73b0c
commit 3367475838
4 changed files with 13 additions and 19 deletions

View file

@ -3,7 +3,7 @@
#include <erl_nif.h>
#define MAX_GENERATED 60
#define MAX_GENERATED 3
static ERL_NIF_TERM do_build_calendar(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
@ -21,6 +21,7 @@ static ERL_NIF_TERM do_build_calendar(ErlNifEnv* env, int argc, const ERL_NIF_TE
// Data used to build the calendar.
long int gracePeriodSeconds;
gracePeriodSeconds = nowSeconds - 60;
gracePeriodSeconds -= (gracePeriodSeconds % 60);
long int step = frequencySeconds * repeat;
// iterators for loops
@ -36,7 +37,6 @@ static ERL_NIF_TERM do_build_calendar(ErlNifEnv* env, int argc, const ERL_NIF_TE
// if this event (i) is after the grace period, add it to the array.
if(i > gracePeriodSeconds) {
events[j] = i;
events[j] -= (events[j] % 60);
j++;
}
}

View file

@ -83,7 +83,7 @@ defmodule Farmbot.FarmEvent.Manager do
now = get_now()
alias Farmbot.Repo.FarmEvent
# maybe_farm_event_log "Rebuilding calendar."
all_events = state.events |> Enum.map(&FarmEvent.build_calendar(&1))
all_events = Enum.map(state.events, &FarmEvent.build_calendar(&1))
# maybe_farm_event_log "Rebuilding calendar complete."
# do checkup is the bulk of the work.

View file

@ -40,9 +40,6 @@ defmodule Farmbot.Firmware do
For a list of paramaters see `Farmbot.Firmware.Gcode.Param`
"""
def update_param(param, val) do
if val == 0 do
Logger.warn 1, "WRITING PARAM: #{param} ZERO!!!"
end
GenStage.call(__MODULE__, {:update_param, [param, val]}, :infinity)
end
@ -297,9 +294,6 @@ defmodule Farmbot.Firmware do
end
defp handle_gcode({:report_parameter_value, param, value}, state) do
if value == 0 do
Logger.warn 1, "Firmware reported zero for #{param}!!!!"
end
Farmbot.System.ConfigStorage.update_config_value(:float, "hardware_params", to_string(param), value / 1)
{:mcu_params, %{param => value}, state}

View file

@ -72,7 +72,7 @@ defmodule Farmbot.Repo.FarmEvent do
start_time_seconds = DateTime.from_iso8601(fe.start_time) |> elem(1) |> DateTime.to_unix(:second)
end_time_seconds = DateTime.from_iso8601(fe.end_time) |> elem(1) |> DateTime.to_unix(:second)
repeat = fe.repeat
repeat_frequency_seconds = time_unit_to_seconds(repeat, fe.time_unit)
repeat_frequency_seconds = time_unit_to_seconds(fe.time_unit)
new_calendar =
do_build_calendar(current_time_seconds,
@ -92,16 +92,16 @@ defmodule Farmbot.Repo.FarmEvent do
Range.new(start_time_seconds, end_time_seconds)
|> Enum.take_every(repeat * repeat_frequency_seconds)
|> Enum.filter(&Kernel.>(&1, grace_period_cutoff_seconds))
|> Enum.take(60)
|> Enum.take(3)
|> Enum.map(&Kernel.-(&1, div(&1, 60)))
end
@compile {:inline, [time_unit_to_seconds: 2]}
defp time_unit_to_seconds(_, "never"), do: 0
defp time_unit_to_seconds(repeat, "minutely"), do: 60 * repeat
defp time_unit_to_seconds(repeat, "hourly"), do: 60 * 60 * repeat
defp time_unit_to_seconds(repeat, "daily"), do: 60 * 60 * 24 * repeat
defp time_unit_to_seconds(repeat, "weekly"), do: 60 * 60 * 24 * 7 * repeat
defp time_unit_to_seconds(repeat, "monthly"), do: 60 * 60 * 24 * 30 * repeat
defp time_unit_to_seconds(repeat, "yearly"), do: 60 * 60 * 24 * 365 * repeat
@compile {:inline, [time_unit_to_seconds: 1]}
defp time_unit_to_seconds("never"), do: 0
defp time_unit_to_seconds("minutely"), do: 60
defp time_unit_to_seconds("hourly"), do: 60 * 60
defp time_unit_to_seconds("daily"), do: 60 * 60 * 24
defp time_unit_to_seconds("weekly"), do: 60 * 60 * 24 * 7
defp time_unit_to_seconds("monthly"), do: 60 * 60 * 24 * 30
defp time_unit_to_seconds("yearly"), do: 60 * 60 * 24 * 365
end