Skip to content

Commit

Permalink
Merge pull request #44 from tibbotech/ui_input_box
Browse files Browse the repository at this point in the history
UI input box
  • Loading branch information
salhk authored Apr 3, 2024
2 parents 353fa01 + c7e939e commit 3ee05d6
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 27 deletions.
46 changes: 45 additions & 1 deletion ui/ui.tbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,23 @@ public function device_settings_sg(setting_name as string(50),index as byte, byr
b1=b2
loop while b1<>0
setting_val=left(s2,len(s2)-1)
end if
end if
if chr(stg_stype_get(setting_name))="T" then
setting_val = datetime_timestamp_to_string(lval(setting_val), "YYYY/MM/DD HH:mm")
end if
if chr(stg_stype_get(setting_name))="M" then
dim hrs as byte = val(setting_val) / 3600
dim min as byte = val(setting_val) / 60 MOD 60
dim hrs_str as string(2)=stri(hrs)
dim min_str as string(2)=stri(min)
if len(hrs_str) = 1 then
hrs_str = "0" + hrs_str
end if
if len(min_str) = 1 then
min_str = "0" + min_str
end if
setting_val = hrs_str + ":" + min_str
end if
end if
device_settings_sg=setting_result
else
Expand All @@ -52,7 +68,35 @@ public function device_settings_sg(setting_name as string(50),index as byte, byr
index=val(right(setting_name,len(setting_name)-b1))
setting_name=left(setting_name,b1-1)
end if
if chr(stg_stype_get(setting_name))="T" then
dim sanitized_setting_val as string=""

dim days as word
dim mins as word
dim secs as byte
dim i as byte=1
do
if asc(mid(setting_val, i, 1)) > 47 and asc(mid(setting_val, i, 1)) < 58 then
sanitized_setting_val = sanitized_setting_val + mid(setting_val, i, 1)
end if
i = i + 1
loop while i < len(setting_val) + 1
datetime_from_timestamp(datetime_str_to_timestamp(sanitized_setting_val, "YYYYMMDDhhmm"), days, mins, secs)
td_local_to_gmt(days, mins, datetime_tz_offset, PL_OFF)
setting_val = datetime_to_timestamp(days, mins, secs)
end if
if chr(stg_stype_get(setting_name))="M" then
dim hours as byte=val(mid(setting_val, 1, 2))
dim min as byte=val(mid(setting_val, 4, 2))
if hours > 24 or min > 59 then
device_settings_sg = EN_STG_STATUS_INVALID
goto error_device_settings_sg
end if
setting_val=hours * 3600 + min * 60
end if
device_settings_sg=stg_sg(setting_name,index,setting_val,EN_STG_SET)

error_device_settings_sg:
end if

end function
Expand Down
7 changes: 5 additions & 2 deletions ui/ui_input_box.tbh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ end enum
enum input_box_char_ranges
INPUT_BOX_CHAR_RANGE_09,
INPUT_BOX_CHAR_RANGE_AZ,
INPUT_BOX_CHAR_RANGE_09AZ
INPUT_BOX_CHAR_RANGE_09AZ,
INPUT_BOX_CHAR_RANGE_DIGITS
end enum

enum input_box_change_chr_dir
Expand Down Expand Up @@ -107,4 +108,6 @@ declare function ui_input_box(
input_length as byte
) as ui_input_box_results

declare sub ui_input_box_key_proc(key_event as pl_kp_event_codes, key_code as byte)
declare sub ui_input_box_key_proc(key_event as pl_kp_event_codes, key_code as byte)

declare sub ui_input_box_proc_timer()
Loading

0 comments on commit 3ee05d6

Please sign in to comment.