Página 1 de 1

How to change watch hand from javascript ?

Publicado: 08 Nov 2025, 16:07
por zankezaa
Hi, i'll change my watch hand from javascript, i have try a someone script, but it not works on me.
Is there any a solution to solve this?

There my code :

Código: Seleccionar todo

		
		//change watch hand
		let handnumber_1 = 1;
		let total_hand = 7; 

		function click_hand() {
			handnumber_1++;

			// kalau sudah melebihi jumlah total, balik lagi ke awal
			if (handnumber_1 > total_hand) {
				handnumber_1 = 1;
			}

			switch (handnumber_1) {
				case 1:
					UpdateHandOne();
					hmUI.showToast({ text: 'Style One' });
					break;
				case 2:
					UpdateHandTwo();
					hmUI.showToast({ text: 'Style Two' });
					break;
				case 3:
					UpdateHandThree();
					hmUI.showToast({ text: 'Style Three' });
					break;
				case 4:
					UpdateHandFour();
					hmUI.showToast({ text: 'Style Four' });
					break;
				case 5:
					UpdateHandFive();
					hmUI.showToast({ text: 'Style Five' });
					break;
				case 6:
					UpdateHandSix();
					hmUI.showToast({ text: 'Style Six' });
					break;
				case 7:
					UpdateHandSeven();
					hmUI.showToast({ text: 'Style Seven' });
					break;
			}
		}

		function UpdateHandOne() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H1.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M1.png");
		}

		function UpdateHandTwo() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H2.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M2.png");
		}

		function UpdateHandThree() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H3.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M3.png");
		}

		function UpdateHandFour() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H4.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M4.png");
		}
		function UpdateHandFive() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H5.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M5.png");
		}
		function UpdateHandSix() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H6.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M6.png");
		}
		function UpdateHandSeven() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H7.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M7.png");
		}
		
Are the code is correct?

Re: How to change watch hand from javascript ?

Publicado: 08 Nov 2025, 16:51
por asoo
zankezaa escribió: 08 Nov 2025, 16:07
Hi, i'll change my watch hand from javascript, i have try a someone script, but it not works on me.
Is there any a solution to solve this?

There my code :

Código: Seleccionar todo

		
		//change watch hand
		let handnumber_1 = 1;
		let total_hand = 7; 

		function click_hand() {
			handnumber_1++;

			// kalau sudah melebihi jumlah total, balik lagi ke awal
			if (handnumber_1 > total_hand) {
				handnumber_1 = 1;
			}

			switch (handnumber_1) {
				case 1:
					UpdateHandOne();
					hmUI.showToast({ text: 'Style One' });
					break;
				case 2:
					UpdateHandTwo();
					hmUI.showToast({ text: 'Style Two' });
					break;
				case 3:
					UpdateHandThree();
					hmUI.showToast({ text: 'Style Three' });
					break;
				case 4:
					UpdateHandFour();
					hmUI.showToast({ text: 'Style Four' });
					break;
				case 5:
					UpdateHandFive();
					hmUI.showToast({ text: 'Style Five' });
					break;
				case 6:
					UpdateHandSix();
					hmUI.showToast({ text: 'Style Six' });
					break;
				case 7:
					UpdateHandSeven();
					hmUI.showToast({ text: 'Style Seven' });
					break;
			}
		}

		function UpdateHandOne() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H1.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M1.png");
		}

		function UpdateHandTwo() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H2.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M2.png");
		}

		function UpdateHandThree() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H3.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M3.png");
		}

		function UpdateHandFour() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H4.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M4.png");
		}
		function UpdateHandFive() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H5.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M5.png");
		}
		function UpdateHandSix() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H6.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M6.png");
		}
		function UpdateHandSeven() {
            normal_analog_clock_time_pointer_hour_img.setProperty(hmUI.prop.SRC, "Hand_H7.png");
            normal_analog_clock_time_pointer_minute_img.setProperty(hmUI.prop.SRC, "Hand_M7.png");
		}
		
Are the code is correct?

Since you didn't submit the entire project, I can only speculate.
From the code you attached, it looks like you created the widget name yourself. If you were to use Sasha's editor, the "normal analog" widget name would likely be "normal_analog_clock_time_pointer_hour."
But I saw that you wrote in the script:
"normal_analog_clock_time_pointer_hour_img."
I think this is not correct, as this widget shouldn't exist, so you can't change it. And if you use the "normal_analog_clock_time_pointer_hour" widget to display the clock hands, you'll see that it doesn't have an SRC, so it can't be change image with SRC
If you want to change elements in this widget, you must use
.setProperty(hmUI.prop.MORE, to do this.

For example,

Código: Seleccionar todo

normal_analog_clock_time_pointer_hour.setProperty(hmUI.prop.MORE, {
hour_path: 'Hand_H2.png',
hour_centerX: 233,
hour_centerY: 233,
hour_posX: 24,
hour_posY: 233,
hour_cover_path: 'HAND_CAP.png',
hour_cover_x: 224,
hour_cover_y: 224,
show_level: hmUI.show_level.ONLY_NORMAL,
});
When using MORE to change widget elements, it is recommended to write every line. Some widgets may not be able to change elements if they are not written in every line.

As mentioned, you didn't attach the entire project, so I can't verify whether my suggestions address your problem.
I can only speculate.

Re: How to change watch hand from javascript ?

Publicado: 08 Nov 2025, 17:03
por zankezaa
Is it possible to not attach a project, like having to attach a zip file of my watchface?

Thanks for the suggestions, i'll try your suggestions.

Re: How to change watch hand from javascript ?

Publicado: 08 Nov 2025, 17:50
por asoo
zankezaa escribió: 08 Nov 2025, 17:03
Is it possible to not attach a project, like having to attach a zip file of my watchface?

Thanks for the suggestions, i'll try your suggestions.

You can also attach a zip file of the watchface, it will help too. But without any attaching the file, it would be difficult to answer the question directly.
Or if you want to replace the analog hands with " SRC ", I recommend switching to use widget "analog pro". The widget's name would be
"normal_analog_clock_pro_hour_pointer_img".
analog pro uses SRC, so you can change the visual elements with the command:

Código: Seleccionar todo

normal_analog_clock_pro_hour_pointer_img.setProperty(hmUI.prop.SRC, "Hand_H1.png");

Re: How to change watch hand from javascript ?

Publicado: 09 Nov 2025, 06:01
por zankezaa
Thanks, its work using the Analog time pro. :D

And what widget are supporrted in ZeppOS?
Can you provide examples of widget in ZeppOS in script form?
I apologize in advance, because i am beginner in this watchface editor

Re: How to change watch hand from javascript ?

Publicado: 09 Nov 2025, 07:12
por asoo
zankezaa escribió: 09 Nov 2025, 06:01
Thanks, its work using the Analog time pro. :D

And what widget are supporrted in ZeppOS?
Can you provide examples of widget in ZeppOS in script form?
I apologize in advance, because i am beginner in this watchface editor
All standard widgets are already available in Sasha's editor. The program includes all standard widgets. If you need a widget script, just enable the widget and pack it. You will get the script in index.js and you can use it as you wish.

Re: How to change watch hand from javascript ?

Publicado: 09 Nov 2025, 09:50
por zankezaa
Okay, thankyou very much asoo